/* 100 coin tosses in sequence in Picat. What is the probability that in 100 recorded coin tosses there are first 50 heads and then 50 tails? For 10 coin tosses: - the probability that the first 5 are 1s and the last 5 are 0s is 1/(2**10) = 1/1024 (0.0009765625) - the probability of exactly 2 runs is 9/512 (0.017578125) For 100 coin tosses - the probability that the first 50 are 1s and the last 50 are 0s is 1/(2**100) = 1/1267650600228229401496703205376 = very small and too small to simulated Cf my Gamble model gamble_coins_in_sequence.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. /* For 10 coins: var : p Probabilities: 0: 0.9992000000000000 1: 0.0008000000000000 mean = 0.0008 [len = 10000,min = 0,mean = 0.0008,median = 0.0,max = 1,variance = 0.00079936,stdev = 0.028273] var : p2 Probabilities: 0: 0.9823000000000000 1: 0.0177000000000000 mean = 0.0177 [len = 10000,min = 0,mean = 0.0177,median = 0.0,max = 1,variance = 0.0173867,stdev = 0.131859] */ go ?=> reset_store, run_model(10_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 = 10, M = N // 2, X = random_integer_n(2,N), % first m are 1s and last m are 0s P = check1( (X[1..M].remove_dups == [1], X[M+1..N].remove_dups == [0])), Runs = get_runs(X), % Exactly two runs P2 = check1(Runs.len == 2), add("p",P), add("p2",P2).