Get the Princess!

For everything that's not in any way related to PureBasic. General chat etc...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Get the Princess!

Post by Trond »

blueznl wrote:Gotta' love brute force :-)
It's a good idea, but as I said, freak's brute forced solutions are wrong.
- It can be proven that there must be a tiger in room 8. None of the solutions include a tiger in room 8.
- It can be proven that sign 3 is always true. Thus there can't be a tiger in it. 4 of the solutions include a tiger in room 3.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 5046
Joined: Sun Apr 12, 2009 6:27 am

Re: Get the Princess!

Post by RASHAD »

The PRINCESS in #6
The Tiger in #7
Egypt my love
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: Get the Princess!

Post by Arctic Fox »

@Trond
The sign of room 8 says that this room contains a tiger. But if it contains a tiger the sign must be false. And thus it cannot contain a tiger which the sign claims, right?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Get the Princess!

Post by blueznl »

Oh bugger, now I'm tempted. Let's see if I can solve this one...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Get the Princess!

Post by freak »

Trond wrote:
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.
Yes, i misread the sign 8 when i did my code. If i correct it however, i get no solutions at all. Here is why:

A. If the princess is in room 7, then all other signs must be false.
B. for sign 6 to be false, room 8 may _not_ be empty (as "sign 2 is false" is true)
C. for sign 8 to be false, room 8 _must_ be empty (as "sign 3 is false" is true, and it does not contain the princess)

So either both our logic concerning signs 2, 5 and 6 is wrong, or 7 is not the answer.

Lets start again:

A. If sign 7 is true, the princess must be in room 7.
B. As i showed above, that leads to an impossibility.
C. If sign 7 is false, the princess cannot be in 1, 3, 5, 7, leaving only 2, 4, 6, 8
D. Room 2 is out, because its sign can never become true with a princess in it
E. Room 4 is out, because if there is a princess in it, sign 1 becomes true
F. Room 6 is out, because if she is in room 6, then sign 6 is true, but that also makes sign 5 true
G. Room 8 is out, because if it contains the princess, it cannot contain a tiger
... no more possible rooms left!

Now what? :P

Maybe the princess is a quantum particle? :mrgreen:
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Get the Princess!

Post by blueznl »

I didn't try 'the other' :-) brute force solution before mine, but here's mine, and it returns room 7.

Edit: I just tried the other one, and it also ends up with room 7.

Be carefull though how you read the original questions / rules, a condition that contains of two parts of which either part is not met, is in total not met.

Code: Select all

Enumeration
  #princess
  #tiger
  #empty
EndEnumeration
;
Dim rule(8)
Dim room(8)
;
For princess = 1 To 8
  ;
  ; fill up the rooms
  ;
  For tiger = 0 To 255
    For n = 1 To 8
      If princess = n
        room(n) = #princess
        rule(n) = #True
      ElseIf tiger & (1 << (n-1) )
        room(n) = #tiger
        rule(n) = #False
      Else
        room(n) = #empty
        rule(n) = #True
      EndIf
    Next n
    ;
    ; now check if the rules are valid
    ;
    found = #True
    ;
    ; 1. Room 4 is Not empty.
    ;
    If room(1) = #tiger
      If room(4) <> #empty
        found = #False
      EndIf
    Else
      If room(4) = #empty
        found = #False
      EndIf
    EndIf
    ;
    ; 2. Sign 5 is true And the princess is Not in this room
    ;
    If room(2) = #princess
      found = #False
    EndIf
    If room(2) = #tiger
      If room(5) <> #tiger And room(2) <> #princess
        found = #False
      EndIf
    EndIf
    ;
    ; 3. Room 2 And 7 are Not empty.
    ;
    If room(3) = #tiger
      If room(2) <> #empty And room(7) <> #empty
        found = #False
      EndIf
    Else
      If room(2) = #empty Or room(7) = #empty
        found = #False
      EndIf
    EndIf
    ;
    ; 4. Room 1 is Not empty.
    ;
    If room(4) = #tiger
      If room(1) <> #empty
        found = #False
      EndIf
    Else
      If room(1) = #empty
        found = #False
      EndIf
    EndIf
    ;
    ; 6. Sign 2 is false And room 8 is empty.
    ;
    If room(6) = #tiger
      If room(2) <> #True And room(8) = #empty
        found = #False
      EndIf
    Else
      If room(2) <> #tiger
        found = #False
      EndIf
      If room(8) <> #empty
        found = #False
      EndIf
    EndIf
    ;
    ; 5. Sign 6 is true.
    ;
    If room(5) = #tiger And room(6) = #tiger
    ElseIf room(5) <> #tiger And room(6) <> #tiger
    Else
      found = #False
    EndIf
    ;
    ; 7. The princess is in a room With an odd number.
    ;
    If room(7) = #tiger
      If Mod(princess,2) = 1
        found = #False
      EndIf
    Else
      If Mod(princess,2) = 1
      Else
        found = #False
      EndIf
    EndIf
    ;
    ; 8. This room contains a tiger And sign 3 is false.
    ;
    If room(8) <> #tiger
      found = #False
    EndIf
    ;
    ; report result
    ;
    ;     s.s = ""
    ;     For n = 1 To 8
    ;       If room(n) = #tiger
    ;         s = "1"+s
    ;       ElseIf room(n) = #princess
    ;         s = "x"+s
    ;       Else
    ;         s = "0"+s
    ;       EndIf
    ;     Next n
    ;     Debug s+" "+Str(tiger)
    ;
    If found
      Debug "princess in room "+Str(princess)
      For n = 1 To 8
        If room(n) = #tiger
          Debug " tiger in room "+Str(n)
        EndIf
      Next n
    EndIf
    ;
  Next tiger
  ;
Next princess
;
Last edited by blueznl on Fri Sep 10, 2010 5:17 pm, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Demivec
Addict
Addict
Posts: 4283
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Get the Princess!

Post by Demivec »

Here's my solution: princess in #7, no tigers.

Logic proceeds this way, if a room's sign contains fluctuating truthness (i patented that term :D ) then the room must be empty. This applies to the group of rooms {2, 5, 6}, {1, 4}, and {3, 8}. Note if a sign mentions a conjunctive condition ('and') all conditions must be true or the sign is false. This leaves only room seven for the princess and its sign says the princess is in an odd numbered room, and thus is true.

This solution is based on the assumption that there is a princess. I would point out though that there may be no princess and room 7 contains a tiger instead. :twisted:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Get the Princess!

Post by blueznl »

Well, who says there's a difference between the princess and the tiger? :-)

(Images in increasing level of... euh... 'duh' factor :-))

http://images2.fanpop.com/image/photos/ ... 16-348.jpg
http://www.t-nation.com/img/photos/2008 ... age005.jpg
http://stbenedict.files.wordpress.com/2 ... igress.jpg

I mean, if I really really have to choose between the princess and the tiger... euh... ;-)
Last edited by blueznl on Fri Sep 10, 2010 5:30 pm, edited 2 times in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Get the Princess!

Post by freak »

I revised my code:
If you equate the statements "Sign X is true/false" with "Room X contains/doesn't contain the proncess",
then there is no circularity in the sign checks and it becomes much simpler.

The result: No princess :)

Code: Select all

; ... more wrong code ...
That is the solution then! :D
blueznl wrote:Well, who says there's a difference between the princess and the tiger? :-)
quidquid Latine dictum sit altum videtur
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Get the Princess!

Post by blueznl »

Frankly, I tried my solution and it seems to qualify, could anyone find a flaw in the logic?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
freak
PureBasic Team
PureBasic Team
Posts: 5962
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Get the Princess!

Post by freak »

Damn, i see my error: I overread the part where empty rooms mean either true or false. Well... :)

Back to doing something productive!
quidquid Latine dictum sit altum videtur
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: Get the Princess!

Post by Perkin »

I've sussed it.
The princess is in one of the rooms, but she's dead, having been eaten by a tiger.
%101010 = $2A = 42
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: Get the Princess!

Post by Trond »

Arctic Fox wrote:@Trond
The sign of room 8 says that this room contains a tiger. But if it contains a tiger the sign must be false. And thus it cannot contain a tiger which the sign claims, right?
No, think again.
A. If the princess is in room 7, then all other signs must be false.
Nope, the signs on empty rooms can be either true or false.
Damn, i see my error: I overread the part where empty rooms mean either true or false. Well...
Yup!
Frankly, I tried my solution and it seems to qualify, could anyone find a flaw in the logic?
Your code prints several solution, of which many are wrong, so there must be a flaw in your logic.
In solution 2, 4, 6 and 8, you have a tiger in room 3. I assure you, there can't ever be a tiger in room 3. This is because there has to be a tiger in room 8. And if you examine sign 8 closely, you understand that if there is a tiger in room 8, sign 3 must be true. And if sign 3 is true, there can't be a tiger in room 3 (as the sign would be false then).
Logic proceeds this way, if a room's sign contains fluctuating truthness (i patented that term ) then the room must be empty. This applies to the group of rooms {2, 5, 6}, {1, 4}, and {3, 8}.
You can logically prove that there must be a tiger in room 3 and 8. Thus your assumption that these rooms are empty can not be right.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6175
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: Get the Princess!

Post by blueznl »

You're right, my coding for rule 8 is wrong. I will change it and try again. It should be something like:

Code: Select all

if room(8) <> #tiger or room(3) = #tiger
  found = #false
endif
... but I will check later.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PMV
Enthusiast
Enthusiast
Posts: 727
Joined: Sat Feb 24, 2007 3:15 pm
Location: Germany

Re: Get the Princess!

Post by PMV »

It needs longer to write the text in English, as to finish this quest. :lol:

Solution:

If princess in room 1 or 4, then one is true and not empty, so the other room must contain the tiger and the sign must be false, but then the sign is true. No princess.
If princess in room 2, the sign must be true, but then it can't be true, because then princess is not allowed to be in this room. No princess.
if princess in room 3, sign 7 must be false because there must be a tiger. 3 is an odd number, so sign 7 would be true. No princess.
If princess in room 5, sign 6 must be true. Sign 6 needs sign 2 to be false. Sign 2 needs sign 5 to be false, but there should be the princess, impossible. No princess.
If princess in room 6, the problem will be repeated. No princess.
If princess in room 7, the 7 must be a odd number, true. Princess can be here.
If princess in room 8, the sign says there is a tiger, so it can't be. No princess

There is only one room without conflict. :D

I got the princess ... who want to search for the tiger, i doesn't need him after all :mrgreen:

MFG PMV

edit: confilct of room/ sign 3 corrected
Last edited by PMV on Sun Sep 12, 2010 10:07 pm, edited 1 time in total.
Post Reply