/* Game of Ur problem in Picat. https://www.allendowney.com/blog/2018/10/21/the-game-of-ur-problem/ """ Here’s a probability puzzle to ruin your week. In the Royal Game of Ur, players advance tokens along a track with 14 spaces. To determine how many spaces to advance, a player rolls 4 dice with 4 sides. Two corners on each die are marked; the other two are not. The total number of marked corners — which is 0, 1, 2, 3, or 4 — is the number of spaces to advance. For example, if the total on your first roll is 2, you could advance a token to space 2. If you roll a 3 on the next roll, you could advance the same token to space 5. Suppose you have a token on space 13. How many rolls did it take to get there? """ See: https://www.allendowney.com/blog/lions-and-tigers-and-bears/ Allen Downey's solution: http://nbviewer.jupyter.org/github/AllenDowney/ThinkBayes2/blob/master/solutions/game_of_ur_soln.ipynb?flush=true This model uses another approach (recursion) than ppl_game_of_ur_problem.pi This is a port of my Gamble model gamble_game_of_ur_problem2.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. main => go. /* var : len Probabilities: 6: 0.2304781818634406 7: 0.2015034973738581 5: 0.1894307121698653 8: 0.1341448236377667 9: 0.0834889104622508 4: 0.0800288751151271 10: 0.0452293829188759 11: 0.0209344584671297 12: 0.0087372115600030 13: 0.0034849276877505 14: 0.0015184327782341 15: 0.0006472008562965 16: 0.0002240310656411 17: 0.0001493540437607 mean = 6.75503 */ go ?=> reset_store, time2(run_model(100_000,$model,[show_probs,mean])), nl. go => true. roll(A) = Ret => S = A.sum, if (S == 13) then Ret = A else if S > 13 then Ret = [] else Ret = roll( A++ [random_integer(5)]) end end. model() => A = roll([]), observe(A.sum == 13), if observed_ok then add("len",A.len) end.