/* The Bomb puzzle in Picat. From http://blog.kutterer.at/?p=7 """ The bomb has 7 flip switches. To disarm the bomb you must put the switches in their correct position. And you got this inforamtions: the bomb detonates when: 1. if switch 3 is on plus 2 and 4 are off, boom! 2. if 1 and 4 off plus 7 is on, boom! 3. if 1, 3 and 4 are off, boom! 4. if 6 is off plus 2 and 3 are on, boom! 5. if 4 and 3 are on, boom! 6. if 6 is on and if, as long as 7 is on, 1 is on too, boom! 7. if 6 is on and, provided 7 is on, 1 is on too, boom! 8. if 1 and 5 are on plus 7 is off, boom! 9. if 3 is off plus 4 and 5 are on, boom! 10. if 1 and 7 are on, boom! 11. if 5 off and if, as long as 2 and 6 are on, 3 is on too, boom! 12. if 7 off plus 3 or 4 on, boom! 13. if switch 6 and 7 are in different positions, boom! 14. if switch 2, 3 and 5 are off, boom! 15. if switch 1 and 2 are on and switch 5 and 7 are off, boom! 16. if 6 and 7 are off, boom! """ Originally from the German puzzle Die Bombe by Angela and Otto Janko http://www.janko.at/Raetsel/Logik/012.a.htm This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => N = 7, X = new_list(N), % the switches X :: 0..1, #~( % 1. if switch 3 is on plus 2 and 4 are off, boom! (X[3] #/\ X[2] #= 0 #/\ X[4] #= 0) % 2. if 1 and 4 off plus 7 is on, boom! #\/ (X[1] #= 0 #/\ X[4] #= 0 #/\ X[7]) % 3. if 1, 3 and 4 are off, boom! #\/ (X[1] #= 0 #/\ X[3] #= 0 #/\ X[4] #= 0) % 4. if 6 is off plus 2 and 3 are on, boom! #\/ (X[6] #= 0 #/\ X[2] #/\ X[3]) % 5. if 4 and 3 are on, boom! #\/ (X[4] #/\ X[3]) % 6. if 6 is on and if, as long as 7 is on, 1 is on too, boom! #\/ (X[6] #/\ X[7] #/\ X[1]) % 7. if 6 is on and, provided 7 is on, 1 is on too, boom! #\/ (X[6] #/\ X[7] #/\ X[1]) % 8. if 1 and 5 are on plus 7 is off, boom! #\/ (X[1] #/\ X[5] #/\ X[7] #= 0) % 9. if 3 is off plus 4 and 5 are on, boom! #\/ (X[3] #= 0 #/\ X[4] #/\ X[5]) % 10 if 1 and 7 are on, boom! #\/ (X[1] #/\ X[7]) % 11. if 5 off and if, as long as 2 and 6 are on, 3 is on too, boom! #\/ (X[5] #= 0 #/\ X[2] #/\ X[6] #/\ X[3]) % 12. if 7 off plus 3 or 4 on, boom! #\/ (X[7] #= 0 #/\ (X[3] #\/ X[4])) % 13. if switch 6 and 7 are in different positions, boom! #\/ (X[6] #!= X[7]) % 14. if switch 2, 3 and 5 are off, boom! #\/ (X[2] #= 0 #/\ X[3] #= 0 #/\ X[5] #= 0) % 15. if switch 1 and 2 are on and switch 5 and 7 are off, boom! #\/ (X[1] #/\ X[2] #/\ X[5] #= 0 #/\ X[7] #= 0) % 16. if 6 and 7 are off, boom! #\/ (X[6] #= 0 #/\ X[7] #= 0) ), solve(X), println(X), fail, nl. % A different approach. go2 => defuse(L), println(L), fail. defuse([A,B,C,D,E,F,G]) :- per_bin([_,_,_,_,_,_,_],[A,B,C,D,E,F,G]), not(boom([A,B,C,D,E,F,G])). per_bin([],[]). per_bin([X|Xs],[X|Ys]) :- member(X,[0,1]), per_bin(Xs,Ys). % 1 2 3 4 5 6 7 boom([_,0,1,0,_,_,_]). boom([0,_,_,0,_,_,1]). boom([0,_,0,0,_,_,_]). boom([_,1,1,_,_,0,_]). boom([_,_,1,1,_,_,_]). boom([1,_,_,_,_,1,1]). boom([1,_,_,_,1,_,0]). boom([_,_,0,1,1,_,_]). boom([1,_,_,_,_,_,1]). boom([_,1,1,_,0,1,_]). boom([_,_,1,1,_,_,0]). boom([_,_,_,_,_,0,1]). boom([_,_,_,_,_,1,0]). boom([_,0,0,_,0,_,_]). boom([1,1,_,_,0,_,0]). boom([_,_,_,_,_,0,0]).