$10K coding deathmatch
Paul Seamons
paul at seamons.com
Fri Nov 3 11:56:07 MST 2006
Next fun problem based on the generator (not too hard - but interesting to
see):
For a specified max entries of 10 - figure out the the percentage chance of a
match.
paul at paul-laptop:~/yar/server/lib$ perl -e 'for(1..100000){print
join(" ",map{int(rand(200)-100)}1..1+rand(10-1)),"\n"}' |
perl -ape '$_="match\n";$i=0;while(++$i<@F){last if(abs$F[$i]-$F[$i-1]||
@F)>=@F and $_="not a $_"}'|grep -v not|wc -l
11256
So roughly 11%.
How about max entries of 100
paul at paul-laptop:~/yar/server/lib$ perl -e 'for(1..100000){print
join(" ",map{int(rand(200)-100)}1..1+rand(100-1)),"\n"}' |
perl -ape '$_="match\n";$i=0;while(++$i<@F){last if(abs$F[$i]-$F[$i-1]||
@F)>=@F and $_="not a $_"}'|grep -v not|wc -l
1008
So roughly 1.1%.
So I would assume that for your max entries of 10000 - your chances of a
matching entry would be .011%.
Paul
More information about the PLUG
mailing list