/* Lotto not two consecutive numbers in Picat. From some unknown source, but I quoted it here: http://www.hakank.org/sims/simulering.html """ One day I was asked What is the probability that no two numbers are consecutive in a lottery draw? Information: National Lottery in UK is to draw 6 different numbers from 1 to 49. so, for example, (a) 1 4 7 12 19 44 - no consecutive numbers (b) 3 6 17 18 44 46 - 17 and 18 are consecutive (c) 1 2 3 17 29 49 - 1, 2 and 3 are consecutive We are asking the probability that class (a) occurs. Hope this is clear. Observation shows that it is NOT a small number (actually near half-and-half). ...... A Monte Carlo simulation experiment produced 50,558 sets of six numbers between 1 and 49 with none consecutive out of 100,000 trials giving an estimated probability of .50558. """ Cf my Gamble model gamble_lotto_not_two_consecutive_numbers.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 : prob Probabilities: true: 0.5066666666666667 false: 0.4933333333333333 mean = [true = 0.506667,false = 0.493333] var : s Probabilities: 0: 0.5066666666666667 1: 0.3849666666666667 2: 0.0988666666666667 3: 0.0092666666666667 4: 0.0002333333333333 mean = 0.611433 */ go ?=> reset_store, run_model(30_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths, % fail, nl. go => true. model() => N = 49, % Numbers 1..49 M = 6, % 6 numbers are drawn A = 1..N, % The selected Lotto numbers Lotto = draw_without_replacement(M,A).sort, % Check if there's any consecutive numbers S = sum([1 : I in 1..M-1, Lotto[I+1]-Lotto[I] == 1]), Prob = check(S == 0), add("s",S), add("prob",Prob).