Page 1 of 5

Get the Princess!

Posted: Thu Sep 09, 2010 8:47 pm
by Trond
After wrestling for about six hours I finally solved (I think) this really hard riddle. Most of the time was spent trying to understand the problem. Here I present it for you. The original was in Swedish, which further complicated my quest, just for you I will translate it into English at no charge :lol: (let's hope I translate it correctly!).


HE GOT THE PRINCESS

Once upon a time there was a king who gave a life sentenced prisoner the opportunity to select one of eight doors. Behind one of the doors stood the princess. Behind each of the others, were either a tiger or nothing. If the prisoner chose the princess he would be discharged (freed from prison) and get to marry the princess. If he chose an empty room, he would be thrown back into prison, and if he chose a tiger, he would be eaten by it.

On each of the eight doors there was a sign. The sign on the door of the princess was true, while the signs on the doors of the tigers were false. The signs on the empty rooms were either true or false.

The signs looked like this:
1. Room 4 is not empty.
2. Sign 5 is true and the princess is not in this room.
3. Room 2 and 7 are not empty.
4. Room 1 is not empty.
5. Sign 6 is true.
6. Sign 2 is false and room 8 is empty.
7. The princess is in a room with an odd number.
8. This room contains a tiger and sign 3 is false.

In which room was the princess?

A big cheers for you if you can get it right (no, I'm not posting the answer yet).

Below is the original Swedish version, so everyone (who knows the language) can check that the translation is correct.
Nr 3g - HAN FICK PRINSESSAN

Det var en gång en kung som gav en livstidsfånge chansen att välja mellan
åtta dörrar. Bakom en av dörrarna stod prinsessan. Bakom de andra fanns en tiger
eller ingenting. Om fången valde prinsessan skulle han bli fri och få gifta sig med
henne, valde han ett tomt rum skulle han åter kastas i fängelse och valde han en tiger,
ja då skulle han bli uppäten av den. På varje dörr fanns en skylt.
Skylten på prinsessans dörr var rätt medan skyltarna på tigrarnas dörrar var fel.
Skyltarna på de tomma dörrarna var antingen rätt eller fel.

Skyltarna såg ut så här:
1. Rum 4 är inte tomt.
2. Skylt 5 är rätt och prinsessan är inte i detta rum.
3. Rum 2 och 7 är inte tomma.
4. Rum 1 är inte tomt.
5. Skylt 6 är rätt.
6. Skylt 2 är fel och rum 8 är tomt.
7. Prinsessan är i ett rum med ojämt nummer
8. Detta rum innehåller en tiger och skylt 3 är fel.

I vilket rum fanns prinsessan?

Re: Get the Princess!

Posted: Thu Sep 09, 2010 9:51 pm
by Rook Zimbabwe
7

It is an odd number and the sign does NOT say the princess is NOT inside...

A murderer is condemned to death. He has to choose between three rooms. The first is full of raging fires, the second is full of assassins with loaded guns and the third is full of lions that haven't eaten in 3 years. Which room is safest for him?

Re: Get the Princess!

Posted: Thu Sep 09, 2010 9:52 pm
by Perkin
After just 5 mins
I think there may be problems with translation,

6. ---room 8 is empty
8. This room contains a tiger

One must be wrong. (unless 6.---room 8 is false)
(doesn't matter anyway as Princess is in odd numbered room anyway)

2. Sign 5 is true and the princess is not in this room.

Does that mean she's not in this room (2) or room 5, depends if two statements or one.

I've got it down to one of three rooms, but depending on meanings, can't narrow it further.

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:04 pm
by Trond
Rook Zimbabwe wrote:7
It is an odd number and the sign does NOT say the princess is NOT inside...
This applies to 3 and 5 as well.
Perkin wrote:After just 5 mins
I think there may be problems with translation,
There is not. Ma Egluch izt purrrvucked. Just read again. It is not known which of the signs are true and which are not. ("The sign on the door of the princess was true, while the signs on the doors of the tigers were false. The signs on the empty rooms were either true or false.") The big job is finding out which signs are true and which are false.
One must be wrong. (unless 6.---room 8 is false)
Correct. One of the signs has to be false.
(doesn't matter anyway as Princess is in odd numbered room anyway)
Unless sign 7 is false.
2. Sign 5 is true and the princess is not in this room.
It means she is not in room 2.

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:07 pm
by freak
When in doubt... use brute force! :mrgreen:

Code: Select all

Enumeration
  #Princess
  #Tiger
  #Empty
EndEnumeration

Procedure CheckSigns(Array Rooms.l(1))
  Protected Dim Signs.l(8)

  ; Sign 1
  If Rooms(4) <> #Empty
    Signs(1) = #True    
  EndIf
  If (Rooms(1) = #Princess And Signs(1) = #False) Or (Rooms(1) <> #Princess And Signs(1) = #True)
    ProcedureReturn #False
  EndIf

  ; Sign 3
  If Rooms(2) <> #Empty And Rooms(7) <> #Empty
    Signs(3) = #True
  EndIf
  If (Rooms(3) = #Princess And Signs(3) = #False) Or (Rooms(3) <> #Princess And Signs(3) = #True)
    ProcedureReturn #False
  EndIf
  
  ; Sign 4
  If Rooms(1) <> #Empty
    Signs(4) = #True
  EndIf
  If (Rooms(4) = #Princess And Signs(4) = #False) Or (Rooms(4) <> #Princess And Signs(4) = #True)
    ProcedureReturn #False
  EndIf
  
  ; Sign 7
  For i = 1 To 8
    If i % 2 = 1 And Rooms(i) = #Princess
      Signs(7) = #True
      Break
    EndIf
  Next i
  If (Rooms(7) = #Princess And Signs(7) = #False) Or (Rooms(7) <> #Princess And Signs(7) = #True)
    ProcedureReturn #False
  EndIf  
  
  ; Sign 8
  If Rooms(8) = #Tiger And Signs(3) = #False
    Signs(8) = #True
  EndIf
  If (Rooms(8) = #Princess And Signs(8) = #False) Or (Rooms(8) <> #Princess And Signs(8) = #True)
    ProcedureReturn #False
  EndIf 
  
  ; 2, 5 and 6 need a bit thinking
  
  ; The princeess can never be in Room 2, else its sign is false and that cannot be
  If Rooms(2) = #Princess
    ProcedureReturn #False
  EndIf
  
  ; .. but then for sign 2 to be false, sign 5 must be false, so no princess in room 5
  If Rooms(5) = #Princess
    ProcedureReturn #False
  EndIf
  
  ; ... same for sign 6
  If Rooms(6) = #Princess
    ProcedureReturn #False
  EndIf
  
  ; No princess in room 6, so its sign must be false. sign 2 is already false, so room 8 must be empty
  If Rooms(8) <> #Empty
    ProcedureReturn #False
  EndIf
  
  ; all signs checked, this is a solution
  ProcedureReturn #True
 
EndProcedure

; permutate all possibilitties
;
Dim Rooms.l(8)

For Princess = 1 To 8

  ; 7 fields to set with either tiger or no tiger, so everything from binary %0000000 to binary %1111111
  For x = %0000000 To %1111111
  
    For i = 1 To 8
      If i = Princess
        Rooms(i) = #Princess
      ElseIf i < Princess And x & (1 << (i-1))
        Rooms(i) = #Tiger
      ElseIf i > Princess And x & (1 << (i-2))
        Rooms(i) = #Tiger
      Else
        Rooms(i) = #Empty
      EndIf
    Next i
    
    If CheckSigns(Rooms())
      Debug "solution:"
      For i = 1 To 8
        If Rooms(i) = #Princess
          Debug "  " + Str(i) + ": Princess"
        ElseIf Rooms(i) = #Tiger
          Debug "  " + Str(i) + ": Tiger"
        Else
          Debug "  " + Str(i) + ": -"
        EndIf
      Next i
      c + 1
    EndIf
        
  Next x
Next Princess

Debug "Solutions: " + Str(c)

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:12 pm
by GWarner
Rook Zimbabwe wrote:A murderer is condemned to death. He has to choose between three rooms. The first is full of raging fires, the second is full of assassins with loaded guns and the third is full of lions that haven't eaten in 3 years. Which room is safest for him?
The third room, after not eating for three years all the lions would be dead and so not a threat.

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:19 pm
by luis
freak wrote:When in doubt... use brute force! :mrgreen:
GREAT !

:D

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:21 pm
by Trond
When in doubt... use brute force!
None of our solutions are the same! (Except for the princess position.)

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:27 pm
by freak
Note that the whole thing works without any tigers at all. Good for the king in case there is a tiger shortage in the country :D

Re: Get the Princess!

Posted: Thu Sep 09, 2010 10:54 pm
by Trond
freak wrote:Note that the whole thing works without any tigers at all. Good for the king in case there is a tiger shortage in the country :D
Actually, I think the reason my answers are different from yours, is that some of yours are wrong. It's impossible to do without a tiger.

See:
0. Assume we know the princess is in room 7
A. Sign 2 is true if sign 5 is true
B. Sign 2 is false if sign 5 is false
C. The truth value of sign 2 and 5 are equal.
D. Sign 5 is true if sign 6 is true.
E. Sign 5 is false if sign 6 is false.
F. The truth value of sign 5 and 6 are equal.
G. The truth value of sign 2, 5 and 6 are all equal.
H. If the truth value of sign 2 is true, the truth value of sign 6 must be true, but sign 6 can only be true if sign 2 is false. It thus leads that 2, 5 and 6 cannot be true, they must be false.
I. For sign 6 to be false when sign 2 is false, the statement "room 8 is empty" must be false.
J. If the statement "room 8 is empty" is false, something must be in room 8.
K. If the princess is in room 7, she cannot be in room 8.
L. There must be a tiger in room 8.

Re: Get the Princess!

Posted: Thu Sep 09, 2010 11:33 pm
by Arctic Fox
Trond wrote:H. If the truth value of sign 2 is true, the truth value of sign 6 must be true, but sign 6 can only be true if sign 2 is false. It thus leads that 2, 5 and 6 cannot be true, they must be false.
If sign 6 is false, and it says that sign 2 is false (which is a false statement), then sign 2 must be true? And then sign 6 must be true, too - I am confused :?

Re: Get the Princess!

Posted: Thu Sep 09, 2010 11:46 pm
by cas

Re: Get the Princess!

Posted: Fri Sep 10, 2010 9:44 am
by Trond
Arctic Fox wrote:
Trond wrote:H. If the truth value of sign 2 is true, the truth value of sign 6 must be true, but sign 6 can only be true if sign 2 is false. It thus leads that 2, 5 and 6 cannot be true, they must be false.
If sign 6 is false, and it says that sign 2 is false (which is a false statement), then sign 2 must be true? And then sign 6 must be true, too - I am confused :?
Yes, an unresolvable conflict occurs if sign 2, 5 or 6 is true. So we know all of them must be false. Because we can't have any unresolvable conflicts in our logic.

Re: Get the Princess!

Posted: Fri Sep 10, 2010 11:13 am
by gnasen
I did like we do it everytime at studies, just bring everything false on a contradiction.
It is very easy to show, that 1-6 and 8 ends very fast in a contradiction, assumed that the princess is in this cell. On the other hand if the princess is in cell 7, the assumption is true. However one has to be carefull: You have to show first, that 7 is true for all combinations of tigers and empty cells on number 1,3,5. This makes 8 possible cases. You can verify this easily by showing, that everyone of them is true, or just use the beautifull solution of freak ;)
Therefore it follows, that the princess must be in number 7.

Re: Get the Princess!

Posted: Fri Sep 10, 2010 12:36 pm
by blueznl
Gotta' love brute force :-)