/* Casino puzzle in Picat. From Muhammad Zain Sarwar "The Casino Puzzle That Breaks Your Expectations!" https://medium.com/puzzle-sphere/youll-never-guess-how-long-it-takes-to-lose-all-your-money-3a7d57e7ac98 """ You find yourself at a casino in Las Vegas, and the dealer presents you with a game. The rules are simple: You roll six dice at the same time and each dice is fair meaning every face (1, 2, 3, 4, 5, or 6) has an equal chance of appearing. You count how many different numbers appear on the dice. If exactly four distinct numbers show up, then you win $1. Otherwise, you lose $1. You start with $100 and play until you run out of money. Each round takes one minute to play. Puzzle Statement How long do you think it will take for you to lose all your money? """ Cf my Gamble model gamble_casino_puzzle.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. % import ordset. main => go. /* var : d Probabilities: 4: 0.5017000000000000 3: 0.2328500000000000 5: 0.2273500000000000 2: 0.0227500000000000 6: 0.0151500000000000 1: 0.0002000000000000 mean = 3.9787 [len = 20000,min = 1,mean = 3.9787,median = 4.0,max = 6,variance = 0.613146,stdev = 0.783037] var : p Probabilities: true: 0.5017000000000000 false: 0.4983000000000000 mean = 0.5017 show_simple_stats: no numeric data Since p > 0.5 the probability of loosing in the long run, is (on average) 0. */ go ?=> reset_store, run_model(20_000,$model,[show_probs_trunc,mean, show_simple_stats % , % show_percentiles, % show_hpd_intervals,hpd_intervals=[0.84,0.9,0.94,0.99,0.99999], % show_histogram, % min_accepted_samples=1000,show_accepted_samples=true ]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => N = 6, Game = random_integer1_n(6,N), D = Game.remove_dups.len, P = check(D == 4), add("d",D), add("p",P). /* But let's simulate this by setting the two stop cases to 0 or 200 so we can see the average number of runs needed. var : v Probabilities: 200: 0.6490000000000000 0: 0.3510000000000000 mean = 129.8 var : c Probabilities (truncated): 1970: 0.0020000000000000 10404: 0.0015000000000000 8872: 0.0015000000000000 7396: 0.0015000000000000 ......... 1026: 0.0005000000000000 1000: 0.0005000000000000 818: 0.0005000000000000 760: 0.0005000000000000 mean = 9385.34 The probability of ending when reaching 200 in this setup is thus about 0.65 and loosing is about 0.34. The mean number of runs is about 9 400 runs. */ go2 ?=> reset_store, run_model(2_000,$model2,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go2 => true. throw(N) = random_integer1_n(6,N).remove_dups.len. f(V,C,N) = Res => if V <= 0 ; V >= 200 then Res = [V,C] else if throw(N) == 4 then Res = f(V+1,C+1,N) else Res = f(V-1,C+1,N) end end. model2() => D = 6, [V,C] = f(100,0,D), add("v",V), add("c",C).