| Bytes | Lang | Time | Link |
|---|---|---|---|
| 077 | C64 Basic | 250729T151614Z | OSI8 |
C64 Basic, 77 bytes
0fOa=0to1:fOf=0to1:b=1-a:x=a<>f:t=1-f:y=(faNb=0)<>(baNt=0):ifx=ytHnE:nE
1?a+1
Description
Definitions
box 1 contains gold: a = 0
box 1 contains frog: a = 1
box 2 contains gold: b = 0
box 2 contains frog: b = 1
box with false inscription contains gold: f = 0
box with false inscription contains frog: f = 1
box with true inscription contains gold: t = 0
box with true inscription contains frog: t = 1
Rules
"One box contains an angry frog, the other box gold":
b = 1 - a
t = 1 - f"Either this box contains an angry frog, or the box with a false inscription contains an angry frog, but not both":
x = a XOR f
in C64 BASIC:x = a<>f
"Either this box contains gold and the box with a false inscription contains an angry frog, or this box contains an angry frog and the box with a true inscription contains gold":
y = ((b=0) AND f) XOR (b AND (t=0))
in C64 BASIC:y = (f and b=0)<>(b and t=0)
"one, and only one, of the inscriptions is true":
x XOR y = 1
in C64 BASIC:x<>y = -1
Algorithm
- iterate through all cases until x<>y = -1
- output box number with gold:
if box 1 contains gold (a = 0) print 1
if box 1 contains frog (a = 1) print 2
so the output is always a + 1
Result
The output is 2, so box 2 contains gold.
Additum
The above program stops at the first result found. But if you iterate to the end, it finds two cases, both with gold in box 2 but different statements about the inscription.
- case 1: gold in box 2, inscription 1 true, inscription 2 false
- case 2: gold in box 2, inscription 1 false, inscription 2 true
