Skip to content

Commit a860256

Browse files
committed
Solved day 23 part 1
1 parent 3503bce commit a860256

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44

55
// project meta data
66
group 'de.havox_design.aoc2015'
7-
version '0.22.1'
7+
version '0.22.2'
88

99
// Switch to gradle "all" distribution.
1010
wrapper {

day23/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Day 23: Opening the Turing Lock
2+
Little Jane Marie just got her very first computer for Christmas from some unknown benefactor. It comes with
3+
instructions and an example program, but the computer itself seems to be malfunctioning. She's curious what the program
4+
does, and would like you to help her run it.
5+
6+
The manual explains that the computer supports two [registers](https://en.wikipedia.org/wiki/Processor_register) and
7+
six [instructions](https://en.wikipedia.org/wiki/Instruction_set) (truly, it goes on to remind the reader, a
8+
state-of-the-art technology). The registers are named `a` and `b`, can hold any
9+
[non-negative integer](https://en.wikipedia.org/wiki/Natural_number), and begin with a value of `0`. The instructions
10+
are as follows:
11+
* `hlf r` sets register `r` to half its current value, then continues with the next instruction.
12+
* `tpl r` sets register `r` to triple its current value, then continues with the next instruction.
13+
* `inc r` **increments** register `r`, adding `1` to it, then continues with the next instruction.
14+
* `jmp offset` is a **jump**; it continues with the instruction `offset` away **relative to itself**.
15+
* `jie r, offset` is like `jmp`, but only jumps if register `r` is **even** ("jump if even").
16+
* `jio r, offset` is like `jmp`, but only jumps if register `r` is `1` ("jump if **one**", not odd).
17+
18+
All three jump instructions work with an **offset** relative to that instruction. The offset is always written with a
19+
prefix `+` or `-` to indicate the direction of the jump (forward or backward, respectively). For example, `jmp +1`
20+
would simply continue with the next instruction, while `jmp +0` would continuously jump back to itself forever.
21+
22+
The program exits when it tries to run an instruction beyond the ones defined.
23+
24+
For example, this program sets `a` to `2`, because the `jio` instruction causes it to skip the `tpl` instruction:
25+
```
26+
inc a
27+
jio a, +2
28+
tpl a
29+
inc a
30+
```
31+
What is **the value in register `b`** when the program in your puzzle input is finished executing?

day23/src/main/resources/day23.txt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
jio a, +19
2+
inc a
3+
tpl a
4+
inc a
5+
tpl a
6+
inc a
7+
tpl a
8+
tpl a
9+
inc a
10+
inc a
11+
tpl a
12+
tpl a
13+
inc a
14+
inc a
15+
tpl a
16+
inc a
17+
inc a
18+
tpl a
19+
jmp +23
20+
tpl a
21+
tpl a
22+
inc a
23+
inc a
24+
tpl a
25+
inc a
26+
inc a
27+
tpl a
28+
inc a
29+
tpl a
30+
inc a
31+
tpl a
32+
inc a
33+
tpl a
34+
inc a
35+
inc a
36+
tpl a
37+
inc a
38+
inc a
39+
tpl a
40+
tpl a
41+
inc a
42+
jio a, +8
43+
inc b
44+
jie a, +4
45+
tpl a
46+
inc a
47+
jmp +2
48+
hlf a
49+
jmp -7

0 commit comments

Comments
 (0)