2018-03-15 16:24:23 +00:00
|
|
|
|
Advent of Code
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
--- Day 23: Opening the Turing Lock ---
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
Little Jane Marie just got her very first computer for Christmas from some
|
|
|
|
|
unknown benefactor. It comes with instructions and an example program, but
|
|
|
|
|
the computer itself seems to be malfunctioning. She's curious what the
|
|
|
|
|
program does, and would like you to help her run it.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
The manual explains that the computer supports two registers and six
|
|
|
|
|
instructions (truly, it goes on to remind the reader, a state-of-the-art
|
|
|
|
|
technology). The registers are named a and b, can hold any non-negative
|
|
|
|
|
integer, and begin with a value of 0. The instructions are as follows:
|
|
|
|
|
|
|
|
|
|
• hlf r sets register r to half its current value, then continues with the
|
|
|
|
|
next instruction.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• tpl r sets register r to triple its current value, then continues with
|
|
|
|
|
the next instruction.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• inc r increments register r, adding 1 to it, then continues with the
|
|
|
|
|
next instruction.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• jmp offset is a jump; it continues with the instruction offset away
|
|
|
|
|
relative to itself.
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• jie r, offset is like jmp, but only jumps if register r is even ("jump
|
|
|
|
|
if even").
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
• jio r, offset is like jmp, but only jumps if register r is 1 ("jump if
|
|
|
|
|
one", not odd).
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
All three jump instructions work with an offset relative to that
|
|
|
|
|
instruction. The offset is always written with a prefix + or - to indicate
|
|
|
|
|
the direction of the jump (forward or backward, respectively). For example,
|
|
|
|
|
jmp +1 would simply continue with the next instruction, while jmp +0 would
|
|
|
|
|
continuously jump back to itself forever.
|
|
|
|
|
|
|
|
|
|
The program exits when it tries to run an instruction beyond the ones
|
|
|
|
|
defined.
|
|
|
|
|
|
|
|
|
|
For example, this program sets a to 2, because the jio instruction causes it
|
|
|
|
|
to skip the tpl instruction:
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
inc a
|
|
|
|
|
jio a, +2
|
|
|
|
|
tpl a
|
|
|
|
|
inc a
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
What is the value in register b when the program in your puzzle input is
|
|
|
|
|
finished executing?
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Your puzzle answer was 255.
|
|
|
|
|
|
|
|
|
|
The first half of this puzzle is complete! It provides one gold star: *
|
|
|
|
|
|
|
|
|
|
--- Part Two ---
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
The unknown benefactor is very thankful for releasi-- er, helping little
|
|
|
|
|
Jane Marie with her computer. Definitely not to distract you, what is the
|
|
|
|
|
value in register b after the program is finished executing if register a
|
|
|
|
|
starts as 1 instead?
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
Although it hasn't changed, you can still get your puzzle input.
|
|
|
|
|
|
2018-03-15 16:24:23 +00:00
|
|
|
|
Answer: 334
|
2016-12-16 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
References
|
|
|
|
|
|
|
|
|
|
Visible links
|
|
|
|
|
. http://adventofcode.com/
|
|
|
|
|
. http://adventofcode.com/about
|
|
|
|
|
. http://adventofcode.com/stats
|
|
|
|
|
. http://adventofcode.com/leaderboard
|
|
|
|
|
. http://adventofcode.com/settings
|
|
|
|
|
. http://adventofcode.com/auth/logout
|
|
|
|
|
. https://en.wikipedia.org/wiki/Processor_register
|
|
|
|
|
. https://en.wikipedia.org/wiki/Instruction_set
|
|
|
|
|
. https://en.wikipedia.org/wiki/Natural_number
|
|
|
|
|
. http://adventofcode.com/day/23/input
|