1
$\begingroup$

A family of your most hated Nggyupnglydown tribe has turned you into a vampire and trapped you in a chamber with a screen and some buttons on it, and you have to enter the code 4, 8, 15, 16, 23, 42 (there can be numbers between) to open the door and escape. Everything in the chamber is made from unbreakable bedrock.

But most of the buttons were yanked out by the Nggyupnglydown ruler Sussus Amogus, and there are only five buttons left:

  1. Subtract 6 from the number
  2. Switch the sign of the number, then integer divide by 4
  3. Convert the number into its base-16 representation, replacing letters with 0 (e.g. 20 -> 14)
  4. Replace the on screen number $x$ with $\frac{2x+4}{x-2}$ (truncated to integer)
  5. Put 9 at the end of the number

If the same number occurs four times, or the number is greater than $2^{32}$, or a division by zero occurs, the room will fill up with garlic and you will die.

The screen currently shows $-1$, and time is running out.

How can you successfully escape the chamber?

Bonus: Can you escape the chamber if buttons 1 and 5 were yanked out as well? If so, how?

$\endgroup$
3
  • 1
    $\begingroup$ What does "integer divide by 4" mean? $\endgroup$
    – ACB
    Commented Oct 22, 2022 at 14:45
  • $\begingroup$ Divide, rounding down $\endgroup$ Commented Oct 22, 2022 at 15:13
  • $\begingroup$ Divide, rounding towards 0 $\endgroup$
    – David G.
    Commented Oct 22, 2022 at 15:15

2 Answers 2

3
$\begingroup$

One solution is:

Shows Press New Target
-1 #5 -19
-19 #2 4 ***
4 #1 -2
-2 #5 -29
-29 #1 -35
-35 #2 8 ***
8 #4 3
3 #5 39
39 #3 27
27 #1 21
21 #1 15 ***
15 #3 0
0 #4 -2
-2 #1 -8
-8 #5 -89
-89 #2 22
22 #1 16 ***
16 #4 2
2 #5 29
29 #1 23 ***
23 #4 2
2 #1 -4
-4 #1 -10
-10 #1 -16
-16 #5 -169
-169 #2 42 ***

In this solution, the numbers -2 and 2 are the only ones used more than once, and they, only twice.

There appear to be at least two routes of length 6 from 23 to 42, as sometimes my program doesn't report 2 used twice. The alternate route

goes from 23 to -4 via button 3 (to 17) and 2.

As for the bonus question:

No. Only buttons 1 and 5 can increase the magnitude of the number. (OK, button 4 can get it to 10 in one case.)

Further, without buttons 1 and 5, the only values you can get are 0, -1, and -2.

$\endgroup$
4
  • $\begingroup$ Much cleaner than mine! $\endgroup$ Commented Oct 22, 2022 at 15:33
  • $\begingroup$ Well, I wrote a program that would do depth first search, and realized that was bad. So I added a depth limit, and iterated until I got solutions at each step. $\endgroup$
    – David G.
    Commented Oct 22, 2022 at 15:35
  • $\begingroup$ Isn't that effectively just breadth first? $\endgroup$
    – Ed Murphy
    Commented Oct 23, 2022 at 5:13
  • $\begingroup$ @EdMurphy Inefficiently, but effectively, yes. Especially inefficient since it re-tests all the lower levels. On the other hand, it doesn't require any extra storage beyond the stack. $\endgroup$
    – David G.
    Commented Oct 23, 2022 at 13:45
1
$\begingroup$

A solution can be this:

-1 (6k+5) ->(2) 0 (6k) ->(1) subtract 6 until -18 (6k) ->(2) 4 (6k+4)

4 ->(1) subtract 6 until -32 (6k+4) ->(2) 8 (6k+2)

8 ->(5) 89 (6k+5) ->(1) subtract 6 until -61 (6k+5) ->(2) 15 (6k+3)

15 ->(5) 159 (6k+3) ->(2) -39 (6k+3) ->(2) 9 (6k+3) ->(2) -2 (6k+4) ->(5) -29 (6k+1) ->(1) subtract 6 until -65 (6k+1) ->(2) 16 (6k+4)

16 ->(2) -4 (6k+2) -> (1) subtract until -94 (6k+2) -> (2) 23 (6k+5)

23 ->(1) subtract until -127 (6k+4) ->(2) 42 (6k)

Bonus:

Nope. 2 and 3 lower the absolute value of the number or don't touch it. 4 is basically $2+8/(x-2)$, which can range from -6 to 10. You can never increase the absolute value to 16, 23 or 42.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.