/* Gree for an Ace in Picat. https://brainstellar.com/puzzles/probability/209 """ What is the expected number of cards that need to be turned over in a regular 52-card deck in order to see the first ace? Answer: 53/5 [10.6] """ Cf my Gamble model gamble_greed_for_an_ace.rkt 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. import util. main => go. /* var : first ace Probabilities (truncated): 1: 0.0775500000000000 2: 0.0705000000000000 3: 0.0680000000000000 5: 0.0616000000000000 ......... 46: 0.0001000000000000 44: 0.0001000000000000 48: 0.0000500000000000 47: 0.0000500000000000 mean = 10.5983 Histogram (total 20000) 1: 1551 ############################################################ (0.078 / 0.078) 2: 1410 ####################################################### (0.070 / 0.148) 3: 1360 ##################################################### (0.068 / 0.216) 4: 1220 ############################################### (0.061 / 0.277) 5: 1232 ################################################ (0.062 / 0.339) 6: 1118 ########################################### (0.056 / 0.395) 7: 1051 ######################################### (0.053 / 0.447) 8: 974 ###################################### (0.049 / 0.496) 9: 956 ##################################### (0.048 / 0.544) 10: 828 ################################ (0.041 / 0.585) 11: 749 ############################# (0.037 / 0.622) 12: 767 ############################## (0.038 / 0.661) 13: 667 ########################## (0.033 / 0.694) 14: 629 ######################## (0.031 / 0.726) 15: 561 ###################### (0.028 / 0.754) 16: 560 ###################### (0.028 / 0.782) 17: 524 #################### (0.026 / 0.808) 18: 454 ################## (0.023 / 0.831) 19: 421 ################ (0.021 / 0.852) 20: 353 ############## (0.018 / 0.869) 21: 344 ############# (0.017 / 0.886) 22: 288 ########### (0.014 / 0.901) 23: 261 ########## (0.013 / 0.914) 24: 238 ######### (0.012 / 0.926) 25: 229 ######### (0.011 / 0.937) 26: 194 ######## (0.010 / 0.947) 27: 168 ###### (0.008 / 0.955) 28: 137 ##### (0.007 / 0.962) 29: 134 ##### (0.007 / 0.969) 30: 109 #### (0.005 / 0.974) 31: 95 #### (0.005 / 0.979) 32: 81 ### (0.004 / 0.983) 33: 67 ### (0.003 / 0.987) 34: 55 ## (0.003 / 0.989) 35: 51 ## (0.003 / 0.992) 36: 39 ## (0.002 / 0.994) 37: 32 # (0.002 / 0.995) 38: 25 # (0.001 / 0.997) 39: 23 # (0.001 / 0.998) 40: 14 # (0.001 / 0.998) 41: 10 (0.001 / 0.999) 42: 8 (0.000 / 0.999) 43: 3 (0.000 / 1.000) 44: 2 (0.000 / 1.000) 45: 4 (0.000 / 1.000) 46: 2 (0.000 / 1.000) 47: 1 (0.000 / 1.000) 48: 1 (0.000 / 1.000) */ go ?=> Deck = [1..13 : _ in 1..4].flatten, reset_store, run_model(20_000,$model(Deck),[show_probs_trunc,mean,show_histogram,histogram_limit=100]), nl, % show_store_lengths,nl, % fail, nl. go => true. model(Deck) => % ShuffledDeck = shuffle(Deck), ShuffledDeck = draw_without_replacement(Deck.len,Deck), FirstAce = find_first_of(ShuffledDeck,1), add("first ace",FirstAce).