diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-12-09 09:46:13 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-12-09 09:46:13 +0800 |
commit | 5b4518cdd74d457b17e81b6a23501793a280f30f (patch) | |
tree | 9bcce910b283e3857a16ac83a277a210f534f405 /src | |
parent | ec8fa76a38c46cf6e9b3c98bb28bbe15ed54140f (diff) | |
download | advent-of-code-5b4518cdd74d457b17e81b6a23501793a280f30f.tar.gz advent-of-code-5b4518cdd74d457b17e81b6a23501793a280f30f.zip |
2015 day23 setup
Diffstat (limited to 'src')
-rw-r--r-- | src/2015/day23/README.md | 23 | ||||
-rw-r--r-- | src/2015/day23/aoc.cpp | 11 | ||||
-rw-r--r-- | src/2015/day23/aoc.h | 7 | ||||
-rw-r--r-- | src/2015/day23/input | 48 | ||||
-rw-r--r-- | src/2015/day23/input0 | 4 | ||||
-rw-r--r-- | src/CMakeLists.txt | 1 |
6 files changed, 94 insertions, 0 deletions
diff --git a/src/2015/day23/README.md b/src/2015/day23/README.md new file mode 100644 index 0000000..a39bf8c --- /dev/null +++ b/src/2015/day23/README.md @@ -0,0 +1,23 @@ +--- Day 23: Opening the Turing Lock --- +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. + +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. +tpl r sets register r to triple its current value, then continues with the next instruction. +inc r increments register r, adding 1 to it, then continues with the next instruction. +jmp offset is a jump; it continues with the instruction offset away relative to itself. +jie r, offset is like jmp, but only jumps if register r is even ("jump if even"). +jio r, offset is like jmp, but only jumps if register r is 1 ("jump if one", not odd). +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: + +inc a +jio a, +2 +tpl a +inc a +What is the value in register b when the program in your puzzle input is finished executing? + diff --git a/src/2015/day23/aoc.cpp b/src/2015/day23/aoc.cpp new file mode 100644 index 0000000..9cb0cef --- /dev/null +++ b/src/2015/day23/aoc.cpp @@ -0,0 +1,11 @@ +#include "aoc.h" +#include <string.h> +#include <vector> + +namespace aoc2015 { + +std::pair<int, int> day23(line_view file) { + return {0, 0}; +} + +} diff --git a/src/2015/day23/aoc.h b/src/2015/day23/aoc.h new file mode 100644 index 0000000..57257e9 --- /dev/null +++ b/src/2015/day23/aoc.h @@ -0,0 +1,7 @@ +#pragma once +#include "common.h" + +namespace aoc2015 { + +std::pair<int, int> day23(line_view lv); +} // namespace aoc2015 diff --git a/src/2015/day23/input b/src/2015/day23/input new file mode 100644 index 0000000..cad5dc2 --- /dev/null +++ b/src/2015/day23/input @@ -0,0 +1,48 @@ +jio a, +22 +inc a +tpl a +tpl a +tpl a +inc a +tpl a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +jmp +19 +tpl a +tpl a +tpl a +tpl a +inc a +inc a +tpl a +inc a +tpl a +inc a +inc a +tpl a +inc a +inc a +tpl a +inc a +tpl a +tpl a +jio a, +8 +inc b +jie a, +4 +tpl a +inc a +jmp +2 +hlf a +jmp -7 diff --git a/src/2015/day23/input0 b/src/2015/day23/input0 new file mode 100644 index 0000000..c55ca77 --- /dev/null +++ b/src/2015/day23/input0 @@ -0,0 +1,4 @@ +inc a +jio a, +2 +tpl a +inc a diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1515b44..4a30d14 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,6 +21,7 @@ set(SOLUTION_FILES "2015/day20/aoc.cpp" "2015/day21/aoc.cpp" "2015/day22/aoc.cpp" + "2015/day23/aoc.cpp" "2016/day1/aoc.cpp" "2016/day2/aoc.cpp" |