/* Controversy about the weekday in Picat. From the German https://www.logisch-gedacht.de/logikraetsel/wochentag/ translated by Google Translate """ Seven friends met and disagreed, which day of the week was: Klaus: Today is Tuesday. Sabine: No, that is not correct. Tomorrow is Tuesday. Lutz: It is both wrong. Yesterday was Tuesday. Claudia: No, Lutz, yesterday was Saturday! Susanne: Today is either Thursday or Friday. Fritz: I do not believe that. Today is Sunday. Sophia: No, today is not Sunday. Only one person is correct with their statement. Determine the day of the week when the friends met! """ Solution: sat The solution comments: """ The meeting took place on a Saturday because two statements are correct for every other day of the week. """ Without the sum(truth) = 1 (and adding fail) the following solutions are generated: today = [6,sat] truth = [0,0,0,0,0,0,1] today = [4,thu] truth = [0,0,0,0,1,0,1] today = [5,fri] truth = [0,0,0,0,1,0,1] today = [7,sun] truth = [0,0,0,1,0,1,0] today = [3,wed] truth = [0,0,1,0,0,0,1] today = [1,mon] truth = [0,1,0,0,0,0,1] today = [2,tue] truth = [1,0,0,0,0,0,1] where we see that all days except Saturdat is covered by two statements. Only the negative statement by Sophia (No, today is not Sunday) is correct. This Picat model 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, L = [Mon,Tue,Wed,Thu,Fri,Sat,Sun], L = 1..N, S = [mon,tue,wed,thu,fri,sat,sun], % decision variables Today :: 1..7, Truth = new_list(N), % truthfullness of a speaker Truth :: 0..1, % 1 2 3 4 5 6 7 % mon,tue,wed,thu,fri,sat,sun % Klaus: Today is Tuesday. Truth[1] #= 1 #<=> Today #= Tue, % Sabine: No, that is not correct. Tomorrow is Tuesday. Truth[2] #= 1 #<=> Today #= Tue-1, % Lutz: It is both wrong. Yesterday was Tuesday. Truth[3] #= 1 #<=> Today #= Tue+1, % Claudia: No, Lutz, yesterday was Saturday! Truth[4] #= 1 #<=> Today #= Sat+1, % Susanne: Today is either Thursday or Friday. Truth[5] #= 1 #<=> Today :: [Thu,Fri], % Fritz: I do not believe that. Today is Sunday. Truth[6] #= 1 #<=> Today #= Sun, % Sophia: No, Today is not Sunday. Truth[7] #= 1 #<=> Today #!= Sun, % Only one person is correct with their statement. sum(Truth) #= 1, solve(Truth ++ [Today]), println(today=[Today,S[Today]]), println(truth=Truth), nl, fail, nl. go => true.