------art_5624_31398283.1191160961804
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

2007/9/28, Ruby Quiz <james / grayproductions.net>:
>
> You just did some probability calculations, and don't know if the answers
> are
> correct.  So you write a program to verify the results.  If you have eight
> dice,
> and throw them all at once, what is the probability that there are AT
> LEAST
> three fives?  Try to write a program that find out the "number of
> desirable
> outcomes" / "number of possible outcomes" by iterating through all the
> possible
> outcomes of the dice throw.



Hi,


My solution can be found at http://pastie.caboo.se/102192


#At least 3 fives from 8 dice:
$ time ./rq141_probableiterations_rafc.rb 8 3

Number of desirable outcomes is 226491
Number of possible outcomes is 1679616

Probability is 0.134846893575674

real    0m20.526s
user    0m18.449s
sys     0m2.060s


#It can do non-cubic dice: at least 2 fives from a d10, 2 d6's and one d20:
$ ./rq141_probableiterations_rafc.rb -d,2d6,d20 -s 2
1 [1, 1, 1, 1]
889 [2, 2, 3, 9]
1777 [3, 3, 5, 17]
2665 [4, 5, 2, 5] <3553 [5, 6, 4, 13]
4441 [7, 2, 1, 1]
5329 [8, 3, 3, 9]
6217 [9, 4, 5, 17]
7105 [10, 6, 2, 5]

Number of desirable outcomes is 515
Number of possible outcomes is 7200

Probability is 0.0715277777777778


#Full show-off mode if launched without parameters:
$ ./rq141_probableiterations_rafc.rb
5 usual dice; # of sixes greater than # of ones:
1 [1, 1, 1, 1, 1]
501 [1, 3, 2, 6, 3]
1001 [1, 5, 4, 5, 5]
1501 [2, 1, 6, 5, 1]
2001 [2, 4, 2, 4, 3]
2501 [2, 6, 4, 3, 5] <3001 [3, 2, 6, 3, 1]
3501 [3, 5, 2, 2, 3]
4001 [4, 1, 4, 1, 5]
4501 [4, 3, 6, 1, 1]
5001 [4, 6, 1, 6, 3] <5501 [5, 2, 3, 5, 5]
6001 [5, 4, 5, 5, 1]
6501 [6, 1, 1, 4, 3]
7001 [6, 3, 3, 3, 5] <7501 [6, 5, 5, 3, 1]

Number of desirable outcomes is 2676
Number of possible outcomes is 7776

Probability is 0.344135802469136


3 tetrahedra (d4); sum of evens smaller than sum of odds:
1 [1, 1, 1] <2 [1, 1, 2]
3 [1, 1, 3] <4 [1, 1, 4]
5 [1, 2, 1]
6 [1, 2, 2]
7 [1, 2, 3] <8 [1, 2, 4]
9 [1, 3, 1] <10 [1, 3, 2] <11 [1, 3, 3] <12 [1, 3, 4]
13 [1, 4, 1]
14 [1, 4, 2]
15 [1, 4, 3]
16 [1, 4, 4]
17 [2, 1, 1]
18 [2, 1, 2]
19 [2, 1, 3] <20 [2, 1, 4]
21 [2, 2, 1]
22 [2, 2, 2]
23 [2, 2, 3]
24 [2, 2, 4]
25 [2, 3, 1] <26 [2, 3, 2]
27 [2, 3, 3] <28 [2, 3, 4]
29 [2, 4, 1]
30 [2, 4, 2]
31 [2, 4, 3]
32 [2, 4, 4]
33 [3, 1, 1] <34 [3, 1, 2] <35 [3, 1, 3] <36 [3, 1, 4]
37 [3, 2, 1] <38 [3, 2, 2]
39 [3, 2, 3] <40 [3, 2, 4]
41 [3, 3, 1] <42 [3, 3, 2] <43 [3, 3, 3] <44 [3, 3, 4] <45 [3, 4, 1]
46 [3, 4, 2]
47 [3, 4, 3] <48 [3, 4, 4]
49 [4, 1, 1]
50 [4, 1, 2]
51 [4, 1, 3]
52 [4, 1, 4]
53 [4, 2, 1]
54 [4, 2, 2]
55 [4, 2, 3]
56 [4, 2, 4]
57 [4, 3, 1]
58 [4, 3, 2]
59 [4, 3, 3] <60 [4, 3, 4]
61 [4, 4, 1]
62 [4, 4, 2]
63 [4, 4, 3]
64 [4, 4, 4]

Number of desirable outcomes is 20
Number of possible outcomes is 64

Probability is 0.3125


3 usual dice and 2 dodecahedra (d12): product greater than 1000
1 [1, 1, 1, 1, 1]
2501 [1, 3, 6, 5, 5]
5001 [1, 6, 5, 9, 9] <7501 [2, 3, 5, 2, 1]
10001 [2, 6, 4, 6, 5] <12501 [3, 3, 3, 10, 9] <15001 [3, 6, 3, 3, 1]
17501 [4, 3, 2, 7, 5]
20001 [4, 6, 1, 11, 9] <22501 [5, 3, 1, 4, 1]
25001 [5, 5, 6, 8, 5] <27501 [6, 2, 5, 12, 9] <30001 [6, 5, 5, 5, 1]

Number of desirable outcomes is 13926
Number of possible outcomes is 31104

Probability is 0.447723765432099


Regards,
Raf

------art_5624_31398283.1191160961804--