/* Knights and Knaves: Marrying a rich Knave in Picat. From TPTP, PUZ021-1.p """ %-------------------------------------------------------------------------- % File : PUZ021-1 : TPTP v7.0.0. Released v1.0.0. % Domain : Puzzles % Problem : How to Win a Bride % Version : Especial. % English : Suppose you are an inhabitant of the island of 'knights' and % 'knaves'. The knights always tell the truth and the knaves % always lie. You fall in love with a girl there and wish % to marry her. However, this girl has strange tastes; for some % odd reason she does not wish to marry a knight; she wants % to marry only a knave. But she wants a rich knave, not a poor % one. (We assume for convenience that everyone is classified % as either rich or poor.) Suppose, in fact, that you are % a rich knave. You are allowed to make only one statement, can % you convince her that you are a rich knave? % Refs : [Smu78] Smullyan (1978), What is the Name of This Book? The Ri % : [Ohl85] Ohlbach (1985), Predicate Logic Hacker Tricks % Source : [Ohl85] % Names : Problem 95 [Smu78] % : How to Win a Bride [Ohl85] """ Some different approaches for a Knave to indicate that he is a Knave and Rich * The Knave says he is a knave and poor A #<=> (A #= Knave #/\ Status #= Poor) * The Knave says that he's not: Knight or Rich A #<=> #~(A #= Knight #\/ Status #= Rich) * The Knave says he is not a knight and not rich: A #<=> (A #!= Knight #/\ Status #!= Rich) This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import util. import cp. main => go. go ?=> Knave = 0, Knight = 1, Poor = 1, Rich = 2, A :: [Knave,Knight], Status :: [Poor,Rich], % The Knave says he is a knave and poor A #<=> (A #= Knave #/\ Status #= Poor), % [a = Knave,status = Rich] <-- % The Knave says that he's not: Knight or Rich % A #<=> #~(A #= Knight #\/ Status #= Rich), % [a = Knave,status = Rich] % The Knave says he is not a knight and not rich % A #<=> (A #!= Knight #/\ Status #!= Rich), % [a = Knave,status = Rich] Vars = [A,Status], solve(Vars), println([a=A,status=Status]), println([a=cond(A==0,"Knave","Knight"),status=cond(Status==1,"Poor","Rich")]), nl, fail, nl. go => true.