Solution to prime dice (R J Mical puzzle)

Feb 7th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. % RJ Mical poses this puzzle: Write 12 distinct nonnegative integers on the faces of two dice such that the sum of any roll of the two dice is prime.
3. % The solution that minimizes the number on the largest face is: [0 6 24 54 66 84] [5 13 17 47 73 83].
4.
5. % This file finds that solution when passed as an input to the Clingo answer set solver. To run it, paste the contents of this file into the text box in the JavaScript version of Clingo at http://potassco.org/clingo/run, then click Run.
6.
7. % From https://oeis.org/A000040
8. prime(2;3;5;7;11;13;17;19;23;29;31;37;41;43;47;53;59;61;67;71;73;79;83;89;97;101;103;107;109;113;127;131;137;139;149;151;157;163;167;173;179;181;191;193;197;199;211;223;227;229;233;239;241;251;257;263;269;271).
9.
10. % Choose faces from the integers from 1 to 100, inclusive.
11. num(0..100).
12.
13. % Choose 6 different numbers for the faces of the first die.
14. 6 { die1(D) : num(D)} 6.
15.
16. % Choose 6 different numbers for the faces of the second die.
17. 6 { die2(D) : num(D), not die1(D)} 6 .
18.
19. % Rule out any potential solution in which two faces sum to a non-prime.
20. :- die1(A), die2(B), not prime(A+B).
21.
22.
23. % Find the largest face.
24. face(X) :- die1(X).
25. face(X) :- die2(X).
26. dominated(X) :- face(X), face(Y), Y > X.
27. largestface(X):- face(X), not dominated(X).
28.
29. % Minimize the size of the largest face.
30. #minimize {X : largestface(X)}.
31.
32. #show die1/1.
33. #show die2/1.