[Tutor] Use functions re avoid Re: Can the following algorithmbe improved?

Brian van den Broek bvande at po-box.mcgill.ca
Wed Aug 10 00:01:59 CEST 2005

Nathan Pinno said unto the world upon 2005-08-09 17:35:
> It printed 25.973 as the result.


>> I don't think I got the math wrong. My thinking is there are 52**6 
>> ways to choose 6 items from 52 if you don't care about duplicates, and 
>> 52*51*50*49*48*47 ways to choose if you do. (The first card can be any 
>> one of 52, the second any one of the 51 left, etc. 52! by contrast 
>> gives you all the ways 52 items can be ordered in a non-repeating 
>> sequence.)
>> Here is a very quick (and I am sure not too efficient) bit of code to 
>> give empirical support to my analysis:
>> <code>


>> </code>
>> Run that and I think you will find the values cluster around 25.85%.
>> (The code was written to be general. Play around with the values in 
>> the final [print] line. I get that 9 choices are enough over a 52 
>> termed sequence to give you more than 50% odds of duplicates.)
>> Best,
>> Brian vdB

Well, Nathan, 25.973 seems like a number that could well be in a 
cluster around 25.85 to me. :-)

Run it multiple times; you'll get different numbers each run. (It is a 
randomized process, after all!) They will be in a cluster around 
25.85. Run it enough times, and you'd eventually get 100, and 0 and 
everything in between. But, with 100000 runs, I don't feel like 
waiting for either case! Lower the runs value to get wider 
fluctuations. (I ran it about 50 times with the values as coded just 
to check behaviour before posting. All my results were between 
25.5'ish and 26.1'ish.)


Brian vdB

More information about the Tutor mailing list