/* Ball entering Q in Picat. Cf my Gamble model gamble_ball_entering_q.rkt https://medium.com/intuition/a-probability-challenge-93d9936b9ef0 (Note: This page is not available) """ How likely is the ball to enter Q? o 0 | | / . \ 1 2 / . . \ 3 4 5 / . . . \ 6 7 8 9 / . . . . \ 10 11 12 13 14 |P|Q|R|S|T| P Q R S T """ 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 : p Probabilities: 0: 0.9389000000000000 1: 0.0611000000000000 mean = 0.0611 var : q Probabilities: 0: 0.7419000000000000 1: 0.2581000000000000 mean = 0.2581 var : r Probabilities: 0: 0.6214000000000000 1: 0.3786000000000000 mean = 0.3786 var : s Probabilities: 0: 0.7569000000000000 1: 0.2431000000000000 mean = 0.2431 var : t Probabilities: 0: 0.9409000000000000 1: 0.0591000000000000 mean = 0.0591 var : v Probabilities: r: 0.3786000000000000 q: 0.2581000000000000 s: 0.2431000000000000 p: 0.0611000000000000 t: 0.0591000000000000 mean = [r = 0.3786,q = 0.2581,s = 0.2431,p = 0.0611,t = 0.0591] The exact probabilities: P Q R S T 0.0625 0.25 0.375 0.25 0.0625 I.e. a normal distribution. */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. next(A,Paths) = Res => I = A.last, % What's last/current pin? if membchk(I,[p,q,r,s,t]) then Res = A else T = Paths[I+1], % Adjust for 0-based % Get the next Res = next(A ++ [condt(flip(0.5), T.first, T.second)] , Paths) end. model() => Paths = [[1, 2], % This is 0 based (from the Gamble model [3, 4], [4, 5], [6, 7], [7, 8], [8, 9], [p, q], [q, r], [r, s], [s, t] ], % How likely is the ball to enter Q? (and P,R,S,T) A = next([0],Paths), V = A.last, PP = check1(V == p), PQ = check1(V == q), PR = check1(V == r), PS = check1(V == s), PT = check1(V == t), % add("a",A), add("v",V), add("p",PP), add("q",PQ), add("r",PR), add("s",PS), add("t",PT).