/* Which day of the week is today puzzle in Picat. From https://puzzling.stackexchange.com/questions/44321/which-day-of-the-week-is-today """ Which day of the week is today? 7 people are arguing what the current day of the week might be. Each states what he believes to know: 1. The day after tomorrow is Wednesday. 2. No, Wednesday is today. 3. You are both wrong, Wednesday is tomorrow. 4. Today is not Monday, nor Tuesday or Wednesday. 5. I think yesterday was Thursday. 6. No, yesterday was Tuesday. 7. Whatever. All I know is that yesterday was not Saturday. All of them, except one, is wrong. What day is it it? """ Solution: ts = [0,0,0,1,0,0,0] day = 6 = Sunday I.e. It's Sunday and the only correct answer is #4: Today is not Monday, nor Tuesday or Wednesday. 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, % Truthfulness of the people Ts = new_list(7), Ts :: 0..1, Days = [Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday], Days = 0..Days.len-1, DaysS = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"], % Day of the week: 0: Monday, 6: Sunday Day :: 0..N-1, % 1. The day after tomorrow is Wednesday. Ts[1] #<=> ((Day + 2) mod N) #= Wednesday, % 2. No, Wednesday is today. Ts[2] #<=> Day #= Wednesday, % 3. You are both wrong, Wednesday is tomorrow. Ts[3] #<=> (Day + 1) mod N #= Wednesday, % 4. Today is not Monday, nor Tuesday or Wednesday. Ts[4] #<=> (Day notin [Monday,Tuesday,Wednesday]), % 5. I think yesterday was Thursday. Ts[5] #<=> ((Day - 1) mod N) #= Thursday, % 6. No, yesterday was Tuesday. Ts[6] #<=> ((Day - 1) mod N) #= Tuesday, % 7. Whatever. All I know is that yesterday was not Saturday. Ts[7] #<=> ((Day - 1) mod N) #!= Saturday, % All of them, except one, is wrong. What day is it it? sum(Ts) #= 1, Vars = Ts ++ [Day], solve(Vars), println(ts=Ts), println(day=Day=DaysS[Day+1]), nl, fail, nl. go => true.