/* 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 is a port of my Gamble model gamble_game_of_ur_problem.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 : num_rolls Probabilities: 7: 0.2115047351806384 6: 0.1988775868116450 5: 0.1662574535250789 8: 0.1560855840056121 9: 0.0964573833742546 4: 0.0729568572430726 10: 0.0487548228691687 11: 0.0298141003156787 12: 0.0122763942476324 13: 0.0056120659417748 14: 0.0007015082427219 16: 0.0003507541213609 15: 0.0003507541213609 mean = 6.97019 */ go ?=> reset_store, time2(run_model(100_000,$model,[show_probs,mean])), nl. go => true. model() => NumRolls = random_integer(17) + 3, % 0..16 + 3 SumRolls = random_integer_n(5,NumRolls).sum, % 0..4 observe(SumRolls == 13), if observed_ok then add("num_rolls",NumRolls) end.