/* Snake Eyes in Picat. From Stand-up Maths: "Are these the luckiest dice rolls in TV history?" https://www.youtube.com/watch?v=XXKjDkmxixA The issue is that in 25 rolls there was (exactly) 5 snake eyes (two 1s). Which is quite rare. What is the probability of that? 0005001936611813 At least 5 Snake Eyes in 25 rolls: 0.0005517764084543 (These exact probabilities are from my PicatPrism model snake_eyes.pi) The theoretical value of exactly 5 Snake Eyes is Picat> X=binomial_dist_pdf(25,1/36,5) X = 0.000500193661181 The theoretical value of 5 or more Snake Eyes is Picat> X=(1-binomial_dist_cdf(25,1/36,5)) X = 0.000051582747273 This model is a port from my Racket/Gamble model gamble_snake_eyes.rkt. (Also see my PicatPRISM model prism/snake_eyes.pi) This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. main => go. /* n = 25 S: Histogram: 0: 4966 ############################################################ (0.497 / 0.497) 1: 3564 ########################################### (0.356 / 0.853) 2: 1174 ############## (0.117 / 0.970) 3: 248 ### (0.025 / 0.995) 4: 38 (0.004 / 0.999) 5: 9 (0.001 / 1.000) 6: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 9990 ############################################################ (0.999 / 0.999) 1: 10 (0.001 / 1.000) exact = 0.000051582747273 (14669 / 284378029) P2 (exactly 5 snake eyes): Histogram: 0: 9991 ############################################################ (0.999 / 0.999) 1: 9 (0.001 / 1.000) exact = 0.000047637491541 (47305 / 993020381) n = 50 S: Histogram: 0: 2411 ######################################## (0.241 / 0.241) 1: 3596 ############################################################ (0.360 / 0.601) 2: 2412 ######################################## (0.241 / 0.842) 3: 1088 ################## (0.109 / 0.951) 4: 353 ###### (0.035 / 0.986) 5: 106 ## (0.011 / 0.997) 6: 27 (0.003 / 0.999) 7: 6 (0.001 / 1.000) 8: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 9860 ############################################################ (0.986 / 0.986) 1: 140 # (0.014 / 1.000) exact = 0.002560201873657 (444506 / 173621465) P2 (exactly 5 snake eyes): Histogram: 0: 9894 ############################################################ (0.989 / 0.989) 1: 106 # (0.011 / 1.000) exact = 0.002113547155019 (179835 / 85086817) n = 100 S: Histogram: 0: 566 ############## (0.057 / 0.057) 1: 1744 ############################################ (0.174 / 0.231) 2: 2382 ############################################################ (0.238 / 0.469) 3: 2249 ######################################################### (0.225 / 0.694) 4: 1557 ####################################### (0.156 / 0.850) 5: 873 ###################### (0.087 / 0.937) 6: 383 ########## (0.038 / 0.975) 7: 175 #### (0.018 / 0.993) 8: 53 # (0.005 / 0.998) 9: 12 (0.001 / 0.999) 10: 3 (0.000 / 1.000) 11: 2 (0.000 / 1.000) 12: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 8498 ############################################################ (0.850 / 0.850) 1: 1502 ########### (0.150 / 1.000) exact = 0.060506873693423 (37913512 / 626598429) P2 (exactly 5 snake eyes): Histogram: 0: 9127 ############################################################ (0.913 / 0.913) 1: 873 ###### (0.087 / 1.000) exact = 0.038765147309606 (9202334 / 237386793) n = 200 S: Histogram: 0: 31 # (0.003 / 0.003) 1: 214 ####### (0.021 / 0.024) 2: 579 #################### (0.058 / 0.082) 3: 1127 ####################################### (0.113 / 0.195) 4: 1598 ####################################################### (0.160 / 0.355) 5: 1751 ############################################################ (0.175 / 0.530) 6: 1535 ##################################################### (0.153 / 0.683) 7: 1262 ########################################### (0.126 / 0.810) 8: 832 ############################# (0.083 / 0.893) 9: 542 ################### (0.054 / 0.947) 10: 302 ########## (0.030 / 0.977) 11: 131 #### (0.013 / 0.990) 12: 51 ## (0.005 / 0.996) 13: 28 # (0.003 / 0.998) 14: 9 (0.001 / 0.999) 15: 5 (0.001 / 1.000) 16: 2 (0.000 / 1.000) 17: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 3549 ################################# (0.355 / 0.355) 1: 6451 ############################################################ (0.645 / 1.000) exact = 0.481911384578246 (87245705 / 181040971) P2 (exactly 5 snake eyes): Histogram: 0: 8249 ############################################################ (0.825 / 0.825) 1: 1751 ############# (0.175 / 1.000) exact = 0.160203915105367 (15025307 / 93788638) n = 250 S: Histogram: 0: 10 (0.001 / 0.001) 1: 51 ## (0.005 / 0.006) 2: 221 ######### (0.022 / 0.028) 3: 534 ##################### (0.053 / 0.082) 4: 936 ##################################### (0.094 / 0.175) 5: 1263 ################################################## (0.126 / 0.301) 6: 1520 ############################################################ (0.152 / 0.454) 7: 1510 ############################################################ (0.151 / 0.605) 8: 1325 #################################################### (0.133 / 0.737) 9: 1003 ######################################## (0.100 / 0.837) 10: 721 ############################ (0.072 / 0.909) 11: 421 ################# (0.042 / 0.952) 12: 227 ######### (0.023 / 0.974) 13: 133 ##### (0.013 / 0.988) 14: 74 ### (0.007 / 0.995) 15: 26 # (0.003 / 0.998) 16: 13 # (0.001 / 0.999) 17: 5 (0.001 / 0.999) 18: 3 (0.000 / 1.000) 20: 2 (0.000 / 1.000) 21: 2 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 1752 ############# (0.175 / 0.175) 1: 8248 ############################################################ (0.825 / 1.000) exact = 0.695696306242989 (12988058 / 18669149) P2 (exactly 5 snake eyes): Histogram: 0: 8737 ############################################################ (0.874 / 0.874) 1: 1263 ######### (0.126 / 1.000) exact = 0.151717023758856 (47590131 / 313676935) n = 300 S: Histogram: 0: 2 (0.000 / 0.000) 1: 19 # (0.002 / 0.002) 2: 65 ### (0.006 / 0.009) 3: 214 ######### (0.021 / 0.030) 4: 476 #################### (0.048 / 0.078) 5: 774 ################################# (0.077 / 0.155) 6: 1140 ################################################# (0.114 / 0.269) 7: 1395 ############################################################ (0.140 / 0.409) 8: 1397 ############################################################ (0.140 / 0.548) 9: 1298 ######################################################## (0.130 / 0.678) 10: 1083 ############################################### (0.108 / 0.786) 11: 806 ################################### (0.081 / 0.867) 12: 568 ######################## (0.057 / 0.924) 13: 337 ############## (0.034 / 0.957) 14: 215 ######### (0.021 / 0.979) 15: 100 #### (0.010 / 0.989) 16: 63 ### (0.006 / 0.995) 17: 23 # (0.002 / 0.997) 18: 17 # (0.002 / 0.999) 19: 3 (0.000 / 0.999) 20: 5 (0.001 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 776 ##### (0.078 / 0.078) 1: 9224 ############################################################ (0.922 / 1.000) exact = 0.841191556159643 (122027443 / 145064988) P2 (exactly 5 snake eyes): Histogram: 0: 9226 ############################################################ (0.923 / 0.923) 1: 774 ##### (0.077 / 1.000) exact = 0.111892556293416 (41877273 / 374263261) n = 500 S: Histogram: 2: 2 (0.000 / 0.000) 3: 7 (0.001 / 0.001) 4: 18 # (0.002 / 0.003) 5: 36 ## (0.004 / 0.006) 6: 96 ##### (0.010 / 0.016) 7: 161 ######### (0.016 / 0.032) 8: 284 ############### (0.028 / 0.060) 9: 498 ########################### (0.050 / 0.110) 10: 724 ####################################### (0.072 / 0.183) 11: 869 ############################################### (0.087 / 0.269) 12: 964 #################################################### (0.096 / 0.366) 13: 1048 ######################################################## (0.105 / 0.471) 14: 1118 ############################################################ (0.112 / 0.582) 15: 996 ##################################################### (0.100 / 0.682) 16: 925 ################################################## (0.092 / 0.775) 17: 679 #################################### (0.068 / 0.842) 18: 507 ########################### (0.051 / 0.893) 19: 374 #################### (0.037 / 0.931) 20: 266 ############## (0.027 / 0.957) 21: 176 ######### (0.018 / 0.975) 22: 108 ###### (0.011 / 0.986) 23: 64 ### (0.006 / 0.992) 24: 43 ## (0.004 / 0.996) 25: 13 # (0.001 / 0.998) 26: 15 # (0.002 / 0.999) 27: 5 (0.001 / 1.000) 28: 2 (0.000 / 1.000) 29: 1 (0.000 / 1.000) 30: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 0: 27 (0.003 / 0.003) 1: 9973 ############################################################ (0.997 / 1.000) exact = 0.994522710165219 (96760281699305843 / 97293184670696142) P2 (exactly 5 snake eyes): Histogram: 0: 9964 ############################################################ (0.996 / 0.996) 1: 36 (0.004 / 1.000) exact = 0.008745289401372 (4869319 / 556793352) n = 1000 S: Histogram: 10.000: 2 (0.000 / 0.000) 11.125: 3 (0.000 / 0.001) 12.250: 6 (0.001 / 0.001) 13.375: 12 # (0.001 / 0.002) 14.500: 38 ## (0.004 / 0.006) 15.625: 39 ## (0.004 / 0.010) 16.750: 71 #### (0.007 / 0.017) 17.875: 121 ###### (0.012 / 0.029) 19.000: 186 ########## (0.019 / 0.048) 20.125: 262 ############# (0.026 / 0.074) 21.250: 336 ################# (0.034 / 0.108) 22.375: 430 ###################### (0.043 / 0.151) 23.500: 1171 ############################################################ (0.117 / 0.268) 24.625: 674 ################################### (0.067 / 0.335) 25.750: 746 ###################################### (0.075 / 0.410) 26.875: 794 ######################################### (0.079 / 0.489) 28.000: 784 ######################################## (0.078 / 0.568) 29.125: 733 ###################################### (0.073 / 0.641) 30.250: 663 ################################## (0.066 / 0.707) 31.375: 610 ############################### (0.061 / 0.768) 32.500: 969 ################################################## (0.097 / 0.865) 33.625: 333 ################# (0.033 / 0.898) 34.750: 283 ############### (0.028 / 0.927) 35.875: 232 ############ (0.023 / 0.950) 37.000: 153 ######## (0.015 / 0.965) 38.125: 103 ##### (0.010 / 0.975) 39.250: 87 #### (0.009 / 0.984) 40.375: 49 ### (0.005 / 0.989) 41.500: 65 ### (0.006 / 0.995) 42.625: 18 # (0.002 / 0.997) 43.750: 11 # (0.001 / 0.998) 44.875: 5 (0.001 / 0.999) 46.000: 4 (0.000 / 0.999) 47.125: 3 (0.000 / 1.000) 48.250: 2 (0.000 / 1.000) 49.375: 0 (0.000 / 1.000) 50.500: 1 (0.000 / 1.000) 51.625: 0 (0.000 / 1.000) 52.750: 0 (0.000 / 1.000) 53.875: 1 (0.000 / 1.000) P1 (5 or more snake eyes): Histogram: 1: 10000 ############################################################ (1.000 / 1.000) exact = 0.999999889847144 (72626343 / 72626351) P2 (exactly 5 snake eyes): Histogram: 0: 10000 ############################################################ (1.000 / 1.000) exact = 0.000000433786895 (701 / 1616000871) */ go ?=> Runs = 10000, member(N,[25,50,100,200,250,300,500,1000]), nl, println(n=N), reset_store, run_model(Runs,$snake_eyes(N),[show_probs,mean,show_histogram]), println(exact=binomial_dist_pdf(N,1/36,6).and_rat), nl, fail, nl. go => true. snake_eyes(N) => S = [ cond( (dice(6)==1,dice(6)==1),1,0) : _ in 1..N].sum, P1 = cond(S >= 5,1,0), % What is the probability that we see 5 or more snake eyes? P2 = cond(S == 5,1,0), % What is the probability that we see exactly 5snake eyes? add("s",S), add("p1",P1), add("p2",P2).