/* Smullyan's Lion and Unicorn problem in Picat. From Raymond Smullyans "What is the name of this book?", Chapter 4 "Alice in the Forest of Forgetfulness". Problems 47, 48, 49, 50. Lions lies on Mondays, Tuesdays, and Wednesdays. Unicorns lies on Thursdays, Fridays, and Saturdays. Solutions: problem47 today = 3 = thu problem48 today = 0 = mon problem49 problem50 today = 0 = mon today = 2 = wed 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 => _ = findall(_,problem47), nl, _ = findall(_,problem48), nl, _ = findall(_,problem49), nl, _ = findall(_,problem50), nl. % % Problem 47 % Lion: Yesterday was one of my lying days. % Unicorn: Yesterday was one of my lying days too. % % Solution: Today is Thursday (day 3) % problem47 => println("problem47"), truth_days(unicorn,Unicorn), truth_days(lion, Lion), Today :: 0..6, T1 #= 1+Today, T2 #= 1+ ((Today-1) mod 7), element(T1,Lion,LionWhen), element(T2,Lion,LionWhat), says(LionWhen, LionWhat #= 0), element(T1,Unicorn,UnicornWhen), element(T2,Unicorn,UnicornWhat), says(UnicornWhen, UnicornWhat #= 0), Vars = Today, solve(Vars), println(today=Today=which_day(Today)), fail, nl. % % Problem 48 % Lion: % 1) I lied yesterday % 2) I will lie two days after tomorrow % % Solution: Today is Monday (day 0) % problem48 => println("problem48"), truth_days(lion, Lion), Today :: 0..6, T1 #= 1+Today, T2 #= 1+(Today - 1) mod 7, element(T1,Lion,LionWhen), element(T2,Lion,LionWhat), says(LionWhen, LionWhat #= 0), T3 #= 1+(Today + 3) mod 7, element(T3,Lion,LionWhat2), says(LionWhen, LionWhat2 #= 0), Vars = Today, solve(Vars), println(today=Today=which_day(Today)), fail, nl. % Problem 49 % Lion: % 1) I lied yesterday % 2) I will lie again tomorrow % % Solution: On no day is this possible to say. % problem49 => println("problem49"), truth_days(lion,Lion), Today :: 0..6, T1 #= 1+(Today mod 7), T2 #= 1+(Today - 1) mod 7, element(T1,Lion,LionWhen), element(T2,Lion,LionWhat1), says(LionWhen, LionWhat1 #= 0), T3 #= 1+(Today + 1) mod 7, element(T3,Lion,LionWhat2), says(LionWhen, LionWhat2 #= 0), Vars = Today, solve(Vars), println(today=Today=which_day(Today)), fail, nl. % % Problem 50 % Lion: I lied yesterday and I will lie again tomorrow % % Solution: Today is either Monday or Wednesday. % problem50 => println("problem50"), truth_days(lion,Lion), Today :: 0..6, T1 #= 1+(Today mod 7), T2 #= 1+(Today - 1) mod 7, T3 #= 1+(Today + 1) mod 7, element(T1,Lion,LionWhen), element(T2,Lion,LionWhat1), element(T3,Lion,LionWhat2), says(LionWhen, LionWhat1 #= 0 #/\ LionWhat2 #= 0), Vars = Today, solve(Vars), println(today=Today=which_day(Today)), fail, nl. says(When, What) => When #= What. % Truthfullness of lion and unicorn. % start week with Monday (day 0) truth_days(unicorn,[1, 1, 1, 0, 0, 0, 1]). truth_days(lion, [0, 0, 0, 1, 1, 1, 1]). which_day(Day) = Days[Day+1] => Days = [mon,tue,wed,thu,fri,sat,sun].