/* Stick to Triangle in Picat. From https://brainstellar.com/puzzles/probability/102 """ A stick is broken into 3 parts, by choosing 2 points randomly along its length. With what probability can it form a triangle? """ Cf my Gamble model gamble_stick_to_triangle.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 : p Probabilities: false: 0.7470000000000000 true: 0.2530000000000000 mean = [false = 0.747,true = 0.253] var : p2 Probabilities: false: 0.7470000000000000 true: 0.2530000000000000 mean = [false = 0.747,true = 0.253] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. model() => % Split the stick in 3 random pieces T = dirichlet_dist([1,1,1]), A = T[1], B = T[2], C = T[3], % Triangle inequality P = check(( A <= B + C, B <= A + C, C <= A + B)), % All pieces < 0.5 P2 = check( (A < 0.5, B < 0.5, C < 0.5)), add("p",P), add("p2",P2).