/* Josh is lying when? in Picat. https://stackoverflow.com/questions/67650348/prolog-logical-task-find-out-when-josh-tells-the-truth """ Prolog logical task (find out when Josh tells the truth) Josh likes telling lies but he does it very methodically. He lies 6 days a week but always tells the truth on the seventh. Josh told you 3 facts in 3 consecutive days: - I lie on monday and tuesday. - Today is thursday,saturday or sunday. - I lie on wednesday and friday. Find out during which day of the week Josh tells the truth. """ The weekdays are sun..sat week = [0,0,1,0,0,0,0] vars = [0,0,1,0,0,0,0,1,2,3,0,0,3,1] truthDay = 3 = Tuesday today = 2 = Monday I.e. Josh is telling the truth on Tuesday. This model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. import cp. main => go. go ?=> % Days of truth / lying % What week calendar is used? % This don't work. % 1 2 3 4 5 6 7 % Week = [Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday], % WeekS = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'], % L = [MondayD,TuesdayD,WednesdayD,ThursdayD,FridayD,SaturdayD,SundayD], % L = 1..L.len, % But this work, so it's a Sun..Sat calendar. % 1 2 3 4 5 6 7 Week = [_Sunday,Monday,Tuesday,Wednesday,_Thursday,Friday,_Saturday], WeekS = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'], L = [SundayD,_MondayD,_TuesdayD,_WednesdayD,ThursdayD,_FridayD,SaturdayD], L = 1..L.len, Week :: 0..1, sum(Week) #= 1, % Telling the truth on one day of the week % The three days Yesterday :: 1..7, Today :: 1..7, Tomorrow :: 1..7, Today #= Yesterday + 1, Tomorrow #= Today + 1, % "Yesterday": I lie on monday and tuesday. element(Yesterday,Week,YesterdayTruth), YesterdayTruth #= 1 #= 1 #<=> (Monday #= 0 #/\ Tuesday #= 0), % "Today": Today is thursday,saturday or sunday. element(Today,Week,TodayTruth), TodayTruth #= 1 #<=> (Today #= ThursdayD #\/ Today #= SaturdayD #\/ Today #= SundayD), % "Tomorrow": I lie on wednesday and friday. element(Tomorrow,Week,TomorrowTruth), TomorrowTruth #= 1 #<=> (Wednesday #= 0 #/\ Friday #= 0), YesterdayTruth + TodayTruth + TomorrowTruth #<= 1, Vars = Week ++ [Yesterday,Today,Tomorrow,YesterdayTruth,TodayTruth,Tomorrow,TomorrowTruth], solve(Vars), println(week=Week), println(vars=Vars), element(TruthDay,Week,1), nth(TruthDay,WeekS,TruthDayS), println(truthDay=TruthDay=TruthDayS), nth(Today,WeekS,TodayS), println(today=Today=TodayS), nl, fail, nl. go => true.