/* Two single persons at the end of the row in Picat. From Adrian Groza: "Measuring reasoning capabilities of ChatGPT" https://www.researchgate.net/publication/374588335_Measuring_reasoning_capabilities_of_ChatGPT page 139 """ Puzzle 81. Two single persons at the end of the row Four married men and three unmarried men are seated in a row at random. What are the chances that the two men at the ends of the row will be single? (adapted from puzzle 470 from Dudeney (2016)) """ The probability is 720/5040 (0.142857) [n1 = 5040,n2 = 720,prob = 0.142857] Also, see Groza's book (from which this puzzle is taken): https://users.utcluj.ro/~agroza/puzzles/maloga/codes.html This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. import cp. main => go. % Constraint modelling go => N = 7, X1 = new_list(7), X1 :: 1..N, all_different(X1), AllN1 = solve_all(X1).len, X2 = new_list(7), X2 :: 1..N, all_different(X2), % Encode married as odd numbers and unmarried as even numbers X2[1] mod 2 #= 0, X2[N] mod 2 #= 0, AllN2 = solve_all(X2).len, println([n1=AllN1,n2=AllN2,prob=(AllN2/AllN1)]), nl. % Imperative approach % (Same encoding of married/unmarried) go2 => N = 7, Perms = permutations(1..N), N1 = Perms.len, N2 = [1 : Perm in Perms, Perm.first mod 2 == 0, Perm.last mod 2 == 0].len, println([n1=N1,n2=N2,prob=(N2/N1)]), nl. % Shorter variant go3 => L = [V : Perm in permutations(1..7), V = cond((Perm.first mod 2 == 0, Perm.last mod 2 == 0),1,0)], println([n1=L.len,n2=L.sum,prob=(L.sum/L.len)]), nl.