Perl: the Markov chain saw | |
PerlMonks |
RE: RE: RE: Kris Kringle Scriptby turnstep (Parson) |
on Apr 28, 2000 at 21:05 UTC ( [id://9609]=note: print w/replies, xml ) | Need Help?? |
>In theory (extrapolating here) you could get caught in a
Well, *in theory* yes, but considering that perl can generate well over 100,000 random numbers per second on even a slow machine, the odds of an infinite loop are, well, infinitely small. The odds of it taking over 1 second are pretty slim, too. Nothing to worry about here. >This script is interesting, I think, as it is typical of
Actually, I tested mine extensively - that's how I found the last person "gotcha". A simple rewrite of one line to takes care of that.
>Anyway, just a note to say that my solution, or code
Your code *does* have that problem - if everyone else is used up, it assigns a null Kris Kringle. Try this out:
Now run that with a data set like this:
When aaron and bob get each other, cindy gets nothing:
The chance of it happening decreases with the total number of people, but it can still happen....
In Section
Code Catacombs
|
|