Hilbert's Hotel

Diskussionsforum zur Unendlichkeit: Theismus, Atheismus, Primzahlen, Unsterblichkeit, das Universum...
Discussing Infinity: theism and atheism, prime numbers, immortality, cosmology, philosophy...

Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 18,435 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 6 of 7 1 2 3 4 5 6 7
Re: NVidia Number Test [Re: Pappenheimer] #162333
10/28/07 23:35
10/28/07 23:35
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
So, no valid answer yet?

How about this?
Code:

int rand7()
{
int x;
do
{
x = ((rand5()+5*rand5())-5);
} while(x>21);
return ((x%7)+1);
}



Again, top of my head. But it gives equal probability (no dice effect).
I do not like the loop, but it is quicker than finding the LCD.

Last edited by Doug; 10/29/07 20:19.

Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: NVidia Number Test [Re: Doug] #162334
10/29/07 03:02
10/29/07 03:02
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
that's basically the same as mine posted a bit more than a week ago. go show-all and search "794517" to jump straight to it if need be, but it's mostly the same as yours (except it returns between 1-7 instead of 1-6 )

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162335
10/29/07 20:23
10/29/07 20:23
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
Yes, as far as I can tell you have the only correct answer in the thread (I went back and fixed my +1 error ).

Congratulations on your job at nVidia.

But, if I gave this as an interview question, my next question would be: "Can you do it without the loop?".

Last edited by Doug; 10/29/07 20:24.

Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: NVidia Number Test [Re: Doug] #162336
10/29/07 21:06
10/29/07 21:06
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
as i said, it seems impossible to acheive both equal distribution and no predictability without at least one branch.

Re: NVidia Number Test [Re: Joey] #162337
10/30/07 00:20
10/30/07 00:20
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
it does seem impossible i was looking for some relationships between the probabilities of different digits showing 1's in binary format (as i'm sure Joey or Ventilator touched on earlier but i can't seem to find it), but that wasn't getting anywhere, and i have loads of studying to do (for exams which won't ask questions like this ).

did anyone find out how much time candidates were given?
Quote:

Congratulations on your job at nVidia.


haha i wouldn't want a job there.

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162338
10/30/07 01:21
10/30/07 01:21
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
Code:
temp = 0
def rand7():
global temp
temp += rand5() + 5*rand5()
return temp % 7 + 1

how about joey's solution but with a second rand5()? wouldn't the predictability be negligible then?

...
i think nvidia just wants to hear something like: you either need a conditional which will result in non predictable runtime or you have to live with some small error in the probability distribution.

the question is how much time you have to find this answer. if you have a whole day to experiment and write test programs it wouldn't be that hard.

Re: NVidia Number Test [Re: ventilator] #162339
10/30/07 01:24
10/30/07 01:24
Joined: Mar 2006
Posts: 3,538
WA, Australia
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
i gotta say i really like that answer

julz


Formerly known as JulzMighty.
I made KarBOOM!
Re: NVidia Number Test [Re: JibbSmart] #162340
10/30/07 20:35
10/30/07 20:35
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
IMHO: When you need a random number you want it to be truly random.
Predictable is not always a bad thing, but you want random distribution.
So "(rand5() + 5*rand5())%7 + 1" would not be a valid answer.

Quote:


the question is how much time you have to find this answer. if you have a whole day to experiment and write test programs it wouldn't be that hard.




Normally they ask these questions during an on-site interview, but this could be a take home test to help weed out candidates.

Even with a whole day, most people wouldn't get it right.

Quote:

as i said, it seems impossible to acheive both equal distribution and no predictability without at least one branch.




Nope. It is possible but (as far as I can see) not practical.
One method involves generating the numbers "offline" and just using a lookup table. Another method requires very large numbers.


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Re: NVidia Number Test [Re: Doug] #162341
10/30/07 21:20
10/30/07 21:20
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
well you could sort-of write your own random number generator without using a single branch or loop, but then you could skip using rand5 anyway.

Re: NVidia Number Test [Re: Joey] #162342
11/01/07 00:07
11/01/07 00:07
Joined: Jul 2000
Posts: 8,973
Bay Area
Doug Offline
Senior Expert
Doug  Offline
Senior Expert

Joined: Jul 2000
Posts: 8,973
Bay Area
Joey: That is certainly thinking "outside the box". But I'm guessing nVidia wants you to use rand5.

Besides, can you write a true random number generator that ran quicker?


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI
Page 6 of 7 1 2 3 4 5 6 7

Moderated by  jcl, Lukas, old_bill, Spirit 

Kompaktes W�rterbuch des UnendlichenCompact Dictionary of the Infinite


Powered by UBB.threads™ PHP Forum Software 7.7.1