/* Uniform dice in Picat. From Mind Your Decisions """ You are given a normal die and a blank die. (Each die is six-sided and equally likely to show each face). Label the blank die using the numbers 0 to 6 so that when you roll the two die the sum shows each whole number from 1 to 12 with equal chance. You can use a number more than once, or not at all, so you could label the faces 1, 2, 3, 4, 4, 5. But you do have to label all six faces of the blank die. """ Also, https://www.youtube.com/watch?v=u4wGKkbzFOY&feature=youtu.be Solution: x1 = [1,2,3,4,5,6] x2 = [0,0,0,6,6,6] 1: 3 2: 3 3: 3 4: 3 5: 3 6: 3 7: 3 8: 3 9: 3 10: 3 11: 3 12: 3 This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> N = 6, % number of sides of a die M = 6, % maximal integer of die (0..M) M2 = M*2, X1 = 1..N, X2 = new_list(N), X2 :: 0..M, Dist = new_list(M2), Dist :: 0..N*N, Z :: 0..M2, % constraints Z #= sum([Dist[K] #> 0: K in 1..M2]), foreach(K in 1..M2) Dist[K] #= sum([(X1[I] + X2[J]) #= K : I in 1..N, J in 1..N]) end, same(Dist), Z #= 2*N, % redundant sum(Dist) #= N*N, % symmetry breaking increasing(X2), solve($[ff,split], X2), println(x1=X1), println(x2=X2), foreach(K in 1..M2) printf("%2d: %d\n", K, Dist[K]) end, nl, fail, nl. go => true. % Slightly different approach: % replace the Dist list with single decision variable Z go2 ?=> N = 6, % number of sides of a die M = 6, % maximal integer of die (0..M) M2 = M*2, X1 = 1..N, X2 = new_list(N), X2 :: 0..M, Z :: 0..M2, % constraints foreach(K in 1..M2) Z #= sum([(X1[I] + X2[J]) #= K : I in 1..N, J in 1..N]) end, % symmetry breaking increasing(X2), solve($[ff,split], X2), println(x1=X1), println(x2=X2), println(z=Z), foreach(K in 1..M2) printf("%2d: %d\n", K, Z) end, nl, nl, fail, nl. go2 => true. same(X) => foreach(K in 1..X.len-1) X[K] #= X[K+1] end.