diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 989d37c12..000000000
--- a/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-**/input.in filter=git-crypt diff=git-crypt
diff --git a/.github/workflows/update-docs.yaml b/.github/workflows/update-docs.yaml
deleted file mode 100644
index 62acdb9ae..000000000
--- a/.github/workflows/update-docs.yaml
+++ /dev/null
@@ -1,53 +0,0 @@
-name: Update Docs
-
-on:
- push:
- branches:
- - master
-
-jobs:
- update-docs:
- runs-on: ubuntu-latest
-
- permissions:
- # Give the default GITHUB_TOKEN write permission to commit and push the
- # added or changed files to the repository.
- contents: write
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v3
-
- - name: Configure Git
- run: |
- # Configure Git
- git config --global user.name "github-actions[bot]"
- git config --global user.email "github-actions[bot]@users.noreply.github.com"
-
- - name: Set up Node.js
- uses: actions/setup-node@v3
- with:
- node-version: '16' # Update based on your project's requirements
-
- - name: Build
- run: |
- cd docs;
- npm install
- cd ..
- ls -la
- node docs/build.js
-
-
- - name: Checkout docs repository
- uses: actions/checkout@v3
- with:
- path: distr
- ref: docs
-
- - name: Deploy docs
- run: |
- rsync -av --exclude='.git/' --del build/ distr/
- cd distr
- git add .
- git commit -m "Update docs on $(date)"
- git push --force origin docs
diff --git a/.gitignore b/.gitignore
index f96db2252..1746e3269 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,2 @@
bin
obj
-aoc-crypt.key
-docs/node_modules
-build
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 86b12f55e..75419e564 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -11,7 +11,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
- "program": "${workspaceFolder}/bin/Debug/net9.0/adventofcode.dll",
+ "program": "${workspaceFolder}/bin/Debug/net8.0/adventofcode.dll",
"args": ["${relativeFileDirname}"],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
diff --git a/2015/Day01/README.md b/2015/Day01/README.md
index e6654b029..bfd951a30 100644
--- a/2015/Day01/README.md
+++ b/2015/Day01/README.md
@@ -1,6 +1,38 @@
+original source: [https://adventofcode.com/2015/day/1](https://adventofcode.com/2015/day/1)
## --- Day 1: Not Quite Lisp ---
Santa was hoping for a white Christmas, but his weather machine's "snow" function is powered by stars, and he's fresh out! To save Christmas, he needs you to collect fifty stars by December 25th.
Collect stars by helping Santa solve puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
-_Visit the website for the full story and [full puzzle](https://adventofcode.com/2015/day/1) description._
+Here's an easy puzzle to warm you up.
+
+Santa is trying to deliver presents in a large apartment building, but he can't find the right floor - the directions he got are a little confusing. He starts on the ground floor (floor 0
) and then follows the instructions one character at a time.
+
+An opening parenthesis, (
, means he should go up one floor, and a closing parenthesis, )
, means he should go down one floor.
+
+The apartment building is very tall, and the basement is very deep; he will never find the top or bottom floors.
+
+For example:
+
+
+ - (())
and ()()
both result in floor 0
.
+ - (((
and (()(()(
both result in floor 3
.
+ - ))(((((
also results in floor 3
.
+ - ())
and ))(
both result in floor -1
(the first basement level).
+ - )))
and )())())
both result in floor -3
.
+
+To what floor do the instructions take Santa?
+
+
+## --- Part Two ---
+Now, given the same instructions, find the position of the first character that causes him to enter the basement (floor -1
). The first character in the instructions has position 1
, the second character has position 2
, and so on.
+
+For example:
+
+
+ - )
causes him to enter the basement at character position 1
.
+ - ()())
causes him to enter the basement at character position 5
.
+
+What is the position of the character that causes Santa to first enter the basement?
+
+
diff --git a/2015/Day01/illustration.jpeg b/2015/Day01/illustration.jpeg
deleted file mode 100644
index 999d41141..000000000
Binary files a/2015/Day01/illustration.jpeg and /dev/null differ
diff --git a/2015/Day01/input.in b/2015/Day01/input.in
index efdae0d4d..1855a96b9 100644
Binary files a/2015/Day01/input.in and b/2015/Day01/input.in differ
diff --git a/2015/Day02/README.md b/2015/Day02/README.md
index 91b468e7c..945f77abf 100644
--- a/2015/Day02/README.md
+++ b/2015/Day02/README.md
@@ -1,6 +1,29 @@
+original source: [https://adventofcode.com/2015/day/2](https://adventofcode.com/2015/day/2)
## --- Day 2: I Was Told There Would Be No Math ---
The elves are running low on wrapping paper, and so they need to submit an order for more. They have a list of the dimensions (length `l`, width `w`, and height `h`) of each present, and only want to order exactly as much as they need.
Fortunately, every present is a box (a perfect [right rectangular prism](https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid)), which makes calculating the required wrapping paper for each gift a little easier: find the surface area of the box, which is `2*l*w + 2*w*h + 2*h*l`. The elves also need a little extra paper for each present: the area of the smallest side.
-Read the [full puzzle](https://adventofcode.com/2015/day/2).
\ No newline at end of file
+For example:
+
+
+ - A present with dimensions `2x3x4` requires `2*6 + 2*12 + 2*8 = 52` square feet of wrapping paper plus `6` square feet of slack, for a total of `58` square feet.
+ - A present with dimensions `1x1x10` requires `2*1 + 2*10 + 2*10 = 42` square feet of wrapping paper plus `1` square foot of slack, for a total of `43` square feet.
+
+All numbers in the elves' list are in feet. How many total *square feet of wrapping paper* should they order?
+
+
+## --- Part Two ---
+The elves are also running low on ribbon. Ribbon is all the same width, so they only have to worry about the length they need to order, which they would again like to be exact.
+
+The ribbon required to wrap a present is the shortest distance around its sides, or the smallest perimeter of any one face. Each present also requires a bow made out of ribbon as well; the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of the present. Don't ask how they tie the bow, though; they'll never tell.
+
+For example:
+
+
+ - A present with dimensions `2x3x4` requires `2+2+3+3 = 10` feet of ribbon to wrap the present plus `2*3*4 = 24` feet of ribbon for the bow, for a total of `34` feet.
+ - A present with dimensions `1x1x10` requires `1+1+1+1 = 4` feet of ribbon to wrap the present plus `1*1*10 = 10` feet of ribbon for the bow, for a total of `14` feet.
+
+How many total *feet of ribbon* should they order?
+
+
diff --git a/2015/Day02/illustration.jpeg b/2015/Day02/illustration.jpeg
deleted file mode 100644
index 23432437a..000000000
Binary files a/2015/Day02/illustration.jpeg and /dev/null differ
diff --git a/2015/Day02/input.in b/2015/Day02/input.in
index ee590c717..2f04474ab 100644
Binary files a/2015/Day02/input.in and b/2015/Day02/input.in differ
diff --git a/2015/Day03/README.md b/2015/Day03/README.md
index 06678a506..39d702484 100644
--- a/2015/Day03/README.md
+++ b/2015/Day03/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2015/day/3](https://adventofcode.com/2015/day/3)
## --- Day 3: Perfectly Spherical Houses in a Vacuum ---
Santa is delivering presents to an infinite two-dimensional grid of houses.
He begins by delivering a present to the house at his starting location, and then an elf at the North Pole calls him via radio and tells him where to move next. Moves are always exactly one house to the north (`^`), south (`v`), east (`>`), or west (`<`). After each move, he delivers another present to the house at his new location.
-Read the [full puzzle](https://adventofcode.com/2015/day/3).
\ No newline at end of file
+However, the elf back at the north pole has had a little too much eggnog, and so his directions are a little off, and Santa ends up visiting some houses more than once. How many houses receive *at least one present*?
+
+For example:
+
+
+ - `>` delivers presents to `2` houses: one at the starting location, and one to the east.
+ - `^>v<` delivers presents to `4` houses in a square, including twice to the house at his starting/ending location.
+ - `^v^v^v^v^v` delivers a bunch of presents to some very lucky children at only `2` houses.
+
+
+## --- Part Two ---
+The next year, to speed up the process, Santa creates a robot version of himself, *Robo-Santa*, to deliver presents with him.
+
+Santa and Robo-Santa start at the same location (delivering two presents to the same starting house), then take turns moving based on instructions from the elf, who is eggnoggedly reading from the same script as the previous year.
+
+This year, how many houses receive *at least one present*?
+
+For example:
+
+
+ - `^v` delivers presents to `3` houses, because Santa goes north, and then Robo-Santa goes south.
+ - `^>v<` now delivers presents to `3` houses, and Santa and Robo-Santa end up back where they started.
+ - `^v^v^v^v^v` now delivers presents to `11` houses, with Santa going one direction and Robo-Santa going the other.
+
+
diff --git a/2015/Day03/illustration.jpeg b/2015/Day03/illustration.jpeg
deleted file mode 100644
index 60cacbd93..000000000
Binary files a/2015/Day03/illustration.jpeg and /dev/null differ
diff --git a/2015/Day03/input.in b/2015/Day03/input.in
index 065d2f825..a5954e780 100644
Binary files a/2015/Day03/input.in and b/2015/Day03/input.in differ
diff --git a/2015/Day04/README.md b/2015/Day04/README.md
index a52193422..839c51a61 100644
--- a/2015/Day04/README.md
+++ b/2015/Day04/README.md
@@ -1,6 +1,17 @@
+original source: [https://adventofcode.com/2015/day/4](https://adventofcode.com/2015/day/4)
## --- Day 4: The Ideal Stocking Stuffer ---
Santa needs help [mining](https://en.wikipedia.org/wiki/Bitcoin#Mining) some AdventCoins (very similar to [bitcoins](https://en.wikipedia.org/wiki/Bitcoin)) to use as gifts for all the economically forward-thinking little girls and boys.
To do this, he needs to find [MD5](https://en.wikipedia.org/wiki/MD5) hashes which, in [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal), start with at least *five zeroes*. The input to the MD5 hash is some secret key (your puzzle input, given below) followed by a number in decimal. To mine AdventCoins, you must find Santa the lowest positive number (no leading zeroes: `1`, `2`, `3`, ...) that produces such a hash.
-Read the [full puzzle](https://adventofcode.com/2015/day/4).
\ No newline at end of file
+For example:
+
+
+ - If your secret key is `abcdef`, the answer is `609043`, because the MD5 hash of `abcdef609043` starts with five zeroes (`000001dbbfa...`), and it is the lowest such number to do so.
+ - If your secret key is `pqrstuv`, the lowest number it combines with to make an MD5 hash starting with five zeroes is `1048970`; that is, the MD5 hash of `pqrstuv1048970` looks like `000006136ef...`.
+
+
+## --- Part Two ---
+Now find one that starts with *six zeroes*.
+
+
diff --git a/2015/Day04/illustration.jpeg b/2015/Day04/illustration.jpeg
deleted file mode 100644
index 243d89a1b..000000000
Binary files a/2015/Day04/illustration.jpeg and /dev/null differ
diff --git a/2015/Day04/input.in b/2015/Day04/input.in
index 7f2ce7a96..d75e0dcd7 100644
Binary files a/2015/Day04/input.in and b/2015/Day04/input.in differ
diff --git a/2015/Day05/README.md b/2015/Day05/README.md
index 0c3382404..15274b7f4 100644
--- a/2015/Day05/README.md
+++ b/2015/Day05/README.md
@@ -1,6 +1,43 @@
+original source: [https://adventofcode.com/2015/day/5](https://adventofcode.com/2015/day/5)
## --- Day 5: Doesn't He Have Intern-Elves For This? ---
Santa needs help figuring out which strings in his text file are naughty or nice.
A *nice string* is one with all of the following properties:
-Read the [full puzzle](https://adventofcode.com/2015/day/5).
\ No newline at end of file
+
+ - It contains at least three vowels (`aeiou` only), like `aei`, `xazegov`, or `aeiouaeiouaeiou`.
+ - It contains at least one letter that appears twice in a row, like `xx`, `abcdde` (`dd`), or `aabbccdd` (`aa`, `bb`, `cc`, or `dd`).
+ - It does *not* contain the strings `ab`, `cd`, `pq`, or `xy`, even if they are part of one of the other requirements.
+
+For example:
+
+
+ - `ugknbfddgicrmopn` is nice because it has at least three vowels (`u...i...o...`), a double letter (`...dd...`), and none of the disallowed substrings.
+ - `aaa` is nice because it has at least three vowels and a double letter, even though the letters used by different rules overlap.
+ - `jchzalrnumimnmhp` is naughty because it has no double letter.
+ - `haegwjzuvuyypxyu` is naughty because it contains the string `xy`.
+ - `dvszwmarrgswjxmb` is naughty because it contains only one vowel.
+
+How many strings are nice?
+
+
+## --- Part Two ---
+Realizing the error of his ways, Santa has switched to a better model of determining whether a string is naughty or nice. None of the old rules apply, as they are all clearly ridiculous.
+
+Now, a nice string is one with all of the following properties:
+
+
+ - It contains a pair of any two letters that appears at least twice in the string without overlapping, like `xyxy` (`xy`) or `aabcdefgaa` (`aa`), but not like `aaa` (`aa`, but it overlaps).
+ - It contains at least one letter which repeats with exactly one letter between them, like `xyx`, `abcdefeghi` (`efe`), or even `aaa`.
+
+For example:
+
+
+ - `qjhvhtzxzqqjkmpb` is nice because is has a pair that appears twice (`qj`) and a letter that repeats with exactly one letter between them (`zxz`).
+ - `xxyxx` is nice because it has a pair that appears twice and a letter that repeats with one between, even though the letters used by each rule overlap.
+ - `uurcxstgmygtbstg` is naughty because it has a pair (`tg`) but no repeat with a single letter between them.
+ - `ieodomkazucvgmuy` is naughty because it has a repeating letter with one between (`odo`), but no pair that appears twice.
+
+How many strings are nice under these new rules?
+
+
diff --git a/2015/Day05/illustration.jpeg b/2015/Day05/illustration.jpeg
deleted file mode 100644
index 8ba151e3c..000000000
Binary files a/2015/Day05/illustration.jpeg and /dev/null differ
diff --git a/2015/Day05/input.in b/2015/Day05/input.in
index 78609b050..a9b6e779f 100644
Binary files a/2015/Day05/input.in and b/2015/Day05/input.in differ
diff --git a/2015/Day06/README.md b/2015/Day06/README.md
index bc54a864c..9ad79d8bf 100644
--- a/2015/Day06/README.md
+++ b/2015/Day06/README.md
@@ -1,6 +1,40 @@
+original source: [https://adventofcode.com/2015/day/6](https://adventofcode.com/2015/day/6)
## --- Day 6: Probably a Fire Hazard ---
Because your neighbors keep defeating you in the holiday house decorating contest year after year, you've decided to deploy one million lights in a 1000x1000 grid.
Furthermore, because you've been especially nice this year, Santa has mailed you instructions on how to display the ideal lighting configuration.
-Read the [full puzzle](https://adventofcode.com/2015/day/6).
\ No newline at end of file
+
+Lights in your grid are numbered from 0 to 999 in each direction; the lights at each corner are at `0,0`, `0,999`, `999,999`, and `999,0`. The instructions include whether to `turn on`, `turn off`, or `toggle` various inclusive ranges given as coordinate pairs. Each coordinate pair represents opposite corners of a rectangle, inclusive; a coordinate pair like `0,0 through 2,2` therefore refers to 9 lights in a 3x3 square. The lights all start turned off.
+To defeat your neighbors this year, all you have to do is set up your lights by doing the instructions Santa sent you in order.
+
+For example:
+
+
+ - `turn on 0,0 through 999,999` would turn on (or leave on) every light.
+ - `toggle 0,0 through 999,0` would toggle the first line of 1000 lights, turning off the ones that were on, and turning on the ones that were off.
+ - `turn off 499,499 through 500,500` would turn off (or leave off) the middle four lights.
+
+After following the instructions, *how many lights are lit*?
+
+
+## --- Part Two ---
+You just finish implementing your winning light pattern when you realize you mistranslated Santa's message from Ancient Nordic Elvish.
+
+The light grid you bought actually has individual brightness controls; each light can have a brightness of zero or more. The lights all start at zero.
+
+The phrase `turn on` actually means that you should increase the brightness of those lights by `1`.
+
+The phrase `turn off` actually means that you should decrease the brightness of those lights by `1`, to a minimum of zero.
+
+The phrase `toggle` actually means that you should increase the brightness of those lights by `2`.
+
+What is the *total brightness* of all lights combined after following Santa's instructions?
+
+For example:
+
+
+ - `turn on 0,0 through 0,0` would increase the total brightness by `1`.
+ - `toggle 0,0 through 999,999` would increase the total brightness by `2000000`.
+
+
diff --git a/2015/Day06/illustration.jpeg b/2015/Day06/illustration.jpeg
deleted file mode 100644
index 3b62f677b..000000000
Binary files a/2015/Day06/illustration.jpeg and /dev/null differ
diff --git a/2015/Day06/input.in b/2015/Day06/input.in
index be73cadf4..df10465d6 100644
Binary files a/2015/Day06/input.in and b/2015/Day06/input.in differ
diff --git a/2015/Day07/README.md b/2015/Day07/README.md
index 7a4b1c9a3..a4455815d 100644
--- a/2015/Day07/README.md
+++ b/2015/Day07/README.md
@@ -1,6 +1,51 @@
+original source: [https://adventofcode.com/2015/day/7](https://adventofcode.com/2015/day/7)
## --- Day 7: Some Assembly Required ---
This year, Santa brought little Bobby Tables a set of wires and [bitwise logic gates](https://en.wikipedia.org/wiki/Bitwise_operation)! Unfortunately, little Bobby is a little under the recommended age range, and he needs help assembling the circuit.
Each wire has an identifier (some lowercase letters) and can carry a [16-bit](https://en.wikipedia.org/wiki/16-bit) signal (a number from `0` to `65535`). A signal is provided to each wire by a gate, another wire, or some specific value. Each wire can only get a signal from one source, but can provide its signal to multiple destinations. A gate provides no signal until all of its inputs have a signal.
-Read the [full puzzle](https://adventofcode.com/2015/day/7).
\ No newline at end of file
+The included instructions booklet describes how to connect the parts together: `x AND y -> z` means to connect wires `x` and `y` to an AND gate, and then connect its output to wire `z`.
+
+For example:
+
+
+ - `123 -> x` means that the signal `123` is provided to wire `x`.
+ - `x AND y -> z` means that the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of wire `x` and wire `y` is provided to wire `z`.
+ - `p LSHIFT 2 -> q` means that the value from wire `p` is [left-shifted](https://en.wikipedia.org/wiki/Logical_shift) by `2` and then provided to wire `q`.
+ - `NOT e -> f` means that the [bitwise complement](https://en.wikipedia.org/wiki/Bitwise_operation#NOT) of the value from wire `e` is provided to wire `f`.
+
+Other possible gates include `OR` ([bitwise OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR)) and `RSHIFT` ([right-shift](https://en.wikipedia.org/wiki/Logical_shift)). If, for some reason, you'd like to *emulate* the circuit instead, almost all programming languages (for example, [C](https://en.wikipedia.org/wiki/Bitwise_operations_in_C), [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators), or [Python](https://wiki.python.org/moin/BitwiseOperators)) provide operators for these gates.
+
+For example, here is a simple circuit:
+
+```
+123 -> x
+456 -> y
+x AND y -> d
+x OR y -> e
+x LSHIFT 2 -> f
+y RSHIFT 2 -> g
+NOT x -> h
+NOT y -> i
+```
+
+After it is run, these are the signals on the wires:
+
+```
+d: 72
+e: 507
+f: 492
+g: 114
+h: 65412
+i: 65079
+x: 123
+y: 456
+```
+
+In little Bobby's kit's instructions booklet (provided as your puzzle input), what signal is ultimately provided to *wire `a`*?
+
+
+## --- Part Two ---
+Now, take the signal you got on wire `a`, override wire `b` to that signal, and reset the other wires (including wire `a`). What new signal is ultimately provided to wire `a`?
+
+
diff --git a/2015/Day07/input.in b/2015/Day07/input.in
index 21197948f..1b7dfc90f 100644
Binary files a/2015/Day07/input.in and b/2015/Day07/input.in differ
diff --git a/2015/Day08/README.md b/2015/Day08/README.md
index acd31d5fc..96a564da8 100644
--- a/2015/Day08/README.md
+++ b/2015/Day08/README.md
@@ -1,6 +1,37 @@
+original source: [https://adventofcode.com/2015/day/8](https://adventofcode.com/2015/day/8)
## --- Day 8: Matchsticks ---
Space on the sleigh is limited this year, and so Santa will be bringing his list as a digital copy. He needs to know how much space it will take up when stored.
It is common in many programming languages to provide a way to escape special characters in strings. For example, [C](https://en.wikipedia.org/wiki/Escape_sequences_in_C), [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [Perl](http://perldoc.perl.org/perlop.html#Quote-and-Quote-like-Operators), [Python](https://docs.python.org/2.0/ref/strings.html), and even [PHP](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.double) handle special characters in very similar ways.
-Read the [full puzzle](https://adventofcode.com/2015/day/8).
\ No newline at end of file
+However, it is important to realize the difference between the number of characters *in the code representation of the string literal* and the number of characters *in the in-memory string itself*.
+
+For example:
+
+
+ - `""` is `2` characters of code (the two double quotes), but the string contains zero characters.
+ - `"abc"` is `5` characters of code, but `3` characters in the string data.
+ - `"aaa\"aaa"` is `10` characters of code, but the string itself contains six "a" characters and a single, escaped quote character, for a total of `7` characters in the string data.
+ - `"\x27"` is `6` characters of code, but the string itself contains just one - an apostrophe (`'`), escaped using hexadecimal notation.
+
+Santa's list is a file that contains many double-quoted string literals, one on each line. The only escape sequences used are `\\` (which represents a single backslash), `\"` (which represents a lone double-quote character), and `\x` plus two hexadecimal characters (which represents a single character with that ASCII code).
+
+Disregarding the whitespace in the file, what is *the number of characters of code for string literals* minus *the number of characters in memory for the values of the strings* in total for the entire file?
+
+For example, given the four strings above, the total number of characters of string code (`2 + 5 + 10 + 6 = 23`) minus the total number of characters in memory for string values (`0 + 3 + 7 + 1 = 11`) is `23 - 11 = 12`.
+
+
+## --- Part Two ---
+Now, let's go the other way. In addition to finding the number of characters of code, you should now *encode each code representation as a new string* and find the number of characters of the new encoded representation, including the surrounding double quotes.
+
+For example:
+
+
+ - `""` encodes to `"\"\""`, an increase from `2` characters to `6`.
+ - `"abc"` encodes to `"\"abc\""`, an increase from `5` characters to `9`.
+ - `"aaa\"aaa"` encodes to `"\"aaa\\\"aaa\""`, an increase from `10` characters to `16`.
+ - `"\x27"` encodes to `"\"\\x27\""`, an increase from `6` characters to `11`.
+
+Your task is to find *the total number of characters to represent the newly encoded strings* minus *the number of characters of code in each original string literal*. For example, for the strings above, the total encoded length (`6 + 9 + 16 + 11 = 42`) minus the characters in the original code representation (`23`, just like in the first part of this puzzle) is `42 - 23 = 19`.
+
+
diff --git a/2015/Day08/input.in b/2015/Day08/input.in
index a37076b5a..3e5be6553 100644
Binary files a/2015/Day08/input.in and b/2015/Day08/input.in differ
diff --git a/2015/Day09/README.md b/2015/Day09/README.md
index 9ea9bfada..a29da3479 100644
--- a/2015/Day09/README.md
+++ b/2015/Day09/README.md
@@ -1,6 +1,40 @@
+original source: [https://adventofcode.com/2015/day/9](https://adventofcode.com/2015/day/9)
## --- Day 9: All in a Single Night ---
Every year, Santa manages to deliver all of his presents in a single night.
This year, however, he has some new locations to visit; his elves have provided him the distances between every pair of locations. He can start and end at any two (different) locations he wants, but he must visit each location exactly once. What is the *shortest distance* he can travel to achieve this?
-Read the [full puzzle](https://adventofcode.com/2015/day/9).
\ No newline at end of file
+For example, given the following distances:
+
+```
+London to Dublin = 464
+London to Belfast = 518
+Dublin to Belfast = 141
+```
+
+The possible routes are therefore:
+
+```
+Dublin -> London -> Belfast = 982
+London -> Dublin -> Belfast = 605
+London -> Belfast -> Dublin = 659
+Dublin -> Belfast -> London = 659
+Belfast -> Dublin -> London = 605
+Belfast -> London -> Dublin = 982
+```
+
+The shortest of these is `London -> Dublin -> Belfast = 605`, and so the answer is `605` in this example.
+
+What is the distance of the shortest route?
+
+
+## --- Part Two ---
+The next year, just to show off, Santa decides to take the route with the *longest distance* instead.
+
+He can still start and end at any two (different) locations he wants, and he still must visit each location exactly once.
+
+For example, given the distances above, the longest route would be `982` via (for example) `Dublin -> London -> Belfast`.
+
+What is the distance of the longest route?
+
+
diff --git a/2015/Day09/input.in b/2015/Day09/input.in
index 9873e3051..a56f5e253 100644
Binary files a/2015/Day09/input.in and b/2015/Day09/input.in differ
diff --git a/2015/Day10/README.md b/2015/Day10/README.md
index e09b557f0..8099a370c 100644
--- a/2015/Day10/README.md
+++ b/2015/Day10/README.md
@@ -1,6 +1,24 @@
+original source: [https://adventofcode.com/2015/day/10](https://adventofcode.com/2015/day/10)
## --- Day 10: Elves Look, Elves Say ---
Today, the Elves are playing a game called [look-and-say](https://en.wikipedia.org/wiki/Look-and-say_sequence). They take turns making sequences by reading aloud the previous sequence and using that reading as the next sequence. For example, `211` is read as "one two, two ones", which becomes `1221` (`1` `2`, `2` `1`s).
Look-and-say sequences are generated iteratively, using the previous value as input for the next step. For each step, take the previous value, and replace each run of digits (like `111`) with the number of digits (`3`) followed by the digit itself (`1`).
-Read the [full puzzle](https://adventofcode.com/2015/day/10).
\ No newline at end of file
+For example:
+
+
+ - `1` becomes `11` (`1` copy of digit `1`).
+ - `11` becomes `21` (`2` copies of digit `1`).
+ - `21` becomes `1211` (one `2` followed by one `1`).
+ - `1211` becomes `111221` (one `1`, one `2`, and two `1`s).
+ - `111221` becomes `312211` (three `1`s, two `2`s, and one `1`).
+
+Starting with the digits in your puzzle input, apply this process 40 times. What is *the length of the result*?
+
+
+## --- Part Two ---
+Neat, right? You might also enjoy hearing [John Conway talking about this sequence](https://www.youtube.com/watch?v=ea7lJkEhytA) (that's Conway of *Conway's Game of Life* fame).
+
+Now, starting again with the digits in your puzzle input, apply this process *50* times. What is *the length of the new result*?
+
+
diff --git a/2015/Day10/input.in b/2015/Day10/input.in
index 33556dd98..067b0ee67 100644
Binary files a/2015/Day10/input.in and b/2015/Day10/input.in differ
diff --git a/2015/Day11/README.md b/2015/Day11/README.md
index f2d68ae2a..2471f1feb 100644
--- a/2015/Day11/README.md
+++ b/2015/Day11/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2015/day/11](https://adventofcode.com/2015/day/11)
## --- Day 11: Corporate Policy ---
Santa's previous password expired, and he needs help choosing a new one.
To help him remember his new password after the old one expires, Santa has devised a method of coming up with a password based on the previous one. Corporate policy dictates that passwords must be exactly eight lowercase letters (for security reasons), so he finds his new password by *incrementing* his old password string repeatedly until it is valid.
-Read the [full puzzle](https://adventofcode.com/2015/day/11).
\ No newline at end of file
+Incrementing is just like counting with numbers: `xx`, `xy`, `xz`, `ya`, `yb`, and so on. Increase the rightmost letter one step; if it was `z`, it wraps around to `a`, and repeat with the next letter to the left until one doesn't wrap around.
+
+Unfortunately for Santa, a new Security-Elf recently started, and he has imposed some additional password requirements:
+
+
+ - Passwords must include one increasing straight of at least three letters, like `abc`, `bcd`, `cde`, and so on, up to `xyz`. They cannot skip letters; `abd` doesn't count.
+ - Passwords may not contain the letters `i`, `o`, or `l`, as these letters can be mistaken for other characters and are therefore confusing.
+ - Passwords must contain at least two different, non-overlapping pairs of letters, like `aa`, `bb`, or `zz`.
+
+For example:
+
+
+ - `hijklmmn` meets the first requirement (because it contains the straight `hij`) but fails the second requirement requirement (because it contains `i` and `l`).
+ - `abbceffg` meets the third requirement (because it repeats `bb` and `ff`) but fails the first requirement.
+ - `abbcegjk` fails the third requirement, because it only has one double letter (`bb`).
+ - The next password after `abcdefgh` is `abcdffaa`.
+ - The next password after `ghijklmn` is `ghjaabcc`, because you eventually skip all the passwords that start with `ghi...`, since `i` is not allowed.
+
+Given Santa's current password (your puzzle input), what should his *next password* be?
+
+
+## --- Part Two ---
+Santa's password expired again. What's the next one?
+
+
diff --git a/2015/Day11/input.in b/2015/Day11/input.in
index cf3823d95..5915be7bb 100644
Binary files a/2015/Day11/input.in and b/2015/Day11/input.in differ
diff --git a/2015/Day12/README.md b/2015/Day12/README.md
index 45ad4b14e..b0863b30f 100644
--- a/2015/Day12/README.md
+++ b/2015/Day12/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2015/day/12](https://adventofcode.com/2015/day/12)
## --- Day 12: JSAbacusFramework.io ---
Santa's Accounting-Elves need help balancing the books after a recent order. Unfortunately, their accounting software uses a peculiar storage format. That's where you come in.
They have a [JSON](http://json.org/) document which contains a variety of things: arrays (`[1,2,3]`), objects (`{"a":1, "b":2}`), numbers, and strings. Your first job is to simply find all of the *numbers* throughout the document and add them together.
-Read the [full puzzle](https://adventofcode.com/2015/day/12).
\ No newline at end of file
+For example:
+
+
+ - `[1,2,3]` and `{"a":2,"b":4}` both have a sum of `6`.
+ - `[[[3]]]` and `{"a":{"b":4},"c":-1}` both have a sum of `3`.
+ - `{"a":[-1,1]}` and `[-1,{"a":1}]` both have a sum of `0`.
+ - `[]` and `{}` both have a sum of `0`.
+
+You will not encounter any strings containing numbers.
+
+What is the *sum of all numbers* in the document?
+
+
+## --- Part Two ---
+Uh oh - the Accounting-Elves have realized that they double-counted everything *red*.
+
+Ignore any object (and all of its children) which has any property with the value `"red"`. Do this only for objects (`{...}`), not arrays (`[...]`).
+
+
+ - `[1,2,3]` still has a sum of `6`.
+ - `[1,{"c":"red","b":2},3]` now has a sum of `4`, because the middle object is ignored.
+ - `{"d":"red","e":[1,2,3,4],"f":5}` now has a sum of `0`, because the entire structure is ignored.
+ - `[1,"red",5]` has a sum of `6`, because `"red"` in an array has no effect.
+
+
diff --git a/2015/Day12/input.in b/2015/Day12/input.in
index 6bce44176..d813484c5 100644
Binary files a/2015/Day12/input.in and b/2015/Day12/input.in differ
diff --git a/2015/Day13/README.md b/2015/Day13/README.md
index c126f8ae3..5eeb7bdfa 100644
--- a/2015/Day13/README.md
+++ b/2015/Day13/README.md
@@ -1,6 +1,48 @@
+original source: [https://adventofcode.com/2015/day/13](https://adventofcode.com/2015/day/13)
## --- Day 13: Knights of the Dinner Table ---
In years past, the holiday feast with your family hasn't gone so well. Not everyone gets along! This year, you resolve, will be different. You're going to find the *optimal seating arrangement* and avoid all those awkward conversations.
You start by writing up a list of everyone invited and the amount their happiness would increase or decrease if they were to find themselves sitting next to each other person. You have a circular table that will be just big enough to fit everyone comfortably, and so each person will have exactly two neighbors.
-Read the [full puzzle](https://adventofcode.com/2015/day/13).
\ No newline at end of file
+For example, suppose you have only four attendees planned, and you calculate their potential happiness as follows:
+
+```
+Alice would gain 54 happiness units by sitting next to Bob.
+Alice would lose 79 happiness units by sitting next to Carol.
+Alice would lose 2 happiness units by sitting next to David.
+Bob would gain 83 happiness units by sitting next to Alice.
+Bob would lose 7 happiness units by sitting next to Carol.
+Bob would lose 63 happiness units by sitting next to David.
+Carol would lose 62 happiness units by sitting next to Alice.
+Carol would gain 60 happiness units by sitting next to Bob.
+Carol would gain 55 happiness units by sitting next to David.
+David would gain 46 happiness units by sitting next to Alice.
+David would lose 7 happiness units by sitting next to Bob.
+David would gain 41 happiness units by sitting next to Carol.
+```
+
+Then, if you seat Alice next to David, Alice would lose `2` happiness units (because David talks so much), but David would gain `46` happiness units (because Alice is such a good listener), for a total change of `44`.
+
+If you continue around the table, you could then seat Bob next to Alice (Bob gains `83`, Alice gains `54`). Finally, seat Carol, who sits next to Bob (Carol gains `60`, Bob loses `7`) and David (Carol gains `55`, David gains `41`). The arrangement looks like this:
+
+```
+ +41 +46
++55 David -2
+Carol Alice
++60 Bob +54
+ -7 +83
+```
+
+After trying every other seating arrangement in this hypothetical scenario, you find that this one is the most optimal, with a total change in happiness of `330`.
+
+What is the *total change in happiness* for the optimal seating arrangement of the actual guest list?
+
+
+## --- Part Two ---
+In all the commotion, you realize that you forgot to seat yourself. At this point, you're pretty apathetic toward the whole thing, and your happiness wouldn't really go up or down regardless of who you sit next to. You assume everyone else would be just as ambivalent about sitting next to you, too.
+
+So, add yourself to the list, and give all happiness relationships that involve you a score of `0`.
+
+What is the *total change in happiness* for the optimal seating arrangement that actually includes yourself?
+
+
diff --git a/2015/Day13/input.in b/2015/Day13/input.in
index 67565872d..35be3572e 100644
Binary files a/2015/Day13/input.in and b/2015/Day13/input.in differ
diff --git a/2015/Day14/README.md b/2015/Day14/README.md
index c731da059..28fead086 100644
--- a/2015/Day14/README.md
+++ b/2015/Day14/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2015/day/14](https://adventofcode.com/2015/day/14)
## --- Day 14: Reindeer Olympics ---
This year is the Reindeer Olympics! Reindeer can fly at high speeds, but must rest occasionally to recover their energy. Santa would like to know which of his reindeer is fastest, and so he has them race.
Reindeer can only either be *flying* (always at their top speed) or *resting* (not moving at all), and always spend whole seconds in either state.
-Read the [full puzzle](https://adventofcode.com/2015/day/14).
\ No newline at end of file
+For example, suppose you have the following Reindeer:
+
+
+ - Comet can fly *14 km/s for 10 seconds*, but then must rest for *127 seconds*.
+ - Dancer can fly *16 km/s for 11 seconds*, but then must rest for *162 seconds*.
+
+After one second, Comet has gone 14 km, while Dancer has gone 16 km. After ten seconds, Comet has gone 140 km, while Dancer has gone 160 km. On the eleventh second, Comet begins resting (staying at 140 km), and Dancer continues on for a total distance of 176 km. On the 12th second, both reindeer are resting. They continue to rest until the 138th second, when Comet flies for another ten seconds. On the 174th second, Dancer flies for another 11 seconds.
+
+In this example, after the 1000th second, both reindeer are resting, and Comet is in the lead at *`1120`* km (poor Dancer has only gotten `1056` km by that point). So, in this situation, Comet would win (if the race ended at 1000 seconds).
+
+Given the descriptions of each reindeer (in your puzzle input), after exactly `2503` seconds, *what distance has the winning reindeer traveled*?
+
+
+## --- Part Two ---
+Seeing how reindeer move in bursts, Santa decides he's not pleased with the old scoring system.
+
+Instead, at the end of each second, he awards one point to the reindeer currently in the lead. (If there are multiple reindeer tied for the lead, they each get one point.) He keeps the traditional 2503 second time limit, of course, as doing otherwise would be entirely ridiculous.
+
+Given the example reindeer from above, after the first second, Dancer is in the lead and gets one point. He stays in the lead until several seconds into Comet's second burst: after the 140th second, Comet pulls into the lead and gets his first point. Of course, since Dancer had been in the lead for the 139 seconds before that, he has accumulated 139 points by the 140th second.
+
+After the 1000th second, Dancer has accumulated *`689`* points, while poor Comet, our old champion, only has `312`. So, with the new scoring system, Dancer would win (if the race ended at 1000 seconds).
+
+Again given the descriptions of each reindeer (in your puzzle input), after exactly `2503` seconds, *how many points does the winning reindeer have*?
+
+
diff --git a/2015/Day14/input.in b/2015/Day14/input.in
index c32701b9d..6cf5489fb 100644
Binary files a/2015/Day14/input.in and b/2015/Day14/input.in differ
diff --git a/2015/Day15/README.md b/2015/Day15/README.md
index b6a9deacf..9c00aa682 100644
--- a/2015/Day15/README.md
+++ b/2015/Day15/README.md
@@ -1,6 +1,44 @@
+original source: [https://adventofcode.com/2015/day/15](https://adventofcode.com/2015/day/15)
## --- Day 15: Science for Hungry People ---
Today, you set out on the task of perfecting your milk-dunking cookie recipe. All you have to do is find the right balance of ingredients.
Your recipe leaves room for exactly 100
teaspoons of ingredients. You make a list of the remaining ingredients you could use to finish the recipe (your puzzle input) and their properties per teaspoon:
-Read the [full puzzle](https://adventofcode.com/2015/day/15).
\ No newline at end of file
+
+ - capacity
(how well it helps the cookie absorb milk)
+ - durability
(how well it keeps the cookie intact when full of milk)
+ - flavor
(how tasty it makes the cookie)
+ - texture
(how it improves the feel of the cookie)
+ - calories
(how many calories it adds to the cookie)
+
+You can only measure ingredients in whole-teaspoon amounts accurately, and you have to be accurate so you can reproduce your results in the future. The total score of a cookie can be found by adding up each of the properties (negative totals become 0
) and then multiplying together everything except calories.
+
+For instance, suppose you have these two ingredients:
+
+
+Butterscotch: capacity -1, durability -2, flavor 6, texture 3, calories 8
+Cinnamon: capacity 2, durability 3, flavor -2, texture -1, calories 3
+
+
+
+Then, choosing to use 44
teaspoons of butterscotch and 56
teaspoons of cinnamon (because the amounts of each ingredient must add up to 100
) would result in a cookie with the following properties:
+
+
+ - A capacity
of 44*-1 + 56*2 = 68
+ - A durability
of 44*-2 + 56*3 = 80
+ - A flavor
of 44*6 + 56*-2 = 152
+ - A texture
of 44*3 + 56*-1 = 76
+
+Multiplying these together (68 * 80 * 152 * 76
, ignoring calories
for now) results in a total score of 62842880
, which happens to be the best score possible given these ingredients. If any properties had produced a negative total, it would have instead become zero, causing the whole score to multiply to zero.
+
+Given the ingredients in your kitchen and their properties, what is the total score of the highest-scoring cookie you can make?
+
+
+## --- Part Two ---
+Your cookie recipe becomes wildly popular! Someone asks if you can make another recipe that has exactly 500
calories per cookie (so they can use it as a meal replacement). Keep the rest of your award-winning process the same (100 teaspoons, same ingredients, same scoring system).
+
+For example, given the ingredients above, if you had instead selected 40
teaspoons of butterscotch and 60
teaspoons of cinnamon (which still adds to 100
), the total calorie count would be 40*8 + 60*3 = 500
. The total score would go down, though: only 57600000
, the best you can do in such trying circumstances.
+
+Given the ingredients in your kitchen and their properties, what is the total score of the highest-scoring cookie you can make with a calorie total of 500
?
+
+
diff --git a/2015/Day15/input.in b/2015/Day15/input.in
index 2a15a4bdf..6281182fe 100644
Binary files a/2015/Day15/input.in and b/2015/Day15/input.in differ
diff --git a/2015/Day16/README.md b/2015/Day16/README.md
index 2af56e4cf..e5c9c53ed 100644
--- a/2015/Day16/README.md
+++ b/2015/Day16/README.md
@@ -1,6 +1,47 @@
+original source: [https://adventofcode.com/2015/day/16](https://adventofcode.com/2015/day/16)
## --- Day 16: Aunt Sue ---
Your Aunt Sue has given you a wonderful gift, and you'd like to send her a thank you card. However, there's a small problem: she signed it "From, Aunt Sue".
You have 500 Aunts named "Sue".
-Read the [full puzzle](https://adventofcode.com/2015/day/16).
\ No newline at end of file
+So, to avoid sending the card to the wrong person, you need to figure out which Aunt Sue (which you conveniently number 1 to 500, for sanity) gave you the gift. You open the present and, as luck would have it, good ol' Aunt Sue got you a My First Crime Scene Analysis Machine! Just what you wanted. Or needed, as the case may be.
+
+The My First Crime Scene Analysis Machine (MFCSAM for short) can detect a few specific compounds in a given sample, as well as how many distinct kinds of those compounds there are. According to the instructions, these are what the MFCSAM can detect:
+
+
+ - `children`, by human DNA age analysis.
+ - `cats`. It doesn't differentiate individual breeds.
+ - Several seemingly random breeds of dog: `[samoyeds](https://en.wikipedia.org/wiki/Samoyed_%28dog%29)`, `[pomeranians](https://en.wikipedia.org/wiki/Pomeranian_%28dog%29)`, `[akitas](https://en.wikipedia.org/wiki/Akita_%28dog%29)`, and `[vizslas](https://en.wikipedia.org/wiki/Vizsla)`.
+ - `goldfish`. No other kinds of fish.
+ - `trees`, all in one group.
+ - `cars`, presumably by exhaust or gasoline or something.
+ - `perfumes`, which is handy, since many of your Aunts Sue wear a few kinds.
+
+In fact, many of your Aunts Sue have many of these. You put the wrapping from the gift into the MFCSAM. It beeps inquisitively at you a few times and then prints out a message on [ticker tape](https://en.wikipedia.org/wiki/Ticker_tape):
+
+```
+children: 3
+cats: 7
+samoyeds: 2
+pomeranians: 3
+akitas: 0
+vizslas: 0
+goldfish: 5
+trees: 3
+cars: 2
+perfumes: 1
+```
+
+You make a list of the things you can remember about each Aunt Sue. Things missing from your list aren't zero - you simply don't remember the value.
+
+What is the *number* of the Sue that got you the gift?
+
+
+## --- Part Two ---
+As you're about to send the thank you note, something in the MFCSAM's instructions catches your eye. Apparently, it has an outdated [retroencabulator](https://www.youtube.com/watch?v=RXJKdh1KZ0w), and so the output from the machine isn't exact values - some of them indicate ranges.
+
+In particular, the `cats` and `trees` readings indicates that there are *greater than* that many (due to the unpredictable nuclear decay of cat dander and tree pollen), while the `pomeranians` and `goldfish` readings indicate that there are *fewer than* that many (due to the modial interaction of magnetoreluctance).
+
+What is the *number* of the real Aunt Sue?
+
+
diff --git a/2015/Day16/input.in b/2015/Day16/input.in
index 88299f18a..ddaeefc31 100644
Binary files a/2015/Day16/input.in and b/2015/Day16/input.in differ
diff --git a/2015/Day17/README.md b/2015/Day17/README.md
index b38b90141..0b1d1f9be 100644
--- a/2015/Day17/README.md
+++ b/2015/Day17/README.md
@@ -1,6 +1,25 @@
+original source: [https://adventofcode.com/2015/day/17](https://adventofcode.com/2015/day/17)
## --- Day 17: No Such Thing as Too Much ---
The elves bought too much eggnog again - `150` liters this time. To fit it all into your refrigerator, you'll need to move it into smaller containers. You take an inventory of the capacities of the available containers.
For example, suppose you have containers of size `20`, `15`, `10`, `5`, and `5` liters. If you need to store `25` liters, there are four ways to do it:
-Read the [full puzzle](https://adventofcode.com/2015/day/17).
\ No newline at end of file
+
+ - `15` and `10`
+ - `20` and `5` (the first `5`)
+ - `20` and `5` (the second `5`)
+ - `15`, `5`, and `5`
+
+Filling all containers entirely, how many different *combinations of containers* can exactly fit all `150` liters of eggnog?
+
+
+## --- Part Two ---
+While playing with all the containers in the kitchen, another load of eggnog arrives! The shipping and receiving department is requesting as many containers as you can spare.
+
+Find the minimum number of containers that can exactly fit all `150` liters of eggnog. *How many different ways* can you fill that number of containers and still hold exactly `150` litres?
+
+In the example above, the minimum number of containers was two. There were three ways to use that many containers, and so the answer there would be `3`.
+
+
+
+
diff --git a/2015/Day17/input.in b/2015/Day17/input.in
index ebbf7e7ad..09ebd4694 100644
Binary files a/2015/Day17/input.in and b/2015/Day17/input.in differ
diff --git a/2015/Day18/README.md b/2015/Day18/README.md
index 05f646e0c..e18d65281 100644
--- a/2015/Day18/README.md
+++ b/2015/Day18/README.md
@@ -1,6 +1,136 @@
+original source: [https://adventofcode.com/2015/day/18](https://adventofcode.com/2015/day/18)
## --- Day 18: Like a GIF For Your Yard ---
After the [million lights incident](6), the fire code has gotten stricter: now, at most ten thousand lights are allowed. You arrange them in a 100x100 grid.
Never one to let you down, Santa again mails you instructions on the ideal lighting configuration. With so few lights, he says, you'll have to resort to *animation*.
-Read the [full puzzle](https://adventofcode.com/2015/day/18).
\ No newline at end of file
+Start by setting your lights to the included initial configuration (your puzzle input). A `#` means "on", and a `.` means "off".
+
+Then, animate your grid in steps, where each step decides the next configuration based on the current one. Each light's next state (either on or off) depends on its current state and the current states of the eight lights adjacent to it (including diagonals). Lights on the edge of the grid might have fewer than eight neighbors; the missing ones always count as "off".
+
+For example, in a simplified 6x6 grid, the light marked `A` has the neighbors numbered `1` through `8`, and the light marked `B`, which is on an edge, only has the neighbors marked `1` through `5`:
+
+```
+1B5...
+234...
+......
+..123.
+..8A4.
+..765.
+```
+
+The state a light should have next is based on its current state (on or off) plus the *number of neighbors that are on*:
+
+
+ - A light which is *on* stays on when `2` or `3` neighbors are on, and turns off otherwise.
+ - A light which is *off* turns on if exactly `3` neighbors are on, and stays off otherwise.
+
+All of the lights update simultaneously; they all consider the same current state before moving to the next.
+
+Here's a few steps from an example configuration of another 6x6 grid:
+
+```
+Initial state:
+.#.#.#
+...##.
+#....#
+..#...
+#.#..#
+####..
+
+After 1 step:
+..##..
+..##.#
+...##.
+......
+#.....
+#.##..
+
+After 2 steps:
+..###.
+......
+..###.
+......
+.#....
+.#....
+
+After 3 steps:
+...#..
+......
+...#..
+..##..
+......
+......
+
+After 4 steps:
+......
+......
+..##..
+..##..
+......
+......
+```
+
+After `4` steps, this example has four lights on.
+
+In your grid of 100x100 lights, given your initial configuration, *how many lights are on after 100 steps*?
+
+
+## --- Part Two ---
+You flip the instructions over; Santa goes on to point out that this is all just an implementation of [Conway's Game of Life](https://en.wikipedia.org/wiki/Conway's_Game_of_Life). At least, it was, until you notice that something's wrong with the grid of lights you bought: four lights, one in each corner, are *stuck on* and can't be turned off. The example above will actually run like this:
+
+```
+Initial state:
+##.#.#
+...##.
+#....#
+..#...
+#.#..#
+####.#
+
+After 1 step:
+#.##.#
+####.#
+...##.
+......
+#...#.
+#.####
+
+After 2 steps:
+#..#.#
+#....#
+.#.##.
+...##.
+.#..##
+##.###
+
+After 3 steps:
+#...##
+####.#
+..##.#
+......
+##....
+####.#
+
+After 4 steps:
+#.####
+#....#
+...#..
+.##...
+#.....
+#.#..#
+
+After 5 steps:
+##.###
+.##..#
+.##...
+.##...
+#.#...
+##...#
+```
+
+After `5` steps, this example now has `17` lights on.
+
+In your grid of 100x100 lights, given your initial configuration, but with the four corners always in the *on* state, *how many lights are on after 100 steps*?
+
+
diff --git a/2015/Day18/input.in b/2015/Day18/input.in
index 9c8fa75ed..e91a2a7e2 100644
Binary files a/2015/Day18/input.in and b/2015/Day18/input.in differ
diff --git a/2015/Day19/README.md b/2015/Day19/README.md
index 143c9b75b..bb0eae480 100644
--- a/2015/Day19/README.md
+++ b/2015/Day19/README.md
@@ -1,6 +1,61 @@
+original source: [https://adventofcode.com/2015/day/19](https://adventofcode.com/2015/day/19)
## --- Day 19: Medicine for Rudolph ---
Rudolph the Red-Nosed Reindeer is sick! His nose isn't shining very brightly, and he needs medicine.
Red-Nosed Reindeer biology isn't similar to regular reindeer biology; Rudolph is going to need custom-made medicine. Unfortunately, Red-Nosed Reindeer chemistry isn't similar to regular reindeer chemistry, either.
-Read the [full puzzle](https://adventofcode.com/2015/day/19).
\ No newline at end of file
+The North Pole is equipped with a Red-Nosed Reindeer nuclear fusion/fission plant, capable of constructing any Red-Nosed Reindeer molecule you need. It works by starting with some input molecule and then doing a series of *replacements*, one per step, until it has the right molecule.
+
+However, the machine has to be calibrated before it can be used. Calibration involves determining the number of molecules that can be generated in one step from a given starting point.
+
+For example, imagine a simpler machine that supports only the following replacements:
+
+```
+H => HO
+H => OH
+O => HH
+```
+
+Given the replacements above and starting with `HOH`, the following molecules could be generated:
+
+
+ - `HOOH` (via `H => HO` on the first `H`).
+ - `HOHO` (via `H => HO` on the second `H`).
+ - `OHOH` (via `H => OH` on the first `H`).
+ - `HOOH` (via `H => OH` on the second `H`).
+ - `HHHH` (via `O => HH`).
+
+So, in the example above, there are `4` *distinct* molecules (not five, because `HOOH` appears twice) after one replacement from `HOH`. Santa's favorite molecule, `HOHOHO`, can become `7` *distinct* molecules (over nine replacements: six from `H`, and three from `O`).
+
+The machine replaces without regard for the surrounding characters. For example, given the string `H2O`, the transition `H => OO` would result in `OO2O`.
+
+Your puzzle input describes all of the possible replacements and, at the bottom, the medicine molecule for which you need to calibrate the machine. *How many distinct molecules can be created* after all the different ways you can do one replacement on the medicine molecule?
+
+
+## --- Part Two ---
+Now that the machine is calibrated, you're ready to begin molecule fabrication.
+
+Molecule fabrication always begins with just a single electron, `e`, and applying replacements one at a time, just like the ones during calibration.
+
+For example, suppose you have the following replacements:
+
+```
+e => H
+e => O
+H => HO
+H => OH
+O => HH
+```
+
+If you'd like to make `HOH`, you start with `e`, and then make the following replacements:
+
+
+ - `e => O` to get `O`
+ - `O => HH` to get `HH`
+ - `H => OH` (on the second `H`) to get `HOH`
+
+So, you could make `HOH` after *`3` steps*. Santa's favorite molecule, `HOHOHO`, can be made in *`6` steps*.
+
+How long will it take to make the medicine? Given the available *replacements* and the *medicine molecule* in your puzzle input, what is the *fewest number of steps* to go from `e` to the medicine molecule?
+
+
diff --git a/2015/Day19/input.in b/2015/Day19/input.in
index e9fd053f8..b0515c05a 100644
Binary files a/2015/Day19/input.in and b/2015/Day19/input.in differ
diff --git a/2015/Day20/README.md b/2015/Day20/README.md
index 7948d8a4b..f07f7a25b 100644
--- a/2015/Day20/README.md
+++ b/2015/Day20/README.md
@@ -1,6 +1,38 @@
+original source: [https://adventofcode.com/2015/day/20](https://adventofcode.com/2015/day/20)
## --- Day 20: Infinite Elves and Infinite Houses ---
To keep the Elves busy, Santa has them deliver some presents by hand, door-to-door. He sends them down a street with infinite houses numbered sequentially: `1`, `2`, `3`, `4`, `5`, and so on.
Each Elf is assigned a number, too, and delivers presents to houses based on that number:
-Read the [full puzzle](https://adventofcode.com/2015/day/20).
\ No newline at end of file
+
+ - The first Elf (number `1`) delivers presents to every house: `1`, `2`, `3`, `4`, `5`, ....
+ - The second Elf (number `2`) delivers presents to every second house: `2`, `4`, `6`, `8`, `10`, ....
+ - Elf number `3` delivers presents to every third house: `3`, `6`, `9`, `12`, `15`, ....
+
+There are infinitely many Elves, numbered starting with `1`. Each Elf delivers presents equal to *ten times* his or her number at each house.
+
+So, the first nine houses on the street end up like this:
+
+```
+House 1 got 10 presents.
+House 2 got 30 presents.
+House 3 got 40 presents.
+House 4 got 70 presents.
+House 5 got 60 presents.
+House 6 got 120 presents.
+House 7 got 80 presents.
+House 8 got 150 presents.
+House 9 got 130 presents.
+```
+
+The first house gets `10` presents: it is visited only by Elf `1`, which delivers `1 * 10 = 10` presents. The fourth house gets `70` presents, because it is visited by Elves `1`, `2`, and `4`, for a total of `10 + 20 + 40 = 70` presents.
+
+What is the *lowest house number* of the house to get at least as many presents as the number in your puzzle input?
+
+
+## --- Part Two ---
+The Elves decide they don't want to visit an infinite number of houses. Instead, each Elf will stop after delivering presents to `50` houses. To make up for it, they decide to deliver presents equal to *eleven times* their number at each house.
+
+With these changes, what is the new *lowest house number* of the house to get at least as many presents as the number in your puzzle input?
+
+
diff --git a/2015/Day20/input.in b/2015/Day20/input.in
index 70de3846e..f0d833616 100644
Binary files a/2015/Day20/input.in and b/2015/Day20/input.in differ
diff --git a/2015/Day21/README.md b/2015/Day21/README.md
index b35a9cffb..16083551f 100644
--- a/2015/Day21/README.md
+++ b/2015/Day21/README.md
@@ -1,6 +1,60 @@
+original source: [https://adventofcode.com/2015/day/21](https://adventofcode.com/2015/day/21)
## --- Day 21: RPG Simulator 20XX ---
Little Henry Case got a new video game for Christmas. It's an [RPG](https://en.wikipedia.org/wiki/Role-playing_video_game), and he's stuck on a boss. He needs to know what equipment to buy at the shop. He hands you the [controller](https://en.wikipedia.org/wiki/Game_controller).
In this game, the player (you) and the enemy (the boss) take turns attacking. The player always goes first. Each attack reduces the opponent's hit points by at least `1`. The first character at or below `0` hit points loses.
-Read the [full puzzle](https://adventofcode.com/2015/day/21).
\ No newline at end of file
+Damage dealt by an attacker each turn is equal to the attacker's damage score minus the defender's armor score. An attacker always does at least `1` damage. So, if the attacker has a damage score of `8`, and the defender has an armor score of `3`, the defender loses `5` hit points. If the defender had an armor score of `300`, the defender would still lose `1` hit point.
+
+Your damage score and armor score both start at zero. They can be increased by buying items in exchange for gold. You start with no items and have as much gold as you need. Your total damage or armor is equal to the sum of those stats from all of your items. You have *100 hit points*.
+
+Here is what the item shop is selling:
+
+```
+Weapons: Cost Damage Armor
+Dagger 8 4 0
+Shortsword 10 5 0
+Warhammer 25 6 0
+Longsword 40 7 0
+Greataxe 74 8 0
+
+Armor: Cost Damage Armor
+Leather 13 0 1
+Chainmail 31 0 2
+Splintmail 53 0 3
+Bandedmail 75 0 4
+Platemail 102 0 5
+
+Rings: Cost Damage Armor
+Damage +1 25 1 0
+Damage +2 50 2 0
+Damage +3 100 3 0
+Defense +1 20 0 1
+Defense +2 40 0 2
+Defense +3 80 0 3
+```
+
+You must buy exactly one weapon; no dual-wielding. Armor is optional, but you can't use more than one. You can buy 0-2 rings (at most one for each hand). You must use any items you buy. The shop only has one of each item, so you can't buy, for example, two rings of Damage +3.
+
+For example, suppose you have `8` hit points, `5` damage, and `5` armor, and that the boss has `12` hit points, `7` damage, and `2` armor:
+
+
+ - The player deals `5-2 = 3` damage; the boss goes down to 9 hit points.
+ - The boss deals `7-5 = 2` damage; the player goes down to 6 hit points.
+ - The player deals `5-2 = 3` damage; the boss goes down to 6 hit points.
+ - The boss deals `7-5 = 2` damage; the player goes down to 4 hit points.
+ - The player deals `5-2 = 3` damage; the boss goes down to 3 hit points.
+ - The boss deals `7-5 = 2` damage; the player goes down to 2 hit points.
+ - The player deals `5-2 = 3` damage; the boss goes down to 0 hit points.
+
+In this scenario, the player wins! (Barely.)
+
+You have *100 hit points*. The boss's actual stats are in your puzzle input. What is *the least amount of gold you can spend* and still win the fight?
+
+
+## --- Part Two ---
+Turns out the shopkeeper is working with the boss, and can persuade you to buy whatever items he wants. The other rules still apply, and he still only has one of each item.
+
+What is the *most* amount of gold you can spend and still *lose* the fight?
+
+
diff --git a/2015/Day21/input.in b/2015/Day21/input.in
index 86a205cfd..e74905192 100644
Binary files a/2015/Day21/input.in and b/2015/Day21/input.in differ
diff --git a/2015/Day22/README.md b/2015/Day22/README.md
index 26a245daa..a2659cf82 100644
--- a/2015/Day22/README.md
+++ b/2015/Day22/README.md
@@ -1,6 +1,125 @@
+original source: [https://adventofcode.com/2015/day/22](https://adventofcode.com/2015/day/22)
## --- Day 22: Wizard Simulator 20XX ---
Little Henry Case decides that defeating bosses with [swords and stuff](21) is boring. Now he's playing the game with a wizard. Of course, he gets stuck on another boss and needs your help again.
In this version, combat still proceeds with the player and the boss taking alternating turns. The player still goes first. Now, however, you don't get any equipment; instead, you must choose one of your spells to cast. The first character at or below `0` hit points loses.
-Read the [full puzzle](https://adventofcode.com/2015/day/22).
\ No newline at end of file
+Since you're a wizard, you don't get to wear armor, and you can't attack normally. However, since you do *magic damage*, your opponent's armor is ignored, and so the boss effectively has zero armor as well. As before, if armor (from a spell, in this case) would reduce damage below `1`, it becomes `1` instead - that is, the boss' attacks always deal at least `1` damage.
+
+On each of your turns, you must select one of your spells to cast. If you cannot afford to cast any spell, you lose. Spells cost *mana*; you start with *500* mana, but have no maximum limit. You must have enough mana to cast a spell, and its cost is immediately deducted when you cast it. Your spells are Magic Missile, Drain, Shield, Poison, and Recharge.
+
+
+ - *Magic Missile* costs `53` mana. It instantly does `4` damage.
+ - *Drain* costs `73` mana. It instantly does `2` damage and heals you for `2` hit points.
+ - *Shield* costs `113` mana. It starts an *effect* that lasts for `6` turns. While it is active, your armor is increased by `7`.
+ - *Poison* costs `173` mana. It starts an *effect* that lasts for `6` turns. At the start of each turn while it is active, it deals the boss `3` damage.
+ - *Recharge* costs `229` mana. It starts an *effect* that lasts for `5` turns. At the start of each turn while it is active, it gives you `101` new mana.
+
+*Effects* all work the same way. Effects apply at the start of both the player's turns and the boss' turns. Effects are created with a timer (the number of turns they last); at the start of each turn, after they apply any effect they have, their timer is decreased by one. If this decreases the timer to zero, the effect ends. You cannot cast a spell that would start an effect which is already active. However, effects can be started on the same turn they end.
+
+For example, suppose the player has `10` hit points and `250` mana, and that the boss has `13` hit points and `8` damage:
+
+```
+-- Player turn --
+- Player has 10 hit points, 0 armor, 250 mana
+- Boss has 13 hit points
+Player casts Poison.
+
+-- Boss turn --
+- Player has 10 hit points, 0 armor, 77 mana
+- Boss has 13 hit points
+Poison deals 3 damage; its timer is now 5.
+Boss attacks for 8 damage.
+
+-- Player turn --
+- Player has 2 hit points, 0 armor, 77 mana
+- Boss has 10 hit points
+Poison deals 3 damage; its timer is now 4.
+Player casts Magic Missile, dealing 4 damage.
+
+-- Boss turn --
+- Player has 2 hit points, 0 armor, 24 mana
+- Boss has 3 hit points
+Poison deals 3 damage. This kills the boss, and the player wins.
+```
+
+Now, suppose the same initial conditions, except that the boss has `14` hit points instead:
+
+```
+-- Player turn --
+- Player has 10 hit points, 0 armor, 250 mana
+- Boss has 14 hit points
+Player casts Recharge.
+
+-- Boss turn --
+- Player has 10 hit points, 0 armor, 21 mana
+- Boss has 14 hit points
+Recharge provides 101 mana; its timer is now 4.
+Boss attacks for 8 damage!
+
+-- Player turn --
+- Player has 2 hit points, 0 armor, 122 mana
+- Boss has 14 hit points
+Recharge provides 101 mana; its timer is now 3.
+Player casts Shield, increasing armor by 7.
+
+-- Boss turn --
+- Player has 2 hit points, 7 armor, 110 mana
+- Boss has 14 hit points
+Shield's timer is now 5.
+Recharge provides 101 mana; its timer is now 2.
+Boss attacks for 8 - 7 = 1 damage!
+
+-- Player turn --
+- Player has 1 hit point, 7 armor, 211 mana
+- Boss has 14 hit points
+Shield's timer is now 4.
+Recharge provides 101 mana; its timer is now 1.
+Player casts Drain, dealing 2 damage, and healing 2 hit points.
+
+-- Boss turn --
+- Player has 3 hit points, 7 armor, 239 mana
+- Boss has 12 hit points
+Shield's timer is now 3.
+Recharge provides 101 mana; its timer is now 0.
+Recharge wears off.
+Boss attacks for 8 - 7 = 1 damage!
+
+-- Player turn --
+- Player has 2 hit points, 7 armor, 340 mana
+- Boss has 12 hit points
+Shield's timer is now 2.
+Player casts Poison.
+
+-- Boss turn --
+- Player has 2 hit points, 7 armor, 167 mana
+- Boss has 12 hit points
+Shield's timer is now 1.
+Poison deals 3 damage; its timer is now 5.
+Boss attacks for 8 - 7 = 1 damage!
+
+-- Player turn --
+- Player has 1 hit point, 7 armor, 167 mana
+- Boss has 9 hit points
+Shield's timer is now 0.
+Shield wears off, decreasing armor by 7.
+Poison deals 3 damage; its timer is now 4.
+Player casts Magic Missile, dealing 4 damage.
+
+-- Boss turn --
+- Player has 1 hit point, 0 armor, 114 mana
+- Boss has 2 hit points
+Poison deals 3 damage. This kills the boss, and the player wins.
+```
+
+You start with *50 hit points* and *500 mana points*. The boss's actual stats are in your puzzle input. What is the *least amount of mana* you can spend and still win the fight? (Do not include mana recharge effects as "spending" negative mana.)
+
+
+## --- Part Two ---
+On the next run through the game, you increase the difficulty to *hard*.
+
+At the start of each *player turn* (before any other effects apply), you lose `1` hit point. If this brings you to or below `0` hit points, you lose.
+
+With the same starting stats for you and the boss, what is the *least amount of mana* you can spend and still win the fight?
+
+
diff --git a/2015/Day22/input.in b/2015/Day22/input.in
index c3d03ea5f..db93bd09a 100644
Binary files a/2015/Day22/input.in and b/2015/Day22/input.in differ
diff --git a/2015/Day23/README.md b/2015/Day23/README.md
index 03c6983b0..3b3556deb 100644
--- a/2015/Day23/README.md
+++ b/2015/Day23/README.md
@@ -1,6 +1,34 @@
+original source: [https://adventofcode.com/2015/day/23](https://adventofcode.com/2015/day/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](https://en.wikipedia.org/wiki/Processor_register) and six [instructions](https://en.wikipedia.org/wiki/Instruction_set) (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](https://en.wikipedia.org/wiki/Natural_number), and begin with a value of `0`. The instructions are as follows:
-Read the [full puzzle](https://adventofcode.com/2015/day/23).
\ No newline at end of file
+
+ - `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?
+
+
+## --- Part Two ---
+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?
+
+
diff --git a/2015/Day23/input.in b/2015/Day23/input.in
index a34fa99f1..79d96248e 100644
Binary files a/2015/Day23/input.in and b/2015/Day23/input.in differ
diff --git a/2015/Day24/README.md b/2015/Day24/README.md
index c00ce7cf2..2c1c9f643 100644
--- a/2015/Day24/README.md
+++ b/2015/Day24/README.md
@@ -1,6 +1,60 @@
+original source: [https://adventofcode.com/2015/day/24](https://adventofcode.com/2015/day/24)
## --- Day 24: It Hangs in the Balance ---
It's Christmas Eve, and Santa is loading up the sleigh for this year's deliveries. However, there's one small problem: he can't get the sleigh to balance. If it isn't balanced, he can't defy physics, and nobody gets presents this year.
No pressure.
-Read the [full puzzle](https://adventofcode.com/2015/day/24).
\ No newline at end of file
+Santa has provided you a list of the weights of every package he needs to fit on the sleigh. The packages need to be split into *three groups of exactly the same weight*, and every package has to fit. The first group goes in the passenger compartment of the sleigh, and the second and third go in containers on either side. Only when all three groups weigh exactly the same amount will the sleigh be able to fly. Defying physics has rules, you know!
+
+Of course, that's not the only problem. The first group - the one going in the passenger compartment - needs *as few packages as possible* so that Santa has some legroom left over. It doesn't matter how many packages are in either of the other two groups, so long as all of the groups weigh the same.
+
+Furthermore, Santa tells you, if there are multiple ways to arrange the packages such that the fewest possible are in the first group, you need to choose the way where the first group has *the smallest quantum entanglement* to reduce the chance of any "complications". The quantum entanglement of a group of packages is the [product](https://en.wikipedia.org/wiki/Product_%28mathematics%29) of their weights, that is, the value you get when you multiply their weights together. Only consider quantum entanglement if the first group has the fewest possible number of packages in it and all groups weigh the same amount.
+
+For example, suppose you have ten packages with weights `1` through `5` and `7` through `11`. For this situation, some of the unique first groups, their quantum entanglements, and a way to divide the remaining packages are as follows:
+
+```
+Group 1; Group 2; Group 3
+11 9 (QE= 99); 10 8 2; 7 5 4 3 1
+10 9 1 (QE= 90); 11 7 2; 8 5 4 3
+10 8 2 (QE=160); 11 9; 7 5 4 3 1
+10 7 3 (QE=210); 11 9; 8 5 4 2 1
+10 5 4 1 (QE=200); 11 9; 8 7 3 2
+10 5 3 2 (QE=300); 11 9; 8 7 4 1
+10 4 3 2 1 (QE=240); 11 9; 8 7 5
+9 8 3 (QE=216); 11 7 2; 10 5 4 1
+9 7 4 (QE=252); 11 8 1; 10 5 3 2
+9 5 4 2 (QE=360); 11 8 1; 10 7 3
+8 7 5 (QE=280); 11 9; 10 4 3 2 1
+8 5 4 3 (QE=480); 11 9; 10 7 2 1
+7 5 4 3 1 (QE=420); 11 9; 10 8 2
+```
+
+Of these, although `10 9 1` has the smallest quantum entanglement (`90`), the configuration with only two packages, `11 9`, in the passenger compartment gives Santa the most legroom and wins. In this situation, the quantum entanglement for the ideal configuration is therefore `99`. Had there been two configurations with only two packages in the first group, the one with the smaller quantum entanglement would be chosen.
+
+What is the *quantum entanglement* of the first group of packages in the ideal configuration?
+
+
+## --- Part Two ---
+That's weird... the sleigh still isn't balancing.
+
+"Ho ho ho", Santa muses to himself. "I forgot the trunk".
+
+Balance the sleigh again, but this time, separate the packages into *four groups* instead of three. The other constraints still apply.
+
+Given the example packages above, this would be some of the new unique first groups, their quantum entanglements, and one way to divide the remaining packages:
+
+```
+
+11 4 (QE=44); 10 5; 9 3 2 1; 8 7
+10 5 (QE=50); 11 4; 9 3 2 1; 8 7
+9 5 1 (QE=45); 11 4; 10 3 2; 8 7
+9 4 2 (QE=72); 11 3 1; 10 5; 8 7
+9 3 2 1 (QE=54); 11 4; 10 5; 8 7
+8 7 (QE=56); 11 4; 10 5; 9 3 2 1
+```
+
+Of these, there are three arrangements that put the minimum (two) number of packages in the first group: `11 4`, `10 5`, and `8 7`. Of these, `11 4` has the lowest quantum entanglement, and so it is selected.
+
+Now, what is the *quantum entanglement* of the first group of packages in the ideal configuration?
+
+
diff --git a/2015/Day24/input.in b/2015/Day24/input.in
index 3d36932f3..502fad752 100644
Binary files a/2015/Day24/input.in and b/2015/Day24/input.in differ
diff --git a/2015/Day25/README.md b/2015/Day25/README.md
index 9107dfdd5..cbb486578 100644
--- a/2015/Day25/README.md
+++ b/2015/Day25/README.md
@@ -1,6 +1,57 @@
+original source: [https://adventofcode.com/2015/day/25](https://adventofcode.com/2015/day/25)
## --- Day 25: Let It Snow ---
Merry Christmas! Santa is booting up his weather machine; looks like you might get a [white Christmas](1) after all.
The weather machine beeps! On the console of the machine is a copy protection message asking you to [enter a code from the instruction manual](https://en.wikipedia.org/wiki/Copy_protection#Early_video_games). Apparently, it refuses to run unless you give it that code. No problem; you'll just look up the code in the--
-Read the [full puzzle](https://adventofcode.com/2015/day/25).
\ No newline at end of file
+"Ho ho ho", Santa ponders aloud. "I can't seem to find the manual."
+
+You look up the support number for the manufacturer and give them a call. Good thing, too - that 49th star wasn't going to earn itself.
+
+"Oh, that machine is quite old!", they tell you. "That model went out of support six minutes ago, and we just finished shredding all of the manuals. I bet we can find you the code generation algorithm, though."
+
+After putting you on hold for twenty minutes (your call is *very* important to them, it reminded you repeatedly), they finally find an engineer that remembers how the code system works.
+
+The codes are printed on an infinite sheet of paper, starting in the top-left corner. The codes are filled in by diagonals: starting with the first row with an empty first box, the codes are filled in diagonally up and to the right. This process repeats until the [infinite paper is covered](https://en.wikipedia.org/wiki/Cantor's_diagonal_argument). So, the first few codes are filled in in this order:
+
+```
+ | 1 2 3 4 5 6
+---+---+---+---+---+---+---+
+ 1 | 1 3 6 10 15 21
+ 2 | 2 5 9 14 20
+ 3 | 4 8 13 19
+ 4 | 7 12 18
+ 5 | 11 17
+ 6 | 16
+```
+
+For example, the 12th code would be written to row `4`, column `2`; the 15th code would be written to row `1`, column `5`.
+
+The voice on the other end of the phone continues with how the codes are actually generated. The first code is `20151125`. After that, each code is generated by taking the previous one, multiplying it by `252533`, and then keeping the remainder from dividing that value by `33554393`.
+
+So, to find the second code (which ends up in row `2`, column `1`), start with the previous value, `20151125`. Multiply it by `252533` to get `5088824049625`. Then, divide that by `33554393`, which leaves a remainder of `31916031`. That remainder is the second code.
+
+"Oh!", says the voice. "It looks like we missed a scrap from one of the manuals. Let me read it to you." You write down his numbers:
+
+```
+ | 1 2 3 4 5 6
+---+---------+---------+---------+---------+---------+---------+
+ 1 | 20151125 18749137 17289845 30943339 10071777 33511524
+ 2 | 31916031 21629792 16929656 7726640 15514188 4041754
+ 3 | 16080970 8057251 1601130 7981243 11661866 16474243
+ 4 | 24592653 32451966 21345942 9380097 10600672 31527494
+ 5 | 77061 17552253 28094349 6899651 9250759 31663883
+ 6 | 33071741 6796745 25397450 24659492 1534922 27995004
+```
+
+"Now remember", the voice continues, "that's not even all of the first few numbers; for example, you're missing the one at 7,1 that would come before 6,2. But, it should be enough to let your-- oh, it's time for lunch! Bye!" The call disconnects.
+
+Santa looks nervous. Your puzzle input contains the message on the machine's console. *What code do you give the machine?*
+
+
+## --- Part Two ---
+The machine springs to life, then falls silent again. It beeps. "Insufficient fuel", the console reads. "*Fifty stars* are required before proceeding. *One star* is available."
+
+..."one star is available"? You check the fuel tank; sure enough, a lone star sits at the bottom, awaiting its friends. Looks like you need to provide 49 yourself.
+
+
diff --git a/2015/Day25/input.in b/2015/Day25/input.in
index d4c53d3dd..08d9d8f8b 100644
Binary files a/2015/Day25/input.in and b/2015/Day25/input.in differ
diff --git a/2015/README.md b/2015/README.md
index a98cc6d87..e642371f9 100644
--- a/2015/README.md
+++ b/2015/README.md
@@ -1,4 +1,6 @@
+
# Advent of Code (2015)
Check out https://adventofcode.com/2015.
L
) or right (R
) 90 degrees, then walk forward the given number of blocks, ending at a new intersection.
+
+There's no time to follow such ridiculous instructions on foot, though, so you take a moment and work out the destination. Given that you can only walk on the [street grid of the city](https://en.wikipedia.org/wiki/Taxicab_geometry), how far is the shortest path to the destination?
+
+For example:
+
+
+ - Following R2, L3
leaves you 2
blocks East and 3
blocks North, or 5
blocks away.
+ - R2, R2, R2
leaves you 2
blocks due South of your starting position, which is 2
blocks away.
+ - R5, L5, R5, R3
leaves you 12
blocks away.
+
+How many blocks away is Easter Bunny HQ?
+
+
+## --- Part Two ---
+Then, you notice the instructions continue on the back of the Recruiting Document. Easter Bunny HQ is actually at the first location you visit twice.
+
+For example, if your instructions are R8, R4, R4, R8
, the first location you visit twice is 4
blocks away, due East.
+
+How many blocks away is the first location you visit twice?
+
+
diff --git a/2016/Day01/input.in b/2016/Day01/input.in
index 687ec0109..94fce73c0 100644
Binary files a/2016/Day01/input.in and b/2016/Day01/input.in differ
diff --git a/2016/Day02/README.md b/2016/Day02/README.md
index 345a8b762..3f7b63bfa 100644
--- a/2016/Day02/README.md
+++ b/2016/Day02/README.md
@@ -1,6 +1,61 @@
+original source: [https://adventofcode.com/2016/day/2](https://adventofcode.com/2016/day/2)
## --- Day 2: Bathroom Security ---
You arrive at *Easter Bunny Headquarters* under cover of darkness. However, you left in such a rush that you forgot to use the bathroom! Fancy office buildings like this one usually have keypad locks on their bathrooms, so you search the front desk for the code.
"In order to improve security," the document you find says, "bathroom codes will no longer be written down. Instead, please memorize and follow the procedure below to access the bathrooms."
-Read the [full puzzle](https://adventofcode.com/2016/day/2).
\ No newline at end of file
+The document goes on to explain that each button to be pressed can be found by starting on the previous button and moving to adjacent buttons on the keypad: `U` moves up, `D` moves down, `L` moves left, and `R` moves right. Each line of instructions corresponds to one button, starting at the previous button (or, for the first line, *the "5" button*); press whatever button you're on at the end of each line. If a move doesn't lead to a button, ignore it.
+
+You can't hold it much longer, so you decide to figure out the code as you walk to the bathroom. You picture a keypad like this:
+
+```
+1 2 3
+4 5 6
+7 8 9
+```
+
+Suppose your instructions are:
+
+```
+ULL
+RRDDD
+LURDL
+UUUUD
+```
+
+
+ - You start at "5" and move up (to "2"), left (to "1"), and left (you can't, and stay on "1"), so the first button is `1`.
+ - Starting from the previous button ("1"), you move right twice (to "3") and then down three times (stopping at "9" after two moves and ignoring the third), ending up with `9`.
+ - Continuing from "9", you move left, up, right, down, and left, ending with `8`.
+ - Finally, you move up four times (stopping at "2"), then down once, ending with `5`.
+
+So, in this example, the bathroom code is `1985`.
+
+Your puzzle input is the instructions from the document you found at the front desk. What is the *bathroom code*?
+
+
+## --- Part Two ---
+
+You finally arrive at the bathroom (it's a several minute walk from the lobby so visitors can behold the many fancy conference rooms and water coolers on this floor) and go to punch in the code. Much to your bladder's dismay, the keypad is not at all like you imagined it. Instead, you are confronted with the result of hundreds of man-hours of bathroom-keypad-design meetings:
+
+```
+ 1
+ 2 3 4
+5 6 7 8 9
+ A B C
+ D
+```
+
+You still start at "5" and stop when you're at an edge, but given the same instructions as above, the outcome is very different:
+
+
+ - You start at "5" and don't move at all (up and left are both edges), ending at `5`.
+ - Continuing from "5", you move right twice and down three times (through "6", "7", "B", "D", "D"), ending at `D`.
+ - Then, from "D", you move five more times (through "D", "B", "C", "C", "B"), ending at `B`.
+ - Finally, after five more moves, you end at `3`.
+
+So, given the actual keypad layout, the code would be `5DB3`.
+
+Using the same instructions in your puzzle input, what is the correct *bathroom code*?
+
+
diff --git a/2016/Day02/input.in b/2016/Day02/input.in
index df0dff54a..e133bb645 100644
Binary files a/2016/Day02/input.in and b/2016/Day02/input.in differ
diff --git a/2016/Day03/README.md b/2016/Day03/README.md
index cd2bf19f7..cd1bf8693 100644
--- a/2016/Day03/README.md
+++ b/2016/Day03/README.md
@@ -1,6 +1,30 @@
+original source: [https://adventofcode.com/2016/day/3](https://adventofcode.com/2016/day/3)
## --- Day 3: Squares With Three Sides ---
Now that you can think clearly, you move deeper into the labyrinth of hallways and office furniture that makes up this part of Easter Bunny HQ. This must be a graphic design department; the walls are covered in specifications for triangles.
Or are they?
-Read the [full puzzle](https://adventofcode.com/2016/day/3).
\ No newline at end of file
+The design document gives the side lengths of each triangle it describes, but... `5 10 25`? Some of these aren't triangles. You can't help but mark the impossible ones.
+
+In a valid triangle, the sum of any two sides must be larger than the remaining side. For example, the "triangle" given above is impossible, because `5 + 10` is not larger than `25`.
+
+In your puzzle input, *how many* of the listed triangles are *possible*?
+
+
+## --- Part Two ---
+Now that you've helpfully marked up their design documents, it occurs to you that triangles are specified in groups of three *vertically*. Each set of three numbers in a column specifies a triangle. Rows are unrelated.
+
+For example, given the following specification, numbers with the same hundreds digit would be part of the same triangle:
+
+```
+101 301 501
+102 302 502
+103 303 503
+201 401 601
+202 402 602
+203 403 603
+```
+
+In your puzzle input, and instead reading by columns, *how many* of the listed triangles are *possible*?
+
+
diff --git a/2016/Day03/input.in b/2016/Day03/input.in
index 84fc5ad53..065758086 100644
Binary files a/2016/Day03/input.in and b/2016/Day03/input.in differ
diff --git a/2016/Day04/README.md b/2016/Day04/README.md
index 39105dd2f..84004a1c0 100644
--- a/2016/Day04/README.md
+++ b/2016/Day04/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2016/day/4](https://adventofcode.com/2016/day/4)
## --- Day 4: Security Through Obscurity ---
Finally, you come across an information kiosk with a list of rooms. Of course, the list is encrypted and full of decoy data, but the instructions to decode the list are barely hidden nearby. Better remove the decoy data first.
Each room consists of an encrypted name (lowercase letters separated by dashes) followed by a dash, a sector ID, and a checksum in square brackets.
-Read the [full puzzle](https://adventofcode.com/2016/day/4).
\ No newline at end of file
+A room is real (not a decoy) if the checksum is the five most common letters in the encrypted name, in order, with ties broken by alphabetization. For example:
+
+
+ - `aaaaa-bbb-z-y-x-123[abxyz]` is a real room because the most common letters are `a` (5), `b` (3), and then a tie between `x`, `y`, and `z`, which are listed alphabetically.
+ - `a-b-c-d-e-f-g-h-987[abcde]` is a real room because although the letters are all tied (1 of each), the first five are listed alphabetically.
+ - `not-a-real-room-404[oarel]` is a real room.
+ - `totally-real-room-200[decoy]` is not.
+
+Of the real rooms from the list above, the sum of their sector IDs is `1514`.
+
+What is the *sum of the sector IDs of the real rooms*?
+
+
+## --- Part Two ---
+With all the decoy data out of the way, it's time to decrypt this list and get moving.
+
+The room names are encrypted by a state-of-the-art [shift cipher](https://en.wikipedia.org/wiki/Caesar_cipher), which is nearly unbreakable without the right software. However, the information kiosk designers at Easter Bunny HQ were not expecting to deal with a master cryptographer like yourself.
+
+To decrypt a room name, rotate each letter forward through the alphabet a number of times equal to the room's sector ID. `A` becomes `B`, `B` becomes `C`, `Z` becomes `A`, and so on. Dashes become spaces.
+
+For example, the real name for `qzmt-zixmtkozy-ivhz-343` is `very encrypted name`.
+
+*What is the sector ID* of the room where North Pole objects are stored?
+
+
diff --git a/2016/Day04/input.in b/2016/Day04/input.in
index c951db70c..c80cd7b19 100644
Binary files a/2016/Day04/input.in and b/2016/Day04/input.in differ
diff --git a/2016/Day05/README.md b/2016/Day05/README.md
index e510a6e67..51944b377 100644
--- a/2016/Day05/README.md
+++ b/2016/Day05/README.md
@@ -1,6 +1,39 @@
+original source: [https://adventofcode.com/2016/day/5](https://adventofcode.com/2016/day/5)
## --- Day 5: How About a Nice Game of Chess? ---
You are faced with a security door designed by Easter Bunny engineers that seem to have acquired most of their security knowledge by watching [hacking](https://en.wikipedia.org/wiki/Hackers_(film)) [movies](https://en.wikipedia.org/wiki/WarGames).
The *eight-character password* for the door is generated one character at a time by finding the [MD5](https://en.wikipedia.org/wiki/MD5) hash of some Door ID (your puzzle input) and an increasing integer index (starting with `0`).
-Read the [full puzzle](https://adventofcode.com/2016/day/5).
\ No newline at end of file
+A hash indicates the *next character* in the password if its [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) representation starts with *five zeroes*. If it does, the sixth character in the hash is the next character of the password.
+
+For example, if the Door ID is `abc`:
+
+
+ - The first index which produces a hash that starts with five zeroes is `3231929`, which we find by hashing `abc3231929`; the sixth character of the hash, and thus the first character of the password, is `1`.
+ - `5017308` produces the next interesting hash, which starts with `000008f82...`, so the second character of the password is `8`.
+ - The third time a hash starts with five zeroes is for `abc5278568`, discovering the character `f`.
+
+In this example, after continuing this search a total of eight times, the password is `18f47a30`.
+
+Given the actual Door ID, *what is the password*?
+
+
+## --- Part Two ---
+As the door slides open, you are presented with a second door that uses a slightly more inspired security mechanism. Clearly unimpressed by the last version (in what movie is the password decrypted *in order*?!), the Easter Bunny engineers have worked out [a better solution](https://www.youtube.com/watch?v=NHWjlCaIrQo&t=25).
+
+Instead of simply filling in the password from left to right, the hash now also indicates the *position* within the password to fill. You still look for hashes that begin with five zeroes; however, now, the *sixth* character represents the *position* (`0`-`7`), and the *seventh* character is the character to put in that position.
+
+A hash result of `000001f` means that `f` is the *second* character in the password. Use only the *first result* for each position, and ignore invalid positions.
+
+For example, if the Door ID is `abc`:
+
+
+ - The first interesting hash is from `abc3231929`, which produces `0000015...`; so, `5` goes in position `1`: `_5______`.
+ - In the previous method, `5017308` produced an interesting hash; however, it is ignored, because it specifies an invalid position (`8`).
+ - The second interesting hash is at index `5357525`, which produces `000004e...`; so, `e` goes in position `4`: `_5__e___`.
+
+You almost choke on your popcorn as the final character falls into place, producing the password `05ace8e3`.
+
+Given the actual Door ID and this new method, *what is the password*? Be extra proud of your solution if it uses a cinematic "decrypting" animation.
+
+
diff --git a/2016/Day05/input.in b/2016/Day05/input.in
index b5738f5d8..a9c42a42e 100644
Binary files a/2016/Day05/input.in and b/2016/Day05/input.in differ
diff --git a/2016/Day06/README.md b/2016/Day06/README.md
index d93688e72..fea2ad691 100644
--- a/2016/Day06/README.md
+++ b/2016/Day06/README.md
@@ -1,6 +1,42 @@
+original source: [https://adventofcode.com/2016/day/6](https://adventofcode.com/2016/day/6)
## --- Day 6: Signals and Noise ---
Something is jamming your communications with Santa. Fortunately, your signal is only partially jammed, and protocol in situations like this is to switch to a simple [repetition code](https://en.wikipedia.org/wiki/Repetition_code) to get the message through.
In this model, the same message is sent repeatedly. You've recorded the repeating message signal (your puzzle input), but the data seems quite corrupted - almost too badly to recover. *Almost*.
-Read the [full puzzle](https://adventofcode.com/2016/day/6).
\ No newline at end of file
+All you need to do is figure out which character is most frequent for each position. For example, suppose you had recorded the following messages:
+
+```
+eedadn
+drvtee
+eandsr
+raavrd
+atevrs
+tsrnev
+sdttsa
+rasrtv
+nssdts
+ntnada
+svetve
+tesnvt
+vntsnd
+vrdear
+dvrsen
+enarar
+```
+
+The most common character in the first column is `e`; in the second, `a`; in the third, `s`, and so on. Combining these characters returns the error-corrected message, `easter`.
+
+Given the recording in your puzzle input, *what is the error-corrected version* of the message being sent?
+
+
+## --- Part Two ---
+Of course, that *would* be the message - if you hadn't agreed to use a *modified repetition code* instead.
+
+In this modified code, the sender instead transmits what looks like random data, but for each character, the character they actually want to send is *slightly less likely* than the others. Even after signal-jamming noise, you can look at the letter distributions in each column and choose the *least common* letter to reconstruct the original message.
+
+In the above example, the least common character in the first column is `a`; in the second, `d`, and so on. Repeating this process for the remaining characters produces the original message, `advent`.
+
+Given the recording in your puzzle input and this new decoding methodology, *what is the original message* that Santa is trying to send?
+
+
diff --git a/2016/Day06/input.in b/2016/Day06/input.in
index 9873339f3..f2d83a79f 100644
Binary files a/2016/Day06/input.in and b/2016/Day06/input.in differ
diff --git a/2016/Day07/README.md b/2016/Day07/README.md
index 089886307..8dec7d175 100644
--- a/2016/Day07/README.md
+++ b/2016/Day07/README.md
@@ -1,6 +1,33 @@
+original source: [https://adventofcode.com/2016/day/7](https://adventofcode.com/2016/day/7)
## --- Day 7: Internet Protocol Version 7 ---
While snooping around the local network of EBHQ, you compile a list of [IP addresses](https://en.wikipedia.org/wiki/IP_address) (they're IPv7, of course; [IPv6](https://en.wikipedia.org/wiki/IPv6) is much too limited). You'd like to figure out which IPs support *TLS* (transport-layer snooping).
An IP supports TLS if it has an Autonomous Bridge Bypass Annotation, or *ABBA*. An ABBA is any four-character sequence which consists of a pair of two different characters followed by the reverse of that pair, such as `xyyx` or `abba`. However, the IP also must not have an ABBA within any hypernet sequences, which are contained by *square brackets*.
-Read the [full puzzle](https://adventofcode.com/2016/day/7).
\ No newline at end of file
+For example:
+
+
+ - `abba[mnop]qrst` supports TLS (`abba` outside square brackets).
+ - `abcd[bddb]xyyx` does *not* support TLS (`bddb` is within square brackets, even though `xyyx` is outside square brackets).
+ - `aaaa[qwer]tyui` does *not* support TLS (`aaaa` is invalid; the interior characters must be different).
+ - `ioxxoj[asdfgh]zxcvbn` supports TLS (`oxxo` is outside square brackets, even though it's within a larger string).
+
+*How many IPs* in your puzzle input support TLS?
+
+
+## --- Part Two ---
+You would also like to know which IPs support *SSL* (super-secret listening).
+
+An IP supports SSL if it has an Area-Broadcast Accessor, or *ABA*, anywhere in the supernet sequences (outside any square bracketed sections), and a corresponding Byte Allocation Block, or *BAB*, anywhere in the hypernet sequences. An ABA is any three-character sequence which consists of the same character twice with a different character between them, such as `xyx` or `aba`. A corresponding BAB is the same characters but in reversed positions: `yxy` and `bab`, respectively.
+
+For example:
+
+
+ - `aba[bab]xyz` supports SSL (`aba` outside square brackets with corresponding `bab` within square brackets).
+ - `xyx[xyx]xyx` does *not* support SSL (`xyx`, but no corresponding `yxy`).
+ - `aaa[kek]eke` supports SSL (`eke` in supernet with corresponding `kek` in hypernet; the `aaa` sequence is not related, because the interior character must be different).
+ - `zazbz[bzb]cdb` supports SSL (`zaz` has no corresponding `aza`, but `zbz` has a corresponding `bzb`, even though `zaz` and `zbz` overlap).
+
+*How many IPs* in your puzzle input support SSL?
+
+
diff --git a/2016/Day07/input.in b/2016/Day07/input.in
index ec26a4f10..d50f36cdd 100644
Binary files a/2016/Day07/input.in and b/2016/Day07/input.in differ
diff --git a/2016/Day08/README.md b/2016/Day08/README.md
index 6f22b40ab..50c12f772 100644
--- a/2016/Day08/README.md
+++ b/2016/Day08/README.md
@@ -1,6 +1,58 @@
+original source: [https://adventofcode.com/2016/day/8](https://adventofcode.com/2016/day/8)
## --- Day 8: Two-Factor Authentication ---
You come across a door implementing what you can only assume is an implementation of [two-factor authentication](https://en.wikipedia.org/wiki/Multi-factor_authentication) after a long game of [requirements](https://en.wikipedia.org/wiki/Requirement) [telephone](https://en.wikipedia.org/wiki/Chinese_whispers).
To get past the door, you first swipe a keycard (no problem; there was one on a nearby desk). Then, it displays a code on a [little screen](https://www.google.com/search?q=tiny+lcd&tbm=isch), and you type that code on a keypad. Then, presumably, the door unlocks.
-Read the [full puzzle](https://adventofcode.com/2016/day/8).
\ No newline at end of file
+Unfortunately, the screen has been smashed. After a few minutes, you've taken everything apart and figured out how it works. Now you just have to work out what the screen *would* have displayed.
+
+The magnetic strip on the card you swiped encodes a series of instructions for the screen; these instructions are your puzzle input. The screen is *`50` pixels wide and `6` pixels tall*, all of which start *off*, and is capable of three somewhat peculiar operations:
+
+
+ - `rect AxB` turns *on* all of the pixels in a rectangle at the top-left of the screen which is `A` wide and `B` tall.
+ - `rotate row y=A by B` shifts all of the pixels in row `A` (0 is the top row) *right* by `B` pixels. Pixels that would fall off the right end appear at the left end of the row.
+ - `rotate column x=A by B` shifts all of the pixels in column `A` (0 is the left column) *down* by `B` pixels. Pixels that would fall off the bottom appear at the top of the column.
+
+For example, here is a simple sequence on a smaller screen:
+
+
+ - `rect 3x2` creates a small rectangle in the top-left corner:
+```
+###....
+###....
+.......
+```
+
+ - `rotate column x=1 by 1` rotates the second column down by one pixel:
+```
+#.#....
+###....
+.#.....
+```
+
+ - `rotate row y=0 by 4` rotates the top row right by four pixels:
+```
+....#.#
+###....
+.#.....
+```
+
+ - `rotate column x=1 by 1` again rotates the second column down by one pixel, causing the bottom pixel to wrap back to the top:
+```
+.#..#.#
+#.#....
+.#.....
+```
+
+
+As you can see, this display technology is extremely powerful, and will soon dominate the tiny-code-displaying-screen market. That's what the advertisement on the back of the display tries to convince you, anyway.
+
+There seems to be an intermediate check of the voltage used by the display: after you swipe your card, if the screen did work, *how many pixels should be lit?*
+
+
+## --- Part Two ---
+You notice that the screen is only capable of displaying capital letters; in the font it uses, each letter is `5` pixels wide and `6` tall.
+
+After you swipe your card, *what code is the screen trying to display?*
+
+
diff --git a/2016/Day08/input.in b/2016/Day08/input.in
index 09aee8aee..cdc78427c 100644
Binary files a/2016/Day08/input.in and b/2016/Day08/input.in differ
diff --git a/2016/Day09/README.md b/2016/Day09/README.md
index 594534d99..2487c3213 100644
--- a/2016/Day09/README.md
+++ b/2016/Day09/README.md
@@ -1,6 +1,39 @@
+original source: [https://adventofcode.com/2016/day/9](https://adventofcode.com/2016/day/9)
## --- Day 9: Explosives in Cyberspace ---
Wandering around a secure area, you come across a datalink port to a new part of the network. After briefly scanning it for interesting files, you find one file in particular that catches your attention. It's compressed with an experimental format, but fortunately, the documentation for the format is nearby.
The format compresses a sequence of characters. Whitespace is ignored. To indicate that some sequence should be repeated, a marker is added to the file, like `(10x2)`. To decompress this marker, take the subsequent `10` characters and repeat them `2` times. Then, continue reading the file *after* the repeated data. The marker itself is not included in the decompressed output.
-Read the [full puzzle](https://adventofcode.com/2016/day/9).
\ No newline at end of file
+If parentheses or other characters appear within the data referenced by a marker, that's okay - treat it like normal data, not a marker, and then resume looking for markers after the decompressed section.
+
+For example:
+
+
+ - `ADVENT` contains no markers and decompresses to itself with no changes, resulting in a decompressed length of `6`.
+ - `A(1x5)BC` repeats only the `B` a total of `5` times, becoming `ABBBBBC` for a decompressed length of `7`.
+ - `(3x3)XYZ` becomes `XYZXYZXYZ` for a decompressed length of `9`.
+ - `A(2x2)BCD(2x2)EFG` doubles the `BC` and `EF`, becoming `ABCBCDEFEFG` for a decompressed length of `11`.
+ - `(6x1)(1x3)A` simply becomes `(1x3)A` - the `(1x3)` looks like a marker, but because it's within a data section of another marker, it is not treated any differently from the `A` that comes after it. It has a decompressed length of `6`.
+ - `X(8x2)(3x3)ABCY` becomes `X(3x3)ABC(3x3)ABCY` (for a decompressed length of `18`), because the decompressed data from the `(8x2)` marker (the `(3x3)ABC`) is skipped and not processed further.
+
+What is the *decompressed length* of the file (your puzzle input)? Don't count whitespace.
+
+
+## --- Part Two ---
+Apparently, the file actually uses *version two* of the format.
+
+In version two, the only difference is that markers within decompressed data *are* decompressed. This, the documentation explains, provides much more substantial compression capabilities, allowing many-gigabyte files to be stored in only a few kilobytes.
+
+For example:
+
+
+ - `(3x3)XYZ` still becomes `XYZXYZXYZ`, as the decompressed section contains no markers.
+ - `X(8x2)(3x3)ABCY` becomes `XABCABCABCABCABCABCY`, because the decompressed data from the `(8x2)` marker is then further decompressed, thus triggering the `(3x3)` marker twice for a total of six `ABC` sequences.
+ - `(27x12)(20x12)(13x14)(7x10)(1x12)A` decompresses into a string of `A` repeated `241920` times.
+ - `(25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN` becomes `445` characters long.
+
+Unfortunately, the computer you brought probably doesn't have enough memory to actually decompress the file; you'll have to *come up with another way* to get its decompressed length.
+
+What is the *decompressed length* of the file using this improved format?
+
+
diff --git a/2016/Day09/input.in b/2016/Day09/input.in
index 84798735c..3ccde7816 100644
Binary files a/2016/Day09/input.in and b/2016/Day09/input.in differ
diff --git a/2016/Day10/README.md b/2016/Day10/README.md
index d03015e16..d0a9854cd 100644
--- a/2016/Day10/README.md
+++ b/2016/Day10/README.md
@@ -1,6 +1,36 @@
+original source: [https://adventofcode.com/2016/day/10](https://adventofcode.com/2016/day/10)
## --- Day 10: Balance Bots ---
You come upon a factory in which many robots are [zooming around](https://www.youtube.com/watch?v=JnkMyfQ5YfY&t=40) handing small microchips to each other.
Upon closer examination, you notice that each bot only proceeds when it has *two* microchips, and once it does, it gives each one to a different bot or puts it in a marked "output" bin. Sometimes, bots take microchips from "input" bins, too.
-Read the [full puzzle](https://adventofcode.com/2016/day/10).
\ No newline at end of file
+Inspecting one of the microchips, it seems like they each contain a single number; the bots must use some logic to decide what to do with each chip. You access the local control computer and download the bots' instructions (your puzzle input).
+
+Some of the instructions specify that a specific-valued microchip should be given to a specific bot; the rest of the instructions indicate what a given bot should do with its *lower-value* or *higher-value* chip.
+
+For example, consider the following instructions:
+
+```
+value 5 goes to bot 2
+bot 2 gives low to bot 1 and high to bot 0
+value 3 goes to bot 1
+bot 1 gives low to output 1 and high to bot 0
+bot 0 gives low to output 2 and high to output 0
+value 2 goes to bot 2
+```
+
+
+ - Initially, bot `1` starts with a value-`3` chip, and bot `2` starts with a value-`2` chip and a value-`5` chip.
+ - Because bot `2` has two microchips, it gives its lower one (`2`) to bot `1` and its higher one (`5`) to bot `0`.
+ - Then, bot `1` has two microchips; it puts the value-`2` chip in output `1` and gives the value-`3` chip to bot `0`.
+ - Finally, bot `0` has two microchips; it puts the `3` in output `2` and the `5` in output `0`.
+
+In the end, output bin `0` contains a value-`5` microchip, output bin `1` contains a value-`2` microchip, and output bin `2` contains a value-`3` microchip. In this configuration, bot number *`2`* is responsible for comparing value-`5` microchips with value-`2` microchips.
+
+Based on your instructions, *what is the number of the bot* that is responsible for comparing value-`61` microchips with value-`17` microchips?
+
+
+## --- Part Two ---
+What do you get if you *multiply together the values* of one chip in each of outputs `0`, `1`, and `2`?
+
+
diff --git a/2016/Day10/input.in b/2016/Day10/input.in
index 4c8c4256a..ca6cead76 100644
Binary files a/2016/Day10/input.in and b/2016/Day10/input.in differ
diff --git a/2016/Day11/README.md b/2016/Day11/README.md
index eaac04c4a..d25f60209 100644
--- a/2016/Day11/README.md
+++ b/2016/Day11/README.md
@@ -1,6 +1,149 @@
+original source: [https://adventofcode.com/2016/day/11](https://adventofcode.com/2016/day/11)
## --- Day 11: Radioisotope Thermoelectric Generators ---
You come upon a column of four floors that have been entirely sealed off from the rest of the building except for a small dedicated lobby. There are some radiation warnings and a big sign which reads "Radioisotope Testing Facility".
According to the project status board, this facility is currently being used to experiment with [Radioisotope Thermoelectric Generators](https://en.wikipedia.org/wiki/Radioisotope_thermoelectric_generator) (RTGs, or simply "generators") that are designed to be paired with specially-constructed microchips. Basically, an RTG is a highly radioactive rock that generates electricity through heat.
-Read the [full puzzle](https://adventofcode.com/2016/day/11).
\ No newline at end of file
+The experimental RTGs have poor radiation containment, so they're dangerously radioactive. The chips are prototypes and don't have normal radiation shielding, but they do have the ability to *generate an electromagnetic radiation shield when powered*. Unfortunately, they can *only* be powered by their corresponding RTG. An RTG powering a microchip is still dangerous to other microchips.
+
+In other words, if a chip is ever left in the same area as another RTG, and it's not connected to its own RTG, the chip will be *fried*. Therefore, it is assumed that you will follow procedure and keep chips connected to their corresponding RTG when they're in the same room, and away from other RTGs otherwise.
+
+These microchips sound very interesting and useful to your current activities, and you'd like to try to retrieve them. The fourth floor of the facility has an assembling machine which can make a self-contained, shielded computer for you to take with you - that is, if you can bring it all of the RTGs and microchips.
+
+Within the radiation-shielded part of the facility (in which it's safe to have these pre-assembly RTGs), there is an elevator that can move between the four floors. Its capacity rating means it can carry at most yourself and two RTGs or microchips in any combination. (They're rigged to some heavy diagnostic equipment - the assembling machine will detach it for you.) As a security measure, the elevator will only function if it contains at least one RTG or microchip. The elevator always stops on each floor to recharge, and this takes long enough that the items within it and the items on that floor can irradiate each other. (You can prevent this if a Microchip and its Generator end up on the same floor in this way, as they can be connected while the elevator is recharging.)
+
+You make some notes of the locations of each component of interest (your puzzle input). Before you don a hazmat suit and start moving things around, you'd like to have an idea of what you need to do.
+
+When you enter the containment area, you and the elevator will start on the first floor.
+
+For example, suppose the isolated area has the following arrangement:
+
+```
+The first floor contains a hydrogen-compatible microchip and a lithium-compatible microchip.
+The second floor contains a hydrogen generator.
+The third floor contains a lithium generator.
+The fourth floor contains nothing relevant.
+```
+
+As a diagram (`F#` for a Floor number, `E` for Elevator, `H` for Hydrogen, `L` for Lithium, `M` for Microchip, and `G` for Generator), the initial state looks like this:
+
+```
+F4 . . . . .
+F3 . . . LG .
+F2 . HG . . .
+F1 E . HM . LM
+```
+
+Then, to get everything up to the assembling machine on the fourth floor, the following steps could be taken:
+
+
+ - Bring the Hydrogen-compatible Microchip to the second floor, which is safe because it can get power from the Hydrogen Generator:
+```
+F4 . . . . .
+F3 . . . LG .
+F2 E HG HM . .
+F1 . . . . LM
+```
+
+ - Bring both Hydrogen-related items to the third floor, which is safe because the Hydrogen-compatible microchip is getting power from its generator:
+```
+F4 . . . . .
+F3 E HG HM LG .
+F2 . . . . .
+F1 . . . . LM
+```
+
+ - Leave the Hydrogen Generator on floor three, but bring the Hydrogen-compatible Microchip back down with you so you can still use the elevator:
+```
+F4 . . . . .
+F3 . HG . LG .
+F2 E . HM . .
+F1 . . . . LM
+```
+
+ - At the first floor, grab the Lithium-compatible Microchip, which is safe because Microchips don't affect each other:
+```
+F4 . . . . .
+F3 . HG . LG .
+F2 . . . . .
+F1 E . HM . LM
+```
+
+ - Bring both Microchips up one floor, where there is nothing to fry them:
+```
+F4 . . . . .
+F3 . HG . LG .
+F2 E . HM . LM
+F1 . . . . .
+```
+
+ - Bring both Microchips up again to floor three, where they can be temporarily connected to their corresponding generators while the elevator recharges, preventing either of them from being fried:
+```
+F4 . . . . .
+F3 E HG HM LG LM
+F2 . . . . .
+F1 . . . . .
+```
+
+ - Bring both Microchips to the fourth floor:
+```
+F4 E . HM . LM
+F3 . HG . LG .
+F2 . . . . .
+F1 . . . . .
+```
+
+ - Leave the Lithium-compatible microchip on the fourth floor, but bring the Hydrogen-compatible one so you can still use the elevator; this is safe because although the Lithium Generator is on the destination floor, you can connect Hydrogen-compatible microchip to the Hydrogen Generator there:
+```
+F4 . . . . LM
+F3 E HG HM LG .
+F2 . . . . .
+F1 . . . . .
+```
+
+ - Bring both Generators up to the fourth floor, which is safe because you can connect the Lithium-compatible Microchip to the Lithium Generator upon arrival:
+```
+F4 E HG . LG LM
+F3 . . HM . .
+F2 . . . . .
+F1 . . . . .
+```
+
+ - Bring the Lithium Microchip with you to the third floor so you can use the elevator:
+```
+F4 . HG . LG .
+F3 E . HM . LM
+F2 . . . . .
+F1 . . . . .
+```
+
+ - Bring both Microchips to the fourth floor:
+```
+F4 E HG HM LG LM
+F3 . . . . .
+F2 . . . . .
+F1 . . . . .
+```
+
+
+In this arrangement, it takes `11` steps to collect all of the objects at the fourth floor for assembly. (Each elevator stop counts as one step, even if nothing is added to or removed from it.)
+
+In your situation, what is the *minimum number of steps* required to bring all of the objects to the fourth floor?
+
+
+## --- Part Two ---
+You step into the cleanroom separating the lobby from the isolated area and put on the hazmat suit.
+
+Upon entering the isolated containment area, however, you notice some extra parts on the first floor that weren't listed on the record outside:
+
+
+ - An elerium generator.
+ - An elerium-compatible microchip.
+ - A dilithium generator.
+ - A dilithium-compatible microchip.
+
+These work just like the other generators and microchips. You'll have to get them up to assembly as well.
+
+What is the *minimum number of steps* required to bring all of the objects, including these four new ones, to the fourth floor?
+
+
diff --git a/2016/Day11/input.in b/2016/Day11/input.in
index 70310eded..2c3c55528 100644
Binary files a/2016/Day11/input.in and b/2016/Day11/input.in differ
diff --git a/2016/Day12/README.md b/2016/Day12/README.md
index 8783e7dc1..9434274f4 100644
--- a/2016/Day12/README.md
+++ b/2016/Day12/README.md
@@ -1,6 +1,42 @@
+original source: [https://adventofcode.com/2016/day/12](https://adventofcode.com/2016/day/12)
## --- Day 12: Leonardo's Monorail ---
You finally reach the top floor of this building: a garden with a slanted glass ceiling. Looks like there are no more stars to be had.
While sitting on a nearby bench amidst some [tiger lilies](https://www.google.com/search?q=tiger+lilies&tbm=isch), you manage to decrypt some of the files you extracted from the servers downstairs.
-Read the [full puzzle](https://adventofcode.com/2016/day/12).
\ No newline at end of file
+According to these documents, Easter Bunny HQ isn't just this building - it's a collection of buildings in the nearby area. They're all connected by a local monorail, and there's another building not far from here! Unfortunately, being night, the monorail is currently not operating.
+
+You remotely connect to the monorail control systems and discover that the boot sequence expects a password. The password-checking logic (your puzzle input) is easy to extract, but the code it uses is strange: it's assembunny code designed for the [new computer](11) you just assembled. You'll have to execute the code and get the password.
+
+The assembunny code you've extracted operates on four [registers](https://en.wikipedia.org/wiki/Processor_register) (`a`, `b`, `c`, and `d`) that start at `0` and can hold any [integer](https://en.wikipedia.org/wiki/Integer). However, it seems to make use of only a few [instructions](https://en.wikipedia.org/wiki/Instruction_set):
+
+
+ - `cpy x y` *copies* `x` (either an integer or the *value* of a register) into register `y`.
+ - `inc x` *increases* the value of register `x` by one.
+ - `dec x` *decreases* the value of register `x` by one.
+ - `jnz x y` *jumps* to an instruction `y` away (positive means forward; negative means backward), but only if `x` is *not zero*.
+
+The `jnz` instruction moves relative to itself: an offset of `-1` would continue at the previous instruction, while an offset of `2` would *skip over* the next instruction.
+
+For example:
+
+```
+cpy 41 a
+inc a
+inc a
+dec a
+jnz a 2
+dec a
+```
+
+The above code would set register `a` to `41`, increase its value by `2`, decrease its value by `1`, and then skip the last `dec a` (because `a` is not zero, so the `jnz a 2` skips it), leaving register `a` at `42`. When you move past the last instruction, the program halts.
+
+After executing the assembunny code in your puzzle input, *what value is left in register `a`?*
+
+
+## --- Part Two ---
+As you head down the fire escape to the monorail, you notice it didn't start; register `c` needs to be initialized to the position of the ignition key.
+
+If you instead *initialize register `c` to be `1`*, what value is now left in register `a`?
+
+
diff --git a/2016/Day12/input.in b/2016/Day12/input.in
index e4a51aade..b74bbbccf 100644
Binary files a/2016/Day12/input.in and b/2016/Day12/input.in differ
diff --git a/2016/Day13/README.md b/2016/Day13/README.md
index 37cfc68bf..0c425b69d 100644
--- a/2016/Day13/README.md
+++ b/2016/Day13/README.md
@@ -1,6 +1,53 @@
+original source: [https://adventofcode.com/2016/day/13](https://adventofcode.com/2016/day/13)
## --- Day 13: A Maze of Twisty Little Cubicles ---
You arrive at the first floor of this new building to discover a much less welcoming environment than the shiny atrium of the last one. Instead, you are in a maze of twisty little cubicles, all alike.
Every location in this area is addressed by a pair of non-negative integers (`x,y`). Each such coordinate is either a wall or an open space. You can't move diagonally. The cube maze starts at `0,0` and seems to extend infinitely toward *positive* `x` and `y`; negative values are *invalid*, as they represent a location outside the building. You are in a small waiting area at `1,1`.
-Read the [full puzzle](https://adventofcode.com/2016/day/13).
\ No newline at end of file
+While it seems chaotic, a nearby morale-boosting poster explains, the layout is actually quite logical. You can determine whether a given `x,y` coordinate will be a wall or an open space using a simple system:
+
+
+ - Find `x*x + 3*x + 2*x*y + y + y*y`.
+ - Add the office designer's favorite number (your puzzle input).
+ - Find the [binary representation](https://en.wikipedia.org/wiki/Binary_number) of that sum; count the *number* of [bits](https://en.wikipedia.org/wiki/Bit) that are `1`.
+
+ - If the number of bits that are `1` is *even*, it's an *open space*.
+ - If the number of bits that are `1` is *odd*, it's a *wall*.
+
+
+
+For example, if the office designer's favorite number were `10`, drawing walls as `#` and open spaces as `.`, the corner of the building containing `0,0` would look like this:
+
+```
+ 0123456789
+0 .#.####.##
+1 ..#..#...#
+2 #....##...
+3 ###.#.###.
+4 .##..#..#.
+5 ..##....#.
+6 #...##.###
+```
+
+Now, suppose you wanted to reach `7,4`. The shortest route you could take is marked as `O`:
+
+```
+ 0123456789
+0 .#.####.##
+1 .O#..#...#
+2 #OOO.##...
+3 ###O#.###.
+4 .##OO#OO#.
+5 ..##OOO.#.
+6 #...##.###
+```
+
+Thus, reaching `7,4` would take a minimum of `11` steps (starting from your current location, `1,1`).
+
+What is the *fewest number of steps required* for you to reach `31,39`?
+
+
+## --- Part Two ---
+*How many locations* (distinct `x,y` coordinates, including your starting location) can you reach in at most `50` steps?
+
+
diff --git a/2016/Day13/input.in b/2016/Day13/input.in
index c12c644c8..dda50873c 100644
Binary files a/2016/Day13/input.in and b/2016/Day13/input.in differ
diff --git a/2016/Day14/README.md b/2016/Day14/README.md
index 5d0c9057c..171a74127 100644
--- a/2016/Day14/README.md
+++ b/2016/Day14/README.md
@@ -1,6 +1,55 @@
+original source: [https://adventofcode.com/2016/day/14](https://adventofcode.com/2016/day/14)
## --- Day 14: One-Time Pad ---
In order to communicate securely with Santa while you're on this mission, you've been using a [one-time pad](https://en.wikipedia.org/wiki/One-time_pad) that you [generate](https://en.wikipedia.org/wiki/Security_through_obscurity) using a pre-agreed algorithm. Unfortunately, you've run out of keys in your one-time pad, and so you need to generate some more.
To generate keys, you first get a stream of random data by taking the [MD5](https://en.wikipedia.org/wiki/MD5) of a pre-arranged [salt](https://en.wikipedia.org/wiki/Salt_(cryptography)) (your puzzle input) and an increasing integer index (starting with `0`, and represented in decimal); the resulting MD5 hash should be represented as a string of *lowercase* hexadecimal digits.
-Read the [full puzzle](https://adventofcode.com/2016/day/14).
\ No newline at end of file
+However, not all of these MD5 hashes are *keys*, and you need `64` new keys for your one-time pad. A hash is a key *only if*:
+
+
+ - It contains *three* of the same character in a row, like `777`. Only consider the first such triplet in a hash.
+ - One of the next `1000` hashes in the stream contains that same character *five* times in a row, like `77777`.
+
+Considering future hashes for five-of-a-kind sequences does not cause those hashes to be skipped; instead, regardless of whether the current hash is a key, always resume testing for keys starting with the very next hash.
+
+For example, if the pre-arranged salt is `abc`:
+
+
+ - The first index which produces a triple is `18`, because the MD5 hash of `abc18` contains `...cc38887a5...`. However, index `18` does not count as a key for your one-time pad, because none of the next thousand hashes (index `19` through index `1018`) contain `88888`.
+ - The next index which produces a triple is `39`; the hash of `abc39` contains `eee`. It is also the first key: one of the next thousand hashes (the one at index 816) contains `eeeee`.
+ - None of the next six triples are keys, but the one after that, at index `92`, is: it contains `999` and index `200` contains `99999`.
+ - Eventually, index `22728` meets all of the criteria to generate the `64`th key.
+
+So, using our example salt of `abc`, index `22728` produces the `64`th key.
+
+Given the actual salt in your puzzle input, *what index* produces your `64`th one-time pad key?
+
+
+## --- Part Two ---
+Of course, in order to make this process [even more secure](https://en.wikipedia.org/wiki/MD5#Security), you've also implemented [key stretching](https://en.wikipedia.org/wiki/Key_stretching).
+
+Key stretching forces attackers to spend more time generating hashes. Unfortunately, it forces everyone else to spend more time, too.
+
+To implement key stretching, whenever you generate a hash, before you use it, you first find the MD5 hash of that hash, then the MD5 hash of *that* hash, and so on, a total of *`2016` additional hashings*. Always use lowercase hexadecimal representations of hashes.
+
+For example, to find the stretched hash for index `0` and salt `abc`:
+
+
+ - Find the MD5 hash of `abc0`: `577571be4de9dcce85a041ba0410f29f`.
+ - Then, find the MD5 hash of that hash: `eec80a0c92dc8a0777c619d9bb51e910`.
+ - Then, find the MD5 hash of that hash: `16062ce768787384c81fe17a7a60c7e3`.
+ - ...repeat many times...
+ - Then, find the MD5 hash of that hash: `a107ff634856bb300138cac6568c0f24`.
+
+So, the stretched hash for index `0` in this situation is `a107ff...`. In the end, you find the original hash (one use of MD5), then find the hash-of-the-previous-hash `2016` times, for a total of `2017` uses of MD5.
+
+The rest of the process remains the same, but now the keys are entirely different. Again for salt `abc`:
+
+
+ - The first triple (`222`, at index `5`) has no matching `22222` in the next thousand hashes.
+ - The second triple (`eee`, at index `10`) hash a matching `eeeee` at index `89`, and so it is the first key.
+ - Eventually, index `22551` produces the `64`th key (triple `fff` with matching `fffff` at index `22859`.
+
+Given the actual salt in your puzzle input and using `2016` extra MD5 calls of key stretching, *what index* now produces your `64`th one-time pad key?
+
+
diff --git a/2016/Day14/input.in b/2016/Day14/input.in
index fa1a5b352..f7f11ad90 100644
Binary files a/2016/Day14/input.in and b/2016/Day14/input.in differ
diff --git a/2016/Day15/README.md b/2016/Day15/README.md
index e0930ef41..7bcd0d064 100644
--- a/2016/Day15/README.md
+++ b/2016/Day15/README.md
@@ -1,6 +1,37 @@
+original source: [https://adventofcode.com/2016/day/15](https://adventofcode.com/2016/day/15)
## --- Day 15: Timing is Everything ---
The halls open into an interior plaza containing a large kinetic sculpture. The sculpture is in a sealed enclosure and seems to involve a set of identical spherical capsules that are carried to the top and allowed to [bounce through the maze](https://youtu.be/IxDoO9oODOk?t=177) of spinning pieces.
Part of the sculpture is even interactive! When a button is pressed, a capsule is dropped and tries to fall through slots in a set of rotating discs to finally go through a little hole at the bottom and come out of the sculpture. If any of the slots aren't aligned with the capsule as it passes, the capsule bounces off the disc and soars away. You feel compelled to get one of those capsules.
-Read the [full puzzle](https://adventofcode.com/2016/day/15).
\ No newline at end of file
+The discs pause their motion each second and come in different sizes; they seem to each have a fixed number of positions at which they stop. You decide to call the position with the slot 0
, and count up for each position it reaches next.
+
+Furthermore, the discs are spaced out so that after you push the button, one second elapses before the first disc is reached, and one second elapses as the capsule passes from one disc to the one below it. So, if you push the button at time=100
, then the capsule reaches the top disc at time=101
, the second disc at time=102
, the third disc at time=103
, and so on.
+
+The button will only drop a capsule at an integer time - no fractional seconds allowed.
+
+For example, at time=0
, suppose you see the following arrangement:
+
+
+Disc #1 has 5 positions; at time=0, it is at position 4.
+Disc #2 has 2 positions; at time=0, it is at position 1.
+
+
+
+If you press the button exactly at time=0
, the capsule would start to fall; it would reach the first disc at time=1
. Since the first disc was at position 4
at time=0
, by time=1
it has ticked one position forward. As a five-position disc, the next position is 0
, and the capsule falls through the slot.
+
+Then, at time=2
, the capsule reaches the second disc. The second disc has ticked forward two positions at this point: it started at position 1
, then continued to position 0
, and finally ended up at position 1
again. Because there's only a slot at position 0
, the capsule bounces away.
+
+If, however, you wait until time=5
to push the button, then when the capsule reaches each disc, the first disc will have ticked forward 5+1 = 6
times (to position 0
), and the second disc will have ticked forward 5+2 = 7
times (also to position 0
). In this case, the capsule would fall through the discs and come out of the machine.
+
+However, your situation has more than two discs; you've noted their positions in your puzzle input. What is the first time you can press the button to get a capsule?
+
+
+## --- Part Two ---
+After getting the first capsule (it contained a star! what great fortune!), the machine detects your success and begins to rearrange itself.
+
+When it's done, the discs are back in their original configuration as if it were time=0
again, but a new disc with 11
positions and starting at position 0
has appeared exactly one second below the previously-bottom disc.
+
+With this new disc, and counting again starting from time=0
with the configuration in your puzzle input, what is the first time you can press the button to get another capsule?
+
+
diff --git a/2016/Day15/input.in b/2016/Day15/input.in
index d98a91e50..c5d50198a 100644
Binary files a/2016/Day15/input.in and b/2016/Day15/input.in differ
diff --git a/2016/Day16/README.md b/2016/Day16/README.md
index e5a6546ce..ff8b06be0 100644
--- a/2016/Day16/README.md
+++ b/2016/Day16/README.md
@@ -1,6 +1,59 @@
+original source: [https://adventofcode.com/2016/day/16](https://adventofcode.com/2016/day/16)
## --- Day 16: Dragon Checksum ---
You're done scanning this part of the network, but you've left traces of your presence. You need to overwrite some disks with random-looking data to cover your tracks and update the local security system with a new checksum for those disks.
For the data to not be suspicious, it needs to have certain properties; purely random data will be detected as tampering. To generate appropriate random data, you'll need to use a modified [dragon curve](https://en.wikipedia.org/wiki/Dragon_curve).
-Read the [full puzzle](https://adventofcode.com/2016/day/16).
\ No newline at end of file
+Start with an appropriate initial state (your puzzle input). Then, so long as you don't have enough data yet to fill the disk, repeat the following steps:
+
+
+ - Call the data you have at this point "a".
+ - Make a copy of "a"; call this copy "b".
+ - Reverse the order of the characters in "b".
+ - In "b", replace all instances of `0` with `1` and all `1`s with `0`.
+ - The resulting data is "a", then a single `0`, then "b".
+
+For example, after a single step of this process,
+
+
+ - `1` becomes `100`.
+ - `0` becomes `001`.
+ - `11111` becomes `11111000000`.
+ - `111100001010` becomes `1111000010100101011110000`.
+
+Repeat these steps until you have enough data to fill the desired disk.
+
+Once the data has been generated, you also need to create a checksum of that data. Calculate the checksum *only* for the data that fits on the disk, even if you generated more data than that in the previous step.
+
+The checksum for some given data is created by considering each non-overlapping *pair* of characters in the input data. If the two characters match (`00` or `11`), the next checksum character is a `1`. If the characters do not match (`01` or `10`), the next checksum character is a `0`. This should produce a new string which is exactly half as long as the original. If the length of the checksum is *even*, repeat the process until you end up with a checksum with an *odd* length.
+
+For example, suppose we want to fill a disk of length `12`, and when we finally generate a string of at least length `12`, the first `12` characters are `110010110100`. To generate its checksum:
+
+
+ - Consider each pair: `11`, `00`, `10`, `11`, `01`, `00`.
+ - These are same, same, different, same, different, same, producing `110101`.
+ - The resulting string has length `6`, which is *even*, so we repeat the process.
+ - The pairs are `11` (same), `01` (different), `01` (different).
+ - This produces the checksum `100`, which has an *odd* length, so we stop.
+
+Therefore, the checksum for `110010110100` is `100`.
+
+Combining all of these steps together, suppose you want to fill a disk of length `20` using an initial state of `10000`:
+
+
+ - Because `10000` is too short, we first use the modified dragon curve to make it longer.
+ - After one round, it becomes `10000011110` (`11` characters), still too short.
+ - After two rounds, it becomes `10000011110010000111110` (`23` characters), which is enough.
+ - Since we only need `20`, but we have `23`, we get rid of all but the first `20` characters: `10000011110010000111`.
+ - Next, we start calculating the checksum; after one round, we have `0111110101`, which `10` characters long (*even*), so we continue.
+ - After two rounds, we have `01100`, which is `5` characters long (*odd*), so we are done.
+
+In this example, the correct checksum would therefore be `01100`.
+
+The first disk you have to fill has length `272`. Using the initial state in your puzzle input, *what is the correct checksum*?
+
+
+## --- Part Two ---
+The second disk you have to fill has length `35651584`. Again using the initial state in your puzzle input, *what is the correct checksum* for this disk?
+
+
diff --git a/2016/Day16/input.in b/2016/Day16/input.in
index 6d0d69381..f8e6224bc 100644
Binary files a/2016/Day16/input.in and b/2016/Day16/input.in differ
diff --git a/2016/Day17/README.md b/2016/Day17/README.md
index 7cc530e50..cae6b5e24 100644
--- a/2016/Day17/README.md
+++ b/2016/Day17/README.md
@@ -1,3 +1,4 @@
+original source: [https://adventofcode.com/2016/day/17](https://adventofcode.com/2016/day/17)
## --- Day 17: Two Steps Forward ---
You're trying to access a secure vault protected by a `4x4` grid of small rooms connected by doors. You start in the top-left room (marked `S`), and you can access the vault (marked `V`) once you reach the bottom-right room:
@@ -13,4 +14,42 @@ You're trying to access a secure vault protected by a `4x4` grid of small rooms
####### V
```
-Read the [full puzzle](https://adventofcode.com/2016/day/17).
\ No newline at end of file
+Fixed walls are marked with `#`, and doors are marked with `-` or `|`.
+
+The doors in your *current room* are either open or closed (and locked) based on the hexadecimal [MD5](https://en.wikipedia.org/wiki/MD5) hash of a passcode (your puzzle input) followed by a sequence of uppercase characters representing the *path you have taken so far* (`U` for up, `D` for down, `L` for left, and `R` for right).
+
+Only the first four characters of the hash are used; they represent, respectively, the doors *up, down, left, and right* from your current position. Any `b`, `c`, `d`, `e`, or `f` means that the corresponding door is *open*; any other character (any number or `a`) means that the corresponding door is *closed and locked*.
+
+To access the vault, all you need to do is reach the bottom-right room; reaching this room opens the vault and all doors in the maze.
+
+For example, suppose the passcode is `hijkl`. Initially, you have taken no steps, and so your path is empty: you simply find the MD5 hash of `hijkl` alone. The first four characters of this hash are `ced9`, which indicate that up is open (`c`), down is open (`e`), left is open (`d`), and right is closed and locked (`9`). Because you start in the top-left corner, there are no "up" or "left" doors to be open, so your only choice is *down*.
+
+Next, having gone only one step (down, or `D`), you find the hash of `hijkl*D*`. This produces `f2bc`, which indicates that you can go back up, left (but that's a wall), or right. Going right means hashing `hijkl*DR*` to get `5745` - all doors closed and locked. However, going *up* instead is worthwhile: even though it returns you to the room you started in, your path would then be `DU`, opening a *different set of doors*.
+
+After going `DU` (and then hashing `hijkl*DU*` to get `528e`), only the right door is open; after going `DUR`, all doors lock. (Fortunately, your actual passcode is not `hijkl`).
+
+Passcodes actually used by Easter Bunny Vault Security do allow access to the vault if you know the right path. For example:
+
+
+ - If your passcode were `ihgpwlah`, the shortest path would be `DDRRRD`.
+ - With `kglvqrro`, the shortest path would be `DDUDRLRRUDRD`.
+ - With `ulqzkmiv`, the shortest would be `DRURDRUDDLLDLUURRDULRLDUUDDDRR`.
+
+Given your vault's passcode, *what is the shortest path* (the actual path, not just the length) to reach the vault?
+
+
+## --- Part Two ---
+You're curious how robust this security solution really is, and so you decide to find longer and longer paths which still provide access to the vault. You remember that paths always end the first time they reach the bottom-right room (that is, they can never pass through it, only end in it).
+
+For example:
+
+
+ - If your passcode were `ihgpwlah`, the longest path would take `370` steps.
+ - With `kglvqrro`, the longest path would be `492` steps long.
+ - With `ulqzkmiv`, the longest path would be `830` steps long.
+
+
+
+What is the *length of the longest path* that reaches the vault?
+
+
diff --git a/2016/Day17/input.in b/2016/Day17/input.in
index a868569aa..02562b2a2 100644
Binary files a/2016/Day17/input.in and b/2016/Day17/input.in differ
diff --git a/2016/Day18/README.md b/2016/Day18/README.md
index aa4737079..a9019d4ce 100644
--- a/2016/Day18/README.md
+++ b/2016/Day18/README.md
@@ -1,6 +1,65 @@
+original source: [https://adventofcode.com/2016/day/18](https://adventofcode.com/2016/day/18)
## --- Day 18: Like a Rogue ---
As you enter this room, you hear a loud click! Some of the tiles in the floor here seem to be pressure plates for [traps](https://nethackwiki.com/wiki/Trap), and the trap you just triggered has run out of... whatever it tried to do to you. You doubt you'll be so lucky next time.
Upon closer examination, the traps and safe tiles in this room seem to follow a pattern. The tiles are arranged into rows that are all the same width; you take note of the safe tiles (`.`) and traps (`^`) in the first row (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2016/day/18).
\ No newline at end of file
+The type of tile (trapped or safe) in each row is based on the types of the tiles in the same position, and to either side of that position, in the previous row. (If either side is off either end of the row, it counts as "safe" because there isn't a trap embedded in the wall.)
+
+For example, suppose you know the first row (with tiles marked by letters) and want to determine the next row (with tiles marked by numbers):
+
+```
+ABCDE
+12345
+```
+
+The type of tile `2` is based on the types of tiles `A`, `B`, and `C`; the type of tile `5` is based on tiles `D`, `E`, and an imaginary "safe" tile. Let's call these three tiles from the previous row the *left*, *center*, and *right* tiles, respectively. Then, a new tile is a *trap* only in one of the following situations:
+
+
+ - Its *left* and *center* tiles are traps, but its *right* tile is not.
+ - Its *center* and *right* tiles are traps, but its *left* tile is not.
+ - Only its *left* tile is a trap.
+ - Only its *right* tile is a trap.
+
+In any other situation, the new tile is safe.
+
+Then, starting with the row `..^^.`, you can determine the next row by applying those rules to each new tile:
+
+
+ - The leftmost character on the next row considers the left (nonexistent, so we assume "safe"), center (the first `.`, which means "safe"), and right (the second `.`, also "safe") tiles on the previous row. Because all of the trap rules require a trap in at least one of the previous three tiles, the first tile on this new row is also safe, `.`.
+ - The second character on the next row considers its left (`.`), center (`.`), and right (`^`) tiles from the previous row. This matches the fourth rule: only the right tile is a trap. Therefore, the next tile in this new row is a trap, `^`.
+ - The third character considers `.^^`, which matches the second trap rule: its center and right tiles are traps, but its left tile is not. Therefore, this tile is also a trap, `^`.
+ - The last two characters in this new row match the first and third rules, respectively, and so they are both also traps, `^`.
+
+After these steps, we now know the next row of tiles in the room: `.^^^^`. Then, we continue on to the next row, using the same rules, and get `^^..^`. After determining two new rows, our map looks like this:
+
+```
+..^^.
+.^^^^
+^^..^
+```
+
+Here's a larger example with ten tiles per row and ten rows:
+
+```
+.^^.^.^^^^
+^^^...^..^
+^.^^.^.^^.
+..^^...^^^
+.^^^^.^^.^
+^^..^.^^..
+^^^^..^^^.
+^..^^^^.^^
+.^^^..^.^^
+^^.^^^..^^
+```
+
+In ten rows, this larger example has `38` safe tiles.
+
+Starting with the map in your puzzle input, in a total of `40` rows (including the starting row), *how many safe tiles* are there?
+
+
+## --- Part Two ---
+*How many safe tiles* are there in a total of `400000` rows?
+
+
diff --git a/2016/Day18/input.in b/2016/Day18/input.in
index ca1d62f7f..2036710b5 100644
Binary files a/2016/Day18/input.in and b/2016/Day18/input.in differ
diff --git a/2016/Day19/README.md b/2016/Day19/README.md
index 5bfdef034..94579f038 100644
--- a/2016/Day19/README.md
+++ b/2016/Day19/README.md
@@ -1,6 +1,75 @@
+original source: [https://adventofcode.com/2016/day/19](https://adventofcode.com/2016/day/19)
## --- Day 19: An Elephant Named Joseph ---
The Elves contact you over a highly secure emergency channel. Back at the North Pole, the Elves are busy misunderstanding [White Elephant parties](https://en.wikipedia.org/wiki/White_elephant_gift_exchange).
Each Elf brings a present. They all sit in a circle, numbered starting with position `1`. Then, starting with the first Elf, they take turns stealing all the presents from the Elf to their left. An Elf with no presents is removed from the circle and does not take turns.
-Read the [full puzzle](https://adventofcode.com/2016/day/19).
\ No newline at end of file
+For example, with five Elves (numbered `1` to `5`):
+
+```
+ 1
+5 2
+ 4 3
+```
+
+
+ - Elf `1` takes Elf `2`'s present.
+ - Elf `2` has no presents and is skipped.
+ - Elf `3` takes Elf `4`'s present.
+ - Elf `4` has no presents and is also skipped.
+ - Elf `5` takes Elf `1`'s two presents.
+ - Neither Elf `1` nor Elf `2` have any presents, so both are skipped.
+ - Elf `3` takes Elf `5`'s three presents.
+
+So, with *five* Elves, the Elf that sits starting in position `3` gets all the presents.
+
+With the number of Elves given in your puzzle input, *which Elf gets all the presents?*
+
+
+## --- Part Two ---
+Realizing the folly of their present-exchange rules, the Elves agree to instead steal presents from the Elf *directly across the circle*. If two Elves are across the circle, the one on the left (from the perspective of the stealer) is stolen from. The other rules remain unchanged: Elves with no presents are removed from the circle entirely, and the other elves move in slightly to keep the circle evenly spaced.
+
+For example, with five Elves (again numbered `1` to `5`):
+
+
+ - The Elves sit in a circle; Elf `1` goes first:
+```
+ *1*
+5 2
+ 4 3
+```
+
+ - Elves `3` and `4` are across the circle; Elf `3`'s present is stolen, being the one to the left. Elf `3` leaves the circle, and the rest of the Elves move in:
+```
+ *1* 1
+5 2 --> 5 2
+ 4 - 4
+```
+
+ - Elf `2` steals from the Elf directly across the circle, Elf `5`:
+```
+ 1 1
+- *2* --> 2
+ 4 4
+```
+
+ - Next is Elf `4` who, choosing between Elves `1` and `2`, steals from Elf `1`:
+```
+ - 2
+ 2 -->
+ *4* 4
+```
+
+ - Finally, Elf `2` steals from Elf `4`:
+```
+ *2*
+ --> 2
+ -
+```
+
+
+So, with *five* Elves, the Elf that sits starting in position `2` gets all the presents.
+
+With the number of Elves given in your puzzle input, *which Elf now gets all the presents?*
+
+
diff --git a/2016/Day19/input.in b/2016/Day19/input.in
index e1bea95a1..a64cd1961 100644
Binary files a/2016/Day19/input.in and b/2016/Day19/input.in differ
diff --git a/2016/Day20/README.md b/2016/Day20/README.md
index f91a56fec..3f573cdc3 100644
--- a/2016/Day20/README.md
+++ b/2016/Day20/README.md
@@ -1,6 +1,23 @@
+original source: [https://adventofcode.com/2016/day/20](https://adventofcode.com/2016/day/20)
## --- Day 20: Firewall Rules ---
You'd like to set up a small hidden computer here so you can use it to get back into the network later. However, the corporate firewall only allows communication with certain external [IP addresses](https://en.wikipedia.org/wiki/IPv4#Addressing).
You've retrieved the list of blocked IPs from the firewall, but the list seems to be messy and poorly maintained, and it's not clear which IPs are allowed. Also, rather than being written in [dot-decimal](https://en.wikipedia.org/wiki/Dot-decimal_notation) notation, they are written as plain [32-bit integers](https://en.wikipedia.org/wiki/32-bit), which can have any value from `0` through `4294967295`, inclusive.
-Read the [full puzzle](https://adventofcode.com/2016/day/20).
\ No newline at end of file
+For example, suppose only the values `0` through `9` were valid, and that you retrieved the following blacklist:
+
+```
+5-8
+0-2
+4-7
+```
+
+The blacklist specifies ranges of IPs (inclusive of both the start and end value) that are *not* allowed. Then, the only IPs that this firewall allows are `3` and `9`, since those are the only numbers not in any range.
+
+Given the list of blocked IPs you retrieved from the firewall (your puzzle input), *what is the lowest-valued IP* that is not blocked?
+
+
+## --- Part Two ---
+*How many IPs* are allowed by the blacklist?
+
+
diff --git a/2016/Day20/input.in b/2016/Day20/input.in
index 06143dbaf..f809e5407 100644
Binary files a/2016/Day20/input.in and b/2016/Day20/input.in differ
diff --git a/2016/Day21/README.md b/2016/Day21/README.md
index a38e2892c..c730dacac 100644
--- a/2016/Day21/README.md
+++ b/2016/Day21/README.md
@@ -1,6 +1,37 @@
+original source: [https://adventofcode.com/2016/day/21](https://adventofcode.com/2016/day/21)
## --- Day 21: Scrambled Letters and Hash ---
The computer system you're breaking into uses a weird scrambling function to store its passwords. It shouldn't be much trouble to create your own scrambled password so you can add it to the system; you just have to implement the scrambler.
The scrambling function is a series of operations (the exact list is provided in your puzzle input). Starting with the password to be scrambled, apply each operation in succession to the string. The individual operations behave as follows:
-Read the [full puzzle](https://adventofcode.com/2016/day/21).
\ No newline at end of file
+
+ - `swap position X with position Y` means that the letters at indexes `X` and `Y` (counting from `0`) should be *swapped*.
+ - `swap letter X with letter Y` means that the letters `X` and `Y` should be *swapped* (regardless of where they appear in the string).
+ - `rotate left/right X steps` means that the whole string should be *rotated*; for example, one right rotation would turn `abcd` into `dabc`.
+ - `rotate based on position of letter X` means that the whole string should be *rotated to the right* based on the *index* of letter `X` (counting from `0`) as determined *before* this instruction does any rotations. Once the index is determined, rotate the string to the right one time, plus a number of times equal to that index, plus one additional time if the index was at least `4`.
+ - `reverse positions X through Y` means that the span of letters at indexes `X` through `Y` (including the letters at `X` and `Y`) should be *reversed in order*.
+ - `move position X to position Y` means that the letter which is at index `X` should be *removed* from the string, then *inserted* such that it ends up at index `Y`.
+
+For example, suppose you start with `abcde` and perform the following operations:
+
+
+ - `swap position 4 with position 0` swaps the first and last letters, producing the input for the next step, `ebcda`.
+ - `swap letter d with letter b` swaps the positions of `d` and `b`: `edcba`.
+ - `reverse positions 0 through 4` causes the entire string to be reversed, producing `abcde`.
+ - `rotate left 1 step` shifts all letters left one position, causing the first letter to wrap to the end of the string: `bcdea`.
+ - `move position 1 to position 4` removes the letter at position `1` (`c`), then inserts it at position `4` (the end of the string): `bdeac`.
+ - `move position 3 to position 0` removes the letter at position `3` (`a`), then inserts it at position `0` (the front of the string): `abdec`.
+ - `rotate based on position of letter b` finds the index of letter `b` (`1`), then rotates the string right once plus a number of times equal to that index (`2`): `ecabd`.
+ - `rotate based on position of letter d` finds the index of letter `d` (`4`), then rotates the string right once, plus a number of times equal to that index, plus an additional time because the index was at least `4`, for a total of `6` right rotations: `decab`.
+
+After these steps, the resulting scrambled password is `decab`.
+
+Now, you just need to generate a new scrambled password and you can access the system. Given the list of scrambling operations in your puzzle input, *what is the result of scrambling `abcdefgh`*?
+
+
+## --- Part Two ---
+You scrambled the password correctly, but you discover that you [can't actually modify](https://en.wikipedia.org/wiki/File_system_permissions) the [password file](https://en.wikipedia.org/wiki/Passwd) on the system. You'll need to un-scramble one of the existing passwords by reversing the scrambling process.
+
+What is the un-scrambled version of the scrambled password `fbgdceah`?
+
+
diff --git a/2016/Day21/input.in b/2016/Day21/input.in
index 859177f85..ebd7d523c 100644
Binary files a/2016/Day21/input.in and b/2016/Day21/input.in differ
diff --git a/2016/Day22/README.md b/2016/Day22/README.md
index 152ace850..dd1c7280b 100644
--- a/2016/Day22/README.md
+++ b/2016/Day22/README.md
@@ -1,6 +1,126 @@
+original source: [https://adventofcode.com/2016/day/22](https://adventofcode.com/2016/day/22)
## --- Day 22: Grid Computing ---
You gain access to a massive storage cluster arranged in a grid; each storage node is only connected to the four nodes directly adjacent to it (three if the node is on an edge, two if it's in a corner).
You can directly access data *only* on node `/dev/grid/node-x0-y0`, but you can perform some limited actions on the other nodes:
-Read the [full puzzle](https://adventofcode.com/2016/day/22).
\ No newline at end of file
+
+ - You can get the disk usage of all nodes (via [`df`](https://en.wikipedia.org/wiki/Df_(Unix)#Example)). The result of doing this is in your puzzle input.
+ - You can instruct a node to *move* (not copy) *all* of its data to an adjacent node (if the destination node has enough space to receive the data). The sending node is left empty after this operation.
+
+Nodes are named by their position: the node named `node-x10-y10` is adjacent to nodes `node-x9-y10`, `node-x11-y10`, `node-x10-y9`, and `node-x10-y11`.
+
+Before you begin, you need to understand the arrangement of data on these nodes. Even though you can only move data between directly connected nodes, you're going to need to rearrange a lot of the data to get access to the data you need. Therefore, you need to work out how you might be able to shift data around.
+
+To do this, you'd like to count the number of *viable pairs* of nodes. A viable pair is any two nodes (A,B), *regardless of whether they are directly connected*, such that:
+
+
+ - Node A is *not* empty (its `Used` is not zero).
+ - Nodes A and B are *not the same* node.
+ - The data on node A (its `Used`) *would fit* on node B (its `Avail`).
+
+*How many viable pairs* of nodes are there?
+
+
+## --- Part Two ---
+Now that you have a better understanding of the grid, it's time to get to work.
+
+Your goal is to gain access to the data which begins in the node with `y=0` and the *highest `x`* (that is, the node in the top-right corner).
+
+For example, suppose you have the following grid:
+
+```
+Filesystem Size Used Avail Use%
+/dev/grid/node-x0-y0 10T 8T 2T 80%
+/dev/grid/node-x0-y1 11T 6T 5T 54%
+/dev/grid/node-x0-y2 32T 28T 4T 87%
+/dev/grid/node-x1-y0 9T 7T 2T 77%
+/dev/grid/node-x1-y1 8T 0T 8T 0%
+/dev/grid/node-x1-y2 11T 7T 4T 63%
+/dev/grid/node-x2-y0 10T 6T 4T 60%
+/dev/grid/node-x2-y1 9T 8T 1T 88%
+/dev/grid/node-x2-y2 9T 6T 3T 66%
+```
+
+In this example, you have a storage grid `3` nodes wide and `3` nodes tall. The node you can access directly, `node-x0-y0`, is almost full. The node containing the data you want to access, `node-x2-y0` (because it has `y=0` and the highest `x` value), contains 6 [terabytes](https://en.wikipedia.org/wiki/Terabyte) of data - enough to fit on your node, if only you could make enough space to move it there.
+
+Fortunately, `node-x1-y1` looks like it has enough free space to enable you to move some of this data around. In fact, it seems like all of the nodes have enough space to hold any node's data (except `node-x0-y2`, which is much larger, very full, and not moving any time soon). So, initially, the grid's capacities and connections look like this:
+
+```
+( 8T/10T) -- 7T/ 9T -- [ 6T/10T]
+ | | |
+ 6T/11T -- 0T/ 8T -- 8T/ 9T
+ | | |
+ 28T/32T -- 7T/11T -- 6T/ 9T
+```
+
+The node you can access directly is in parentheses; the data you want starts in the node marked by square brackets.
+
+In this example, most of the nodes are interchangable: they're full enough that no other node's data would fit, but small enough that their data could be moved around. Let's draw these nodes as `.`. The exceptions are the empty node, which we'll draw as `_`, and the very large, very full node, which we'll draw as `#`. Let's also draw the goal data as `G`. Then, it looks like this:
+
+```
+(.) . G
+ . _ .
+ # . .
+```
+
+The goal is to move the data in the top right, `G`, to the node in parentheses. To do this, we can issue some commands to the grid and rearrange the data:
+
+
+ - Move data from `node-y0-x1` to `node-y1-x1`, leaving node `node-y0-x1` empty:
+```
+(.) _ G
+ . . .
+ # . .
+```
+
+ - Move the goal data from `node-y0-x2` to `node-y0-x1`:
+```
+(.) G _
+ . . .
+ # . .
+```
+
+ - At this point, we're quite close. However, we have no deletion command, so we have to move some more data around. So, next, we move the data from `node-y1-x2` to `node-y0-x2`:
+```
+(.) G .
+ . . _
+ # . .
+```
+
+ - Move the data from `node-y1-x1` to `node-y1-x2`:
+```
+(.) G .
+ . _ .
+ # . .
+```
+
+ - Move the data from `node-y1-x0` to `node-y1-x1`:
+```
+(.) G .
+ _ . .
+ # . .
+```
+
+ - Next, we can free up space on our node by moving the data from `node-y0-x0` to `node-y1-x0`:
+```
+(_) G .
+ . . .
+ # . .
+```
+
+
+ - Finally, we can access the goal data by moving the it from `node-y0-x1` to `node-y0-x0`:
+```
+(G) _ .
+ . . .
+ # . .
+```
+
+
+
+So, after `7` steps, we've accessed the data we want. Unfortunately, each of these moves takes time, and we need to be efficient:
+
+*What is the fewest number of steps* required to move your goal data to `node-x0-y0`?
+
+
diff --git a/2016/Day22/input.in b/2016/Day22/input.in
index 1c0570dda..878a6b267 100644
Binary files a/2016/Day22/input.in and b/2016/Day22/input.in differ
diff --git a/2016/Day23/README.md b/2016/Day23/README.md
index 6312da7fa..7e43ab965 100644
--- a/2016/Day23/README.md
+++ b/2016/Day23/README.md
@@ -1,6 +1,58 @@
+original source: [https://adventofcode.com/2016/day/23](https://adventofcode.com/2016/day/23)
## --- Day 23: Safe Cracking ---
This is one of the top floors of the nicest tower in EBHQ. The Easter Bunny's private office is here, complete with a safe hidden behind a painting, and who *wouldn't* hide a star in a safe behind a painting?
The safe has a digital screen and keypad for code entry. A sticky note attached to the safe has a password hint on it: "eggs". The painting is of a large rabbit coloring some eggs. You see `7`.
-Read the [full puzzle](https://adventofcode.com/2016/day/23).
\ No newline at end of file
+When you go to type the code, though, nothing appears on the display; instead, the keypad comes apart in your hands, apparently having been smashed. Behind it is some kind of socket - one that matches a connector in your [prototype computer](11)! You pull apart the smashed keypad and extract the logic circuit, plug it into your computer, and plug your computer into the safe.
+
+Now, you just need to figure out what output the keypad would have sent to the safe. You extract the [assembunny code](12) from the logic chip (your puzzle input).
+
+The code looks like it uses *almost* the same architecture and instruction set that the [monorail computer](12) used! You should be able to *use the same assembunny interpreter* for this as you did there, but with one new instruction:
+
+`tgl x` *toggles* the instruction `x` away (pointing at instructions like `jnz` does: positive means forward; negative means backward):
+
+
+ - For *one-argument* instructions, `inc` becomes `dec`, and all other one-argument instructions become `inc`.
+ - For *two-argument* instructions, `jnz` becomes `cpy`, and all other two-instructions become `jnz`.
+ - The arguments of a toggled instruction are *not affected*.
+ - If an attempt is made to toggle an instruction outside the program, *nothing happens*.
+ - If toggling produces an *invalid instruction* (like `cpy 1 2`) and an attempt is later made to execute that instruction, *skip it instead*.
+ - If `tgl` toggles *itself* (for example, if `a` is `0`, `tgl a` would target itself and become `inc a`), the resulting instruction is not executed until the next time it is reached.
+
+For example, given this program:
+
+```
+cpy 2 a
+tgl a
+tgl a
+tgl a
+cpy 1 a
+dec a
+dec a
+```
+
+
+ - `cpy 2 a` initializes register `a` to `2`.
+ - The first `tgl a` toggles an instruction `a` (`2`) away from it, which changes the third `tgl a` into `inc a`.
+ - The second `tgl a` also modifies an instruction `2` away from it, which changes the `cpy 1 a` into `jnz 1 a`.
+ - The fourth line, which is now `inc a`, increments `a` to `3`.
+ - Finally, the fifth line, which is now `jnz 1 a`, jumps `a` (`3`) instructions ahead, skipping the `dec a` instructions.
+
+In this example, the final value in register `a` is `3`.
+
+The rest of the electronics seem to place the keypad entry (the number of eggs, `7`) in register `a`, run the code, and then send the value left in register `a` to the safe.
+
+*What value* should be sent to the safe?
+
+
+## --- Part Two ---
+The safe doesn't open, but it *does* make several angry noises to express its frustration.
+
+You're quite sure your logic is working correctly, so the only other thing is... you check the painting again. As it turns out, colored eggs are still eggs. Now you count `12`.
+
+As you run the program with this new input, the prototype computer begins to *overheat*. You wonder what's taking so long, and whether the lack of any instruction more powerful than "add one" has anything to do with it. Don't bunnies usually *multiply*?
+
+Anyway, *what value* should actually be sent to the safe?
+
+
diff --git a/2016/Day23/input.in b/2016/Day23/input.in
index ea5304016..37b4dac6f 100644
Binary files a/2016/Day23/input.in and b/2016/Day23/input.in differ
diff --git a/2016/Day24/README.md b/2016/Day24/README.md
index ca42bf3f9..03ad41f1a 100644
--- a/2016/Day24/README.md
+++ b/2016/Day24/README.md
@@ -1,6 +1,39 @@
+original source: [https://adventofcode.com/2016/day/24](https://adventofcode.com/2016/day/24)
## --- Day 24: Air Duct Spelunking ---
You've finally met your match; the doors that provide access to the roof are locked tight, and all of the controls and related electronics are inaccessible. You simply can't reach them.
The robot that cleans the air ducts, however, *can*.
-Read the [full puzzle](https://adventofcode.com/2016/day/24).
\ No newline at end of file
+It's not a very fast little robot, but you reconfigure it to be able to interface with some of the exposed wires that have been routed through the [HVAC](https://en.wikipedia.org/wiki/HVAC) system. If you can direct it to each of those locations, you should be able to bypass the security controls.
+
+You extract the duct layout for this area from some blueprints you acquired and create a map with the relevant locations marked (your puzzle input). `0` is your current location, from which the cleaning robot embarks; the other numbers are (in *no particular order*) the locations the robot needs to visit at least once each. Walls are marked as `#`, and open passages are marked as `.`. Numbers behave like open passages.
+
+For example, suppose you have a map like the following:
+
+```
+###########
+#0.1.....2#
+#.#######.#
+#4.......3#
+###########
+```
+
+To reach all of the points of interest as quickly as possible, you would have the robot take the following path:
+
+
+ - `0` to `4` (`2` steps)
+ - `4` to `1` (`4` steps; it can't move diagonally)
+ - `1` to `2` (`6` steps)
+ - `2` to `3` (`2` steps)
+
+Since the robot isn't very fast, you need to find it the *shortest route*. This path is the fewest steps (in the above example, a total of `14`) required to start at `0` and then visit every other location at least once.
+
+Given your actual map, and starting from location `0`, what is the *fewest number of steps* required to visit every non-`0` number marked on the map at least once?
+
+
+## --- Part Two ---
+Of course, if you leave the cleaning robot somewhere weird, someone is bound to notice.
+
+What is the fewest number of steps required to start at `0`, visit every non-`0` number marked on the map at least once, and then *return to `0`*?
+
+
diff --git a/2016/Day24/input.in b/2016/Day24/input.in
index 5051464fd..3b3bade27 100644
Binary files a/2016/Day24/input.in and b/2016/Day24/input.in differ
diff --git a/2016/Day25/README.md b/2016/Day25/README.md
index 268d84818..c5e743775 100644
--- a/2016/Day25/README.md
+++ b/2016/Day25/README.md
@@ -1,6 +1,36 @@
+original source: [https://adventofcode.com/2016/day/25](https://adventofcode.com/2016/day/25)
## --- Day 25: Clock Signal ---
You open the door and find yourself on the roof. The city sprawls away from you for miles and miles.
There's not much time now - it's already Christmas, but you're nowhere near the North Pole, much too far to deliver these stars to the sleigh in time.
-Read the [full puzzle](https://adventofcode.com/2016/day/25).
\ No newline at end of file
+However, maybe the *huge antenna* up here can offer a solution. After all, the sleigh doesn't need the stars, exactly; it needs the timing data they provide, and you happen to have a massive signal generator right here.
+
+You connect the stars you have to your prototype computer, connect that to the antenna, and begin the transmission.
+
+Nothing happens.
+
+You call the service number printed on the side of the antenna and quickly explain the situation. "I'm not sure what kind of equipment you have connected over there," he says, "but you need a clock signal." You try to explain that this is a signal for a clock.
+
+"No, no, a [clock signal](https://en.wikipedia.org/wiki/Clock_signal) - timing information so the antenna computer knows how to read the data you're sending it. An endless, alternating pattern of `0`, `1`, `0`, `1`, `0`, `1`, `0`, `1`, `0`, `1`...." He trails off.
+
+You ask if the antenna can handle a clock signal at the frequency you would need to use for the data from the stars. "There's *no way* it can! The only antenna we've installed capable of *that* is on top of a top-secret Easter Bunny installation, and you're *definitely* not-" You hang up the phone.
+
+You've extracted the antenna's clock signal generation [assembunny](12) code (your puzzle input); it looks mostly compatible with code you worked on [just recently](23).
+
+This antenna code, being a signal generator, uses one extra instruction:
+
+
+ - `out x` *transmits* `x` (either an integer or the *value* of a register) as the next value for the clock signal.
+
+The code takes a value (via register `a`) that describes the signal to generate, but you're not sure how it's used. You'll have to find the input to produce the right signal through experimentation.
+
+*What is the lowest positive integer* that can be used to initialize register `a` and cause the code to output a clock signal of `0`, `1`, `0`, `1`... repeating forever?
+
+
+## --- Part Two ---
+The antenna is ready. Now, all you need is the *fifty stars* required to generate the signal for the sleigh, but you don't have enough.
+
+You look toward the sky in desperation... suddenly noticing that a lone star has been installed at the top of the antenna! Only *49 more* to go.
+
+
diff --git a/2016/Day25/input.in b/2016/Day25/input.in
index 98d287199..8038270ba 100644
Binary files a/2016/Day25/input.in and b/2016/Day25/input.in differ
diff --git a/2016/README.md b/2016/README.md
index d3ef6bd90..8212cc07f 100644
--- a/2016/README.md
+++ b/2016/README.md
@@ -1,4 +1,6 @@
+
# Advent of Code (2016)
Check out https://adventofcode.com/2016.
1122
produces a sum of 3
(1
+ 2
) because the first digit (1
) matches the second digit and the third digit (2
) matches the fourth digit.
+ - 1111
produces 4
because each digit (all 1
) matches the next.
+ - 1234
produces 0
because no digit matches the next.
+ - 91212129
produces 9
because the only digit that matches the next one is the last digit, 9
.
+
+What is the solution to your captcha?
+
+
+## --- Part Two ---
+You notice a progress bar that jumps to 50% completion. Apparently, the door isn't yet satisfied, but it did emit a star as encouragement. The instructions change:
+
+Now, instead of considering the next digit, it wants you to consider the digit halfway around the circular list. That is, if your list contains 10
items, only include a digit in your sum if the digit 10/2 = 5
steps forward matches it. Fortunately, your list has an even number of elements.
+
+For example:
+
+
+ - 1212
produces 6
: the list contains 4
items, and all four digits match the digit 2
items ahead.
+ - 1221
produces 0
, because every comparison is between a 1
and a 2
.
+ - 123425
produces 4
, because both 2
s match each other, but no other digit has a match.
+ - 123123
produces 12
.
+ - 12131415
produces 4
.
+
+What is the solution to your new captcha?
+
+
diff --git a/2017/Day01/input.in b/2017/Day01/input.in
index a2138c7ab..2b1f7768f 100644
Binary files a/2017/Day01/input.in and b/2017/Day01/input.in differ
diff --git a/2017/Day02/README.md b/2017/Day02/README.md
index f2bb4b766..e007cf40b 100644
--- a/2017/Day02/README.md
+++ b/2017/Day02/README.md
@@ -1,6 +1,49 @@
+original source: [https://adventofcode.com/2017/day/2](https://adventofcode.com/2017/day/2)
## --- Day 2: Corruption Checksum ---
As you walk through the door, a glowing humanoid shape yells in your direction. "You there! Your state appears to be idle. Come help us repair the corruption in this spreadsheet - if we take another millisecond, we'll have to display an hourglass cursor!"
The spreadsheet consists of rows of apparently-random numbers. To make sure the recovery process is on the right track, they need you to calculate the spreadsheet's *checksum*. For each row, determine the difference between the largest value and the smallest value; the checksum is the sum of all of these differences.
-Read the [full puzzle](https://adventofcode.com/2017/day/2).
\ No newline at end of file
+For example, given the following spreadsheet:
+
+```
+5 1 9 5
+7 5 3
+2 4 6 8
+```
+
+
+ - The first row's largest and smallest values are `9` and `1`, and their difference is `8`.
+ - The second row's largest and smallest values are `7` and `3`, and their difference is `4`.
+ - The third row's difference is `6`.
+
+In this example, the spreadsheet's checksum would be `8 + 4 + 6 = 18`.
+
+*What is the checksum* for the spreadsheet in your puzzle input?
+
+
+## --- Part Two ---
+"Great work; looks like we're on the right track after all. Here's a *star* for your effort." However, the program seems a little worried. Can programs *be* worried?
+
+"Based on what we're seeing, it looks like all the User wanted is some information about the *evenly divisible values* in the spreadsheet. Unfortunately, none of us are equipped for that kind of calculation - most of us specialize in bitwise operations."
+
+It sounds like the goal is to find the only two numbers in each row where one evenly divides the other - that is, where the result of the division operation is a whole number. They would like you to find those numbers on each line, divide them, and add up each line's result.
+
+For example, given the following spreadsheet:
+
+```
+5 9 2 8
+9 4 7 3
+3 8 6 5
+```
+
+
+ - In the first row, the only two numbers that evenly divide are `8` and `2`; the result of this division is `4`.
+ - In the second row, the two numbers are `9` and `3`; the result is `3`.
+ - In the third row, the result is `2`.
+
+In this example, the sum of the results would be `4 + 3 + 2 = 9`.
+
+What is the *sum of each row's result* in your puzzle input?
+
+
diff --git a/2017/Day02/input.in b/2017/Day02/input.in
index e09ace427..ff84c807e 100644
Binary files a/2017/Day02/input.in and b/2017/Day02/input.in differ
diff --git a/2017/Day03/README.md b/2017/Day03/README.md
index 8bf5afc07..2040b18ef 100644
--- a/2017/Day03/README.md
+++ b/2017/Day03/README.md
@@ -1,6 +1,52 @@
+original source: [https://adventofcode.com/2017/day/3](https://adventofcode.com/2017/day/3)
## --- Day 3: Spiral Memory ---
You come across an experimental new kind of memory stored on an infinite two-dimensional grid.
Each square on the grid is allocated in a spiral pattern starting at a location marked `1` and then counting up while spiraling outward. For example, the first few squares are allocated like this:
-Read the [full puzzle](https://adventofcode.com/2017/day/3).
\ No newline at end of file
+```
+17 16 15 14 13
+18 5 4 3 12
+19 6 1 2 11
+20 7 8 9 10
+21 22 23---> ...
+```
+
+While this is very space-efficient (no squares are skipped), requested data must be carried back to square `1` (the location of the only access port for this memory system) by programs that can only move up, down, left, or right. They always take the shortest path: the [Manhattan Distance](https://en.wikipedia.org/wiki/Taxicab_geometry) between the location of the data and square `1`.
+
+For example:
+
+
+ - Data from square `1` is carried `0` steps, since it's at the access port.
+ - Data from square `12` is carried `3` steps, such as: down, left, left.
+ - Data from square `23` is carried only `2` steps: up twice.
+ - Data from square `1024` must be carried `31` steps.
+
+*How many steps* are required to carry the data from the square identified in your puzzle input all the way to the access port?
+
+
+## --- Part Two ---
+As a stress test on the system, the programs here clear the grid and then store the value `1` in square `1`. Then, in the same allocation order as shown above, they store the sum of the values in all adjacent squares, including diagonals.
+
+So, the first few squares' values are chosen as follows:
+
+
+ - Square `1` starts with the value `1`.
+ - Square `2` has only one adjacent filled square (with value `1`), so it also stores `1`.
+ - Square `3` has both of the above squares as neighbors and stores the sum of their values, `2`.
+ - Square `4` has all three of the aforementioned squares as neighbors and stores the sum of their values, `4`.
+ - Square `5` only has the first and fourth squares as neighbors, so it gets the value `5`.
+
+Once a square is written, its value does not change. Therefore, the first few squares would receive the following values:
+
+```
+147 142 133 122 59
+304 5 4 2 57
+330 10 1 1 54
+351 11 23 25 26
+362 747 806---> ...
+```
+
+What is the *first value written* that is *larger* than your puzzle input?
+
+
diff --git a/2017/Day03/input.in b/2017/Day03/input.in
index 799a453dc..232509ee5 100644
Binary files a/2017/Day03/input.in and b/2017/Day03/input.in differ
diff --git a/2017/Day04/README.md b/2017/Day04/README.md
index 1c942d90a..95fb9c63f 100644
--- a/2017/Day04/README.md
+++ b/2017/Day04/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2017/day/4](https://adventofcode.com/2017/day/4)
## --- Day 4: High-Entropy Passphrases ---
A new system policy has been put in place that requires all accounts to use a *passphrase* instead of simply a pass*word*. A passphrase consists of a series of words (lowercase letters) separated by spaces.
To ensure security, a valid passphrase must contain no duplicate words.
-Read the [full puzzle](https://adventofcode.com/2017/day/4).
\ No newline at end of file
+For example:
+
+
+ - `aa bb cc dd ee` is valid.
+ - `aa bb cc dd aa` is not valid - the word `aa` appears more than once.
+ - `aa bb cc dd aaa` is valid - `aa` and `aaa` count as different words.
+
+The system's full passphrase list is available as your puzzle input. *How many passphrases are valid?*
+
+
+## --- Part Two ---
+For added security, yet another system policy has been put in place. Now, a valid passphrase must contain no two words that are anagrams of each other - that is, a passphrase is invalid if any word's letters can be rearranged to form any other word in the passphrase.
+
+For example:
+
+
+ - `abcde fghij` is a valid passphrase.
+ - `abcde xyz ecdab` is not valid - the letters from the third word can be rearranged to form the first word.
+ - `a ab abc abd abf abj` is a valid passphrase, because *all* letters need to be used when forming another word.
+ - `iiii oiii ooii oooi oooo` is valid.
+ - `oiii ioii iioi iiio` is not valid - any of these words can be rearranged to form any other word.
+
+Under this new system policy, *how many passphrases are valid?*
+
+
diff --git a/2017/Day04/input.in b/2017/Day04/input.in
index a2a581f41..dc46914f7 100644
Binary files a/2017/Day04/input.in and b/2017/Day04/input.in differ
diff --git a/2017/Day05/README.md b/2017/Day05/README.md
index 838976f6a..58e0a5de5 100644
--- a/2017/Day05/README.md
+++ b/2017/Day05/README.md
@@ -1,6 +1,41 @@
+original source: [https://adventofcode.com/2017/day/5](https://adventofcode.com/2017/day/5)
## --- Day 5: A Maze of Twisty Trampolines, All Alike ---
An urgent interrupt arrives from the CPU: it's trapped in a maze of jump instructions, and it would like assistance from any programs with spare cycles to help find the exit.
The message includes a list of the offsets for each jump. Jumps are relative: `-1` moves to the previous instruction, and `2` skips the next one. Start at the first instruction in the list. The goal is to follow the jumps until one leads *outside* the list.
-Read the [full puzzle](https://adventofcode.com/2017/day/5).
\ No newline at end of file
+In addition, these instructions are a little strange; after each jump, the offset of that instruction increases by `1`. So, if you come across an offset of `3`, you would move three instructions forward, but change it to a `4` for the next time it is encountered.
+
+For example, consider the following list of jump offsets:
+
+```
+0
+3
+0
+1
+-3
+```
+
+Positive jumps ("forward") move downward; negative jumps move upward. For legibility in this example, these offset values will be written all on one line, with the current instruction marked in parentheses. The following steps would be taken before an exit is found:
+
+
+ - `(0) 3 0 1 -3 ` - *before* we have taken any steps.
+ - `(1) 3 0 1 -3 ` - jump with offset `0` (that is, don't jump at all). Fortunately, the instruction is then incremented to `1`.
+ - ` 2 (3) 0 1 -3 ` - step forward because of the instruction we just modified. The first instruction is incremented again, now to `2`.
+ - ` 2 4 0 1 (-3)` - jump all the way to the end; leave a `4` behind.
+ - ` 2 (4) 0 1 -2 ` - go back to where we just were; increment `-3` to `-2`.
+ - ` 2 5 0 1 -2 ` - jump `4` steps forward, escaping the maze.
+
+In this example, the exit is reached in `5` steps.
+
+*How many steps* does it take to reach the exit?
+
+
+## --- Part Two ---
+Now, the jumps are even stranger: after each jump, if the offset was *three or more*, instead *decrease* it by `1`. Otherwise, increase it by `1` as before.
+
+Using this rule with the above example, the process now takes `10` steps, and the offset values after finding the exit are left as `2 3 2 3 -1`.
+
+*How many steps* does it now take to reach the exit?
+
+
diff --git a/2017/Day05/input.in b/2017/Day05/input.in
index a6f2d41e0..9a15026f9 100644
Binary files a/2017/Day05/input.in and b/2017/Day05/input.in differ
diff --git a/2017/Day06/README.md b/2017/Day06/README.md
index a3a4fd7ba..96f8c8808 100644
--- a/2017/Day06/README.md
+++ b/2017/Day06/README.md
@@ -1,6 +1,33 @@
+original source: [https://adventofcode.com/2017/day/6](https://adventofcode.com/2017/day/6)
## --- Day 6: Memory Reallocation ---
A debugger program here is having an issue: it is trying to repair a memory reallocation routine, but it keeps getting stuck in an infinite loop.
In this area, there are sixteen memory banks; each memory bank can hold any number of *blocks*. The goal of the reallocation routine is to balance the blocks between the memory banks.
-Read the [full puzzle](https://adventofcode.com/2017/day/6).
\ No newline at end of file
+The reallocation routine operates in cycles. In each cycle, it finds the memory bank with the most blocks (ties won by the lowest-numbered memory bank) and redistributes those blocks among the banks. To do this, it removes all of the blocks from the selected bank, then moves to the next (by index) memory bank and inserts one of the blocks. It continues doing this until it runs out of blocks; if it reaches the last memory bank, it wraps around to the first one.
+
+The debugger would like to know how many redistributions can be done before a blocks-in-banks configuration is produced that *has been seen before*.
+
+For example, imagine a scenario with only four memory banks:
+
+
+ - The banks start with `0`, `2`, `7`, and `0` blocks. The third bank has the most blocks, so it is chosen for redistribution.
+ - Starting with the next bank (the fourth bank) and then continuing to the first bank, the second bank, and so on, the `7` blocks are spread out over the memory banks. The fourth, first, and second banks get two blocks each, and the third bank gets one back. The final result looks like this: `2 4 1 2`.
+ - Next, the second bank is chosen because it contains the most blocks (four). Because there are four memory banks, each gets one block. The result is: `3 1 2 3`.
+ - Now, there is a tie between the first and fourth memory banks, both of which have three blocks. The first bank wins the tie, and its three blocks are distributed evenly over the other three banks, leaving it with none: `0 2 3 4`.
+ - The fourth bank is chosen, and its four blocks are distributed such that each of the four banks receives one: `1 3 4 1`.
+ - The third bank is chosen, and the same thing happens: `2 4 1 2`.
+
+At this point, we've reached a state we've seen before: `2 4 1 2` was already seen. The infinite loop is detected after the fifth block redistribution cycle, and so the answer in this example is `5`.
+
+Given the initial block counts in your puzzle input, *how many redistribution cycles* must be completed before a configuration is produced that has been seen before?
+
+
+## --- Part Two ---
+Out of curiosity, the debugger would also like to know the size of the loop: starting from a state that has already been seen, how many block redistribution cycles must be performed before that same state is seen again?
+
+In the example above, `2 4 1 2` is seen again after four cycles, and so the answer in that example would be `4`.
+
+*How many cycles* are in the infinite loop that arises from the configuration in your puzzle input?
+
+
diff --git a/2017/Day06/input.in b/2017/Day06/input.in
index 90d310c5a..517243634 100644
Binary files a/2017/Day06/input.in and b/2017/Day06/input.in differ
diff --git a/2017/Day07/README.md b/2017/Day07/README.md
index 5d8adfa75..8ea8c8000 100644
--- a/2017/Day07/README.md
+++ b/2017/Day07/README.md
@@ -1,6 +1,72 @@
+original source: [https://adventofcode.com/2017/day/7](https://adventofcode.com/2017/day/7)
## --- Day 7: Recursive Circus ---
Wandering further through the circuits of the computer, you come upon a tower of programs that have gotten themselves into a bit of trouble. A recursive algorithm has gotten out of hand, and now they're balanced precariously in a large tower.
One program at the bottom supports the entire tower. It's holding a large disc, and on the disc are balanced several more sub-towers. At the bottom of these sub-towers, standing on the bottom disc, are other programs, each holding *their* own disc, and so on. At the very tops of these sub-sub-sub-...-towers, many programs stand simply keeping the disc below them balanced but with no disc of their own.
-Read the [full puzzle](https://adventofcode.com/2017/day/7).
\ No newline at end of file
+You offer to help, but first you need to understand the structure of these towers. You ask each program to yell out their *name*, their *weight*, and (if they're holding a disc) the *names of the programs immediately above them* balancing on that disc. You write this information down (your puzzle input). Unfortunately, in their panic, they don't do this in an orderly fashion; by the time you're done, you're not sure which program gave which information.
+
+For example, if your list is the following:
+
+```
+pbga (66)
+xhth (57)
+ebii (61)
+havc (66)
+ktlj (57)
+fwft (72) -> ktlj, cntj, xhth
+qoyq (66)
+padx (45) -> pbga, havc, qoyq
+tknk (41) -> ugml, padx, fwft
+jptl (61)
+ugml (68) -> gyxo, ebii, jptl
+gyxo (61)
+cntj (57)
+```
+
+...then you would be able to recreate the structure of the towers that looks like this:
+
+```
+ gyxo
+ /
+ ugml - ebii
+ / \
+ | jptl
+ |
+ | pbga
+ / /
+tknk --- padx - havc
+ \ \
+ | qoyq
+ |
+ | ktlj
+ \ /
+ fwft - cntj
+ \
+ xhth
+```
+
+In this example, `tknk` is at the bottom of the tower (the *bottom program*), and is holding up `ugml`, `padx`, and `fwft`. Those programs are, in turn, holding up other programs; in this example, none of those programs are holding up any other programs, and are all the tops of their own towers. (The actual tower balancing in front of you is much larger.)
+
+Before you're ready to help them, you need to make sure your information is correct. *What is the name of the bottom program?*
+
+
+## --- Part Two ---
+The programs explain the situation: they can't get down. Rather, they *could* get down, if they weren't expending all of their energy trying to keep the tower balanced. Apparently, one program has the *wrong weight*, and until it's fixed, they're stuck here.
+
+For any program holding a disc, each program standing on that disc forms a sub-tower. Each of those sub-towers are supposed to be the same weight, or the disc itself isn't balanced. The weight of a tower is the sum of the weights of the programs in that tower.
+
+In the example above, this means that for `ugml`'s disc to be balanced, `gyxo`, `ebii`, and `jptl` must all have the same weight, and they do: `61`.
+
+However, for `tknk` to be balanced, each of the programs standing on its disc *and all programs above it* must each match. This means that the following sums must all be the same:
+
+
+ - `ugml` + (`gyxo` + `ebii` + `jptl`) = 68 + (61 + 61 + 61) = 251
+ - `padx` + (`pbga` + `havc` + `qoyq`) = 45 + (66 + 66 + 66) = 243
+ - `fwft` + (`ktlj` + `cntj` + `xhth`) = 72 + (57 + 57 + 57) = 243
+
+As you can see, `tknk`'s disc is unbalanced: `ugml`'s stack is heavier than the other two. Even though the nodes above `ugml` are balanced, `ugml` itself is too heavy: it needs to be `8` units lighter for its stack to weigh `243` and keep the towers balanced. If this change were made, its weight would be `60`.
+
+Given that exactly one program is the wrong weight, *what would its weight need to be* to balance the entire tower?
+
+
diff --git a/2017/Day07/input.in b/2017/Day07/input.in
index 0f1f687ea..b74e00e71 100644
Binary files a/2017/Day07/input.in and b/2017/Day07/input.in differ
diff --git a/2017/Day08/README.md b/2017/Day08/README.md
index b8a09384d..0873dd695 100644
--- a/2017/Day08/README.md
+++ b/2017/Day08/README.md
@@ -1,6 +1,32 @@
+original source: [https://adventofcode.com/2017/day/8](https://adventofcode.com/2017/day/8)
## --- Day 8: I Heard You Like Registers ---
You receive a signal directly from the CPU. Because of your recent assistance with [jump instructions](5), it would like you to compute the result of a series of unusual register instructions.
Each instruction consists of several parts: the register to modify, whether to increase or decrease that register's value, the amount by which to increase or decrease it, and a condition. If the condition fails, skip the instruction without modifying the register. The registers all start at `0`. The instructions look like this:
-Read the [full puzzle](https://adventofcode.com/2017/day/8).
\ No newline at end of file
+```
+b inc 5 if a > 1
+a inc 1 if b < 5
+c dec -10 if a >= 1
+c inc -20 if c == 10
+```
+
+These instructions would be processed as follows:
+
+
+ - Because `a` starts at `0`, it is not greater than `1`, and so `b` is not modified.
+ - `a` is increased by `1` (to `1`) because `b` is less than `5` (it is `0`).
+ - `c` is decreased by `-10` (to `10`) because `a` is now greater than or equal to `1` (it is `1`).
+ - `c` is increased by `-20` (to `-10`) because `c` is equal to `10`.
+
+After this process, the largest value in any register is `1`.
+
+You might also encounter `<=` (less than or equal to) or `!=` (not equal to). However, the CPU doesn't have the bandwidth to tell you what all the registers are named, and leaves that to you to determine.
+
+*What is the largest value in any register* after completing the instructions in your puzzle input?
+
+
+## --- Part Two ---
+To be safe, the CPU also needs to know *the highest value held in any register during this process* so that it can decide how much memory to allocate to these operations. For example, in the above instructions, the highest value ever held was `10` (in register `c` after the third instruction was evaluated).
+
+
diff --git a/2017/Day08/input.in b/2017/Day08/input.in
index 94afcf93d..6f2de6441 100644
Binary files a/2017/Day08/input.in and b/2017/Day08/input.in differ
diff --git a/2017/Day09/README.md b/2017/Day09/README.md
index 03e6ad6b8..585c7addd 100644
--- a/2017/Day09/README.md
+++ b/2017/Day09/README.md
@@ -1,6 +1,67 @@
+original source: [https://adventofcode.com/2017/day/9](https://adventofcode.com/2017/day/9)
## --- Day 9: Stream Processing ---
A large stream blocks your path. According to the locals, it's not safe to cross the stream at the moment because it's full of *garbage*. You look down at the stream; rather than water, you discover that it's a *stream of characters*.
You sit for a while and record part of the stream (your puzzle input). The characters represent *groups* - sequences that begin with `{` and end with `}`. Within a group, there are zero or more other things, separated by commas: either another *group* or *garbage*. Since groups can contain other groups, a `}` only closes the *most-recently-opened unclosed group* - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many smaller ones.
-Read the [full puzzle](https://adventofcode.com/2017/day/9).
\ No newline at end of file
+Sometimes, instead of a group, you will find *garbage*. Garbage begins with `<` and ends with `>`. Between those angle brackets, almost any character can appear, including `{` and `}`. *Within* garbage, `<` has no special meaning.
+
+In a futile attempt to clean up the garbage, some program has *canceled* some of the characters within it using `!`: inside garbage, *any* character that comes after `!` should be *ignored*, including `<`, `>`, and even another `!`.
+
+You don't see any characters that deviate from these rules. Outside garbage, you only find well-formed groups, and garbage always terminates according to the rules above.
+
+Here are some self-contained pieces of garbage:
+
+
+ - `<>`, empty garbage.
+ - `16807
; generator B uses 48271
), and then keep the remainder of dividing that resulting product by 2147483647
. That final remainder is the value it produces next.
+
+To calculate each generator's first value, it instead uses a specific starting value as its "previous value" (as listed in your puzzle input).
+
+For example, suppose that for starting values, generator A uses 65
, while generator B uses 8921
. Then, the first five pairs of generated values are:
+
+
+--Gen. A-- --Gen. B--
+ 1092455 430625591
+1181022009 1233683848
+ 245556042 1431495498
+1744312007 137874439
+1352636452 285222916
+
+
+
+In binary, these pairs are (with generator A's value first in each pair):
+
+
+00000000000100001010101101100111
+00011001101010101101001100110111
+
+01000110011001001111011100111001
+01001001100010001000010110001000
+
+00001110101000101110001101001010
+01010101010100101110001101001010
+
+01100111111110000001011011000111
+00001000001101111100110000000111
+
+01010000100111111001100000100100
+00010001000000000010100000000100
+
+
+
+Here, you can see that the lowest (here, rightmost) 16 bits of the third value match: 1110001101001010
. Because of this one match, after processing these five pairs, the judge would have added only 1
to its total.
+
+To get a significant sample, the judge would like to consider 40 million pairs. (In the example above, the judge would eventually find a total of 588
pairs that match in their lowest 16 bits.)
+
+After 40 million pairs, what is the judge's final count?
+
+
+## --- Part Two ---
+In the interest of trying to align a little better, the generators get more picky about the numbers they actually give to the judge.
+
+They still generate values in the same way, but now they only hand a value to the judge when it meets their criteria:
+
+
+ - Generator A looks for values that are multiples of 4
.
+ - Generator B looks for values that are multiples of 8
.
+
+Each generator functions completely independently: they both go through values entirely on their own, only occasionally handing an acceptable value to the judge, and otherwise working through the same sequence of values as before until they find one.
+
+The judge still waits for each generator to provide it with a value before comparing them (using the same comparison method as before). It keeps track of the order it receives values; the first values from each generator are compared, then the second values from each generator, then the third values, and so on.
+
+Using the example starting values given above, the generators now produce the following first five values each:
+
+
+--Gen. A-- --Gen. B--
+1352636452 1233683848
+1992081072 862516352
+ 530830436 1159784568
+1980017072 1616057672
+ 740335192 412269392
+
+
+
+These values have the following corresponding binary values:
+
+
+01010000100111111001100000100100
+01001001100010001000010110001000
+
+01110110101111001011111010110000
+00110011011010001111010010000000
+
+00011111101000111101010001100100
+01000101001000001110100001111000
+
+01110110000001001010100110110000
+01100000010100110001010101001000
+
+00101100001000001001111001011000
+00011000100100101011101101010000
+
+
+
+Unfortunately, even though this change makes more bits similar on average, none of these values' lowest 16 bits match. Now, it's not until the 1056th pair that the judge finds the first match:
+
+
+--Gen. A-- --Gen. B--
+1023762912 896885216
+
+00111101000001010110000111100000
+00110101011101010110000111100000
+
+
+
+This change makes the generators much slower, and the judge is getting impatient; it is now only willing to consider 5 million pairs. (Using the values from the example above, after five million pairs, the judge would eventually find a total of 309
pairs that match in their lowest 16 bits.)
+
+After 5 million pairs, but using this new generator logic, what is the judge's final count?
+
+
diff --git a/2017/Day15/input.in b/2017/Day15/input.in
index a5e775638..99a802901 100644
Binary files a/2017/Day15/input.in and b/2017/Day15/input.in differ
diff --git a/2017/Day16/README.md b/2017/Day16/README.md
index 5fea82b4c..ca7b84edb 100644
--- a/2017/Day16/README.md
+++ b/2017/Day16/README.md
@@ -1,6 +1,41 @@
+original source: [https://adventofcode.com/2017/day/16](https://adventofcode.com/2017/day/16)
## --- Day 16: Permutation Promenade ---
You come upon a very unusual sight; a group of programs here appear to be [dancing](https://www.youtube.com/watch?v=lyZQPjUT5B4&t=53).
There are sixteen programs in total, named `a` through `p`. They start by standing in a line: `a` stands in position `0`, `b` stands in position `1`, and so on until `p`, which stands in position `15`.
-Read the [full puzzle](https://adventofcode.com/2017/day/16).
\ No newline at end of file
+The programs' *dance* consists of a sequence of *dance moves*:
+
+
+ - *Spin*, written `sX`, makes `X` programs move from the end to the front, but maintain their order otherwise. (For example, `s3` on `abcde` produces `cdeab`).
+ - *Exchange*, written `xA/B`, makes the programs at positions `A` and `B` swap places.
+ - *Partner*, written `pA/B`, makes the programs named `A` and `B` swap places.
+
+For example, with only five programs standing in a line (`abcde`), they could do the following dance:
+
+
+ - `s1`, a spin of size `1`: `eabcd`.
+ - `x3/4`, swapping the last two programs: `eabdc`.
+ - `pe/b`, swapping programs `e` and `b`: `baedc`.
+
+After finishing their dance, the programs end up in order `baedc`.
+You watch the dance for a while and record their dance moves (your puzzle input). *In what order are the programs standing* after their dance?
+
+
+
+
+## --- Part Two ---
+Now that you're starting to get a feel for the dance moves, you turn your attention to *the dance as a whole*.
+
+Keeping the positions they ended up in from their previous dance, the programs perform it again and again: including the first dance, a total of *one billion* (`1000000000`) times.
+
+In the example above, their second dance would *begin* with the order `baedc`, and use the same dance moves:
+
+
+ - `s1`, a spin of size `1`: `cbaed`.
+ - `x3/4`, swapping the last two programs: `cbade`.
+ - `pe/b`, swapping programs `e` and `b`: `ceadb`.
+
+*In what order are the programs standing* after their billion dances?
+
+
diff --git a/2017/Day16/input.in b/2017/Day16/input.in
index bca792491..afac7a443 100644
Binary files a/2017/Day16/input.in and b/2017/Day16/input.in differ
diff --git a/2017/Day17/README.md b/2017/Day17/README.md
index 470b36a6a..5d523d793 100755
--- a/2017/Day17/README.md
+++ b/2017/Day17/README.md
@@ -1,6 +1,51 @@
+original source: [https://adventofcode.com/2017/day/17](https://adventofcode.com/2017/day/17)
## --- Day 17: Spinlock ---
Suddenly, whirling in the distance, you notice what looks like a massive, pixelated hurricane: a deadly [spinlock](https://en.wikipedia.org/wiki/Spinlock). This spinlock isn't just consuming computing power, but memory, too; vast, digital mountains are being ripped from the ground and consumed by the vortex.
If you don't move quickly, fixing that printer will be the least of your problems.
-Read the [full puzzle](https://adventofcode.com/2017/day/17).
\ No newline at end of file
+This spinlock's algorithm is simple but efficient, quickly consuming everything in its path. It starts with a circular buffer containing only the value `0`, which it marks as the *current position*. It then steps forward through the circular buffer some number of steps (your puzzle input) before inserting the first new value, `1`, after the value it stopped on. The inserted value becomes the *current position*. Then, it steps forward from there the same number of steps, and wherever it stops, inserts after it the second new value, `2`, and uses that as the new *current position* again.
+
+It repeats this process of *stepping forward*, *inserting a new value*, and *using the location of the inserted value as the new current position* a total of `*2017*` times, inserting `2017` as its final operation, and ending with a total of `2018` values (including `0`) in the circular buffer.
+
+For example, if the spinlock were to step `3` times per insert, the circular buffer would begin to evolve like this (using parentheses to mark the current position after each iteration of the algorithm):
+
+
+ - `(0)`, the initial state before any insertions.
+ - `0 (1)`: the spinlock steps forward three times (`0`, `0`, `0`), and then inserts the first value, `1`, after it. `1` becomes the current position.
+ - `0 (2) 1`: the spinlock steps forward three times (`0`, `1`, `0`), and then inserts the second value, `2`, after it. `2` becomes the current position.
+ - `0 2 (3) 1`: the spinlock steps forward three times (`1`, `0`, `2`), and then inserts the third value, `3`, after it. `3` becomes the current position.
+
+And so on:
+
+
+ - `0 2 (4) 3 1`
+ - `0 (5) 2 4 3 1`
+ - `0 5 2 4 3 (6) 1`
+ - `0 5 (7) 2 4 3 6 1`
+ - `0 5 7 2 4 3 (8) 6 1`
+ - `0 (9) 5 7 2 4 3 8 6 1`
+
+Eventually, after 2017 insertions, the section of the circular buffer near the last insertion looks like this:
+
+```
+1512 1134 151 (2017) 638 1513 851
+```
+
+Perhaps, if you can identify the value that will ultimately be *after* the last value written (`2017`), you can short-circuit the spinlock. In this example, that would be `638`.
+
+*What is the value after `2017`* in your completed circular buffer?
+
+
+## --- Part Two ---
+The spinlock does not short-circuit. Instead, it gets *more* angry. At least, you assume that's what happened; it's spinning significantly faster than it was a moment ago.
+
+You have good news and bad news.
+
+The good news is that you have improved calculations for how to stop the spinlock. They indicate that you actually need to identify *the value after `0`* in the current state of the circular buffer.
+
+The bad news is that while you were determining this, the spinlock has just finished inserting its fifty millionth value (`50000000`).
+
+*What is the value after `0`* the moment `50000000` is inserted?
+
+
diff --git a/2017/Day17/input.in b/2017/Day17/input.in
index 680907958..47eb669ba 100755
Binary files a/2017/Day17/input.in and b/2017/Day17/input.in differ
diff --git a/2017/Day18/README.md b/2017/Day18/README.md
index 5dad72bb5..d9ee665f1 100755
--- a/2017/Day18/README.md
+++ b/2017/Day18/README.md
@@ -1,6 +1,79 @@
+original source: [https://adventofcode.com/2017/day/18](https://adventofcode.com/2017/day/18)
## --- Day 18: Duet ---
You discover a tablet containing some strange assembly code labeled simply "[Duet](https://en.wikipedia.org/wiki/Duet)". Rather than bother the sound card with it, you decide to run the code yourself. Unfortunately, you don't see any documentation, so you're left to figure out what the instructions mean on your own.
It seems like the assembly is meant to operate on a set of *registers* that are each named with a single letter and that can each hold a single [integer](https://en.wikipedia.org/wiki/Integer). You suppose each register should start with a value of `0`.
-Read the [full puzzle](https://adventofcode.com/2017/day/18).
\ No newline at end of file
+There aren't that many instructions, so it shouldn't be hard to figure out what they do. Here's what you determine:
+
+
+ - `snd X` *plays a sound* with a frequency equal to the value of `X`.
+ - `set X Y` *sets* register `X` to the value of `Y`.
+ - `add X Y` *increases* register `X` by the value of `Y`.
+ - `mul X Y` sets register `X` to the result of *multiplying* the value contained in register `X` by the value of `Y`.
+ - `mod X Y` sets register `X` to the *remainder* of dividing the value contained in register `X` by the value of `Y` (that is, it sets `X` to the result of `X` [modulo](https://en.wikipedia.org/wiki/Modulo_operation) `Y`).
+ - `rcv X` *recovers* the frequency of the last sound played, but only when the value of `X` is not zero. (If it is zero, the command does nothing.)
+ - `jgz X Y` *jumps* with an offset of the value of `Y`, but only if the value of `X` is *greater than zero*. (An offset of `2` skips the next instruction, an offset of `-1` jumps to the previous instruction, and so on.)
+
+Many of the instructions can take either a register (a single letter) or a number. The value of a register is the integer it contains; the value of a number is that number.
+
+After each *jump* instruction, the program continues with the instruction to which the *jump* jumped. After any other instruction, the program continues with the next instruction. Continuing (or jumping) off either end of the program terminates it.
+
+For example:
+
+```
+set a 1
+add a 2
+mul a a
+mod a 5
+snd a
+set a 0
+rcv a
+jgz a -1
+set a 1
+jgz a -2
+```
+
+
+ - The first four instructions set `a` to `1`, add `2` to it, square it, and then set it to itself modulo `5`, resulting in a value of `4`.
+ - Then, a sound with frequency `4` (the value of `a`) is played.
+ - After that, `a` is set to `0`, causing the subsequent `rcv` and `jgz` instructions to both be skipped (`rcv` because `a` is `0`, and `jgz` because `a` is not greater than `0`).
+ - Finally, `a` is set to `1`, causing the next `jgz` instruction to activate, jumping back two instructions to another jump, which jumps again to the `rcv`, which ultimately triggers the *recover* operation.
+
+At the time the *recover* operation is executed, the frequency of the last sound played is `4`.
+
+*What is the value of the recovered frequency* (the value of the most recently played sound) the *first* time a `rcv` instruction is executed with a non-zero value?
+
+
+## --- Part Two ---
+As you congratulate yourself for a job well done, you notice that the documentation has been on the back of the tablet this entire time. While you actually got most of the instructions correct, there are a few key differences. This assembly code isn't about sound at all - it's meant to be run *twice at the same time*.
+
+Each running copy of the program has its own set of registers and follows the code independently - in fact, the programs don't even necessarily run at the same speed. To coordinate, they use the *send* (`snd`) and *receive* (`rcv`) instructions:
+
+
+ - `snd X` *sends* the value of `X` to the other program. These values wait in a queue until that program is ready to receive them. Each program has its own message queue, so a program can never receive a message it sent.
+ - `rcv X` *receives* the next value and stores it in register `X`. If no values are in the queue, the program *waits for a value to be sent to it*. Programs do not continue to the next instruction until they have received a value. Values are received in the order they are sent.
+
+Each program also has its own *program ID* (one `0` and the other `1`); the register `p` should begin with this value.
+
+For example:
+
+```
+snd 1
+snd 2
+snd p
+rcv a
+rcv b
+rcv c
+rcv d
+```
+
+Both programs begin by sending three values to the other. Program `0` sends `1, 2, 0`; program `1` sends `1, 2, 1`. Then, each program receives a value (both `1`) and stores it in `a`, receives another value (both `2`) and stores it in `b`, and then each receives the program ID of the other program (program `0` receives `1`; program `1` receives `0`) and stores it in `c`. Each program now sees a different value in its own copy of register `c`.
+
+Finally, both programs try to `rcv` a *fourth* time, but no data is waiting for either of them, and they reach a *deadlock*. When this happens, both programs terminate.
+
+It should be noted that it would be equally valid for the programs to run at different speeds; for example, program `0` might have sent all three values and then stopped at the first `rcv` before program `1` executed even its first instruction.
+
+Once both of your programs have terminated (regardless of what caused them to do so), *how many times did program `1` send a value*?
+
+
diff --git a/2017/Day18/input.in b/2017/Day18/input.in
index d009c685d..90173aea5 100755
Binary files a/2017/Day18/input.in and b/2017/Day18/input.in differ
diff --git a/2017/Day19/README.md b/2017/Day19/README.md
index 51bf41e1f..c9071a10c 100644
--- a/2017/Day19/README.md
+++ b/2017/Day19/README.md
@@ -1,6 +1,63 @@
+original source: [https://adventofcode.com/2017/day/19](https://adventofcode.com/2017/day/19)
## --- Day 19: A Series of Tubes ---
Somehow, a network packet got lost and ended up here. It's trying to follow a routing diagram (your puzzle input), but it's confused about where to go.
Its starting point is just off the top of the diagram. Lines (drawn with `|`, `-`, and `+`) show the path it needs to take, starting by going down onto the only line connected to the top of the diagram. It needs to follow this path until it reaches the end (located somewhere within the diagram) and stop there.
-Read the [full puzzle](https://adventofcode.com/2017/day/19).
\ No newline at end of file
+Sometimes, the lines cross over each other; in these cases, it needs to continue going the same direction, and only turn left or right when there's no other option. In addition, someone has left *letters* on the line; these also don't change its direction, but it can use them to keep track of where it's been. For example:
+
+```
+ |
+ | +--+
+ A | C
+ F---|----E|--+
+ | | | D
+ +B-+ +--+
+
+```
+
+Given this diagram, the packet needs to take the following path:
+
+
+ - Starting at the only line touching the top of the diagram, it must go down, pass through `A`, and continue onward to the first `+`.
+ - Travel right, up, and right, passing through `B` in the process.
+ - Continue down (collecting `C`), right, and up (collecting `D`).
+ - Finally, go all the way left through `E` and stopping at `F`.
+
+Following the path to the end, the letters it sees on its path are `ABCDEF`.
+
+The little packet looks up at you, hoping you can help it find the way. *What letters will it see* (in the order it would see them) if it follows the path? (The routing diagram is very wide; make sure you view it without line wrapping.)
+
+
+## --- Part Two ---
+The packet is curious how many steps it needs to go.
+
+For example, using the same routing diagram from the example above...
+
+```
+ |
+ | +--+
+ A | C
+ F---|--|-E---+
+ | | | D
+ +B-+ +--+
+
+```
+
+...the packet would go:
+
+
+ - `6` steps down (including the first line at the top of the diagram).
+ - `3` steps right.
+ - `4` steps up.
+ - `3` steps right.
+ - `4` steps down.
+ - `3` steps right.
+ - `2` steps up.
+ - `13` steps left (including the `F` it stops on).
+
+This would result in a total of `38` steps.
+
+*How many steps* does the packet need to go?
+
+
diff --git a/2017/Day19/input.in b/2017/Day19/input.in
index 5dff2031d..e5946cfe9 100644
Binary files a/2017/Day19/input.in and b/2017/Day19/input.in differ
diff --git a/2017/Day20/README.md b/2017/Day20/README.md
index 5f187c427..260c9f7a1 100644
--- a/2017/Day20/README.md
+++ b/2017/Day20/README.md
@@ -1,6 +1,71 @@
+original source: [https://adventofcode.com/2017/day/20](https://adventofcode.com/2017/day/20)
## --- Day 20: Particle Swarm ---
Suddenly, the GPU contacts you, asking for help. Someone has asked it to simulate *too many particles*, and it won't be able to finish them all in time to render the next frame at this rate.
It transmits to you a buffer (your puzzle input) listing each particle in order (starting with particle `0`, then particle `1`, particle `2`, and so on). For each particle, it provides the `X`, `Y`, and `Z` coordinates for the particle's position (`p`), velocity (`v`), and acceleration (`a`), each in the format `+6
means the current frequency increases by 6
; a value like -3
means the current frequency decreases by 3
.
+
+For example, if the device displays frequency changes of +1, -2, +3, +1
, then starting from a frequency of zero, the following changes would occur:
+
+
+ - Current frequency 0
, change of +1
; resulting frequency 1
.
+ - Current frequency 1
, change of -2
; resulting frequency -1
.
+ - Current frequency -1
, change of +3
; resulting frequency 2
.
+ - Current frequency 2
, change of +1
; resulting frequency 3
.
+
+In this example, the resulting frequency is 3
.
+
+Here are other example situations:
+
+
+ - +1, +1, +1
results in 3
+ - +1, +1, -2
results in 0
+ - -1, -2, -3
results in -6
+
+Starting with a frequency of zero, what is the resulting frequency after all of the changes in frequency have been applied?
+
+
+## --- Part Two ---
+You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice.
+
+For example, using the same list of changes above, the device would loop as follows:
+
+
+ - Current frequency 0
, change of +1
; resulting frequency 1
.
+ - Current frequency 1
, change of -2
; resulting frequency -1
.
+ - Current frequency -1
, change of +3
; resulting frequency 2
.
+ - Current frequency 2
, change of +1
; resulting frequency 3
.
+ - (At this point, the device continues from the start of the list.)
+ - Current frequency 3
, change of +1
; resulting frequency 4
.
+ - Current frequency 4
, change of -2
; resulting frequency 2
, which has already been seen.
+
+In this example, the first frequency reached twice is 2
. Note that your device might need to repeat its list of frequency changes many times before a duplicate frequency is found, and that duplicates might be found while in the middle of processing the list.
+
+Here are other examples:
+
+
+ - +1, -1
first reaches 0
twice.
+ - +3, +3, +4, -2, -4
first reaches 10
twice.
+ - -6, +3, +8, +5, -6
first reaches 5
twice.
+ - +7, +7, -2, -7, -4
first reaches 14
twice.
+
+What is the first frequency your device reaches twice?
+
+
diff --git a/2018/Day01/input.in b/2018/Day01/input.in
index 8103c3057..15d2c6e20 100644
Binary files a/2018/Day01/input.in and b/2018/Day01/input.in differ
diff --git a/2018/Day02/README.md b/2018/Day02/README.md
index 920cce933..dccfa211d 100644
--- a/2018/Day02/README.md
+++ b/2018/Day02/README.md
@@ -1,6 +1,48 @@
+original source: [https://adventofcode.com/2018/day/2](https://adventofcode.com/2018/day/2)
## --- Day 2: Inventory Management System ---
You stop falling through time, catch your breath, and check the screen on the device. "Destination reached. Current Year: 1518. Current Location: North Pole Utility Closet 83N10." You made it! Now, to find those anomalies.
Outside the utility closet, you hear footsteps and a voice. "...I'm not sure either. But now that so many people have chimneys, maybe he could sneak in that way?" Another voice responds, "Actually, we've been working on a new kind of *suit* that would let him fit through tight spaces like that. But, I heard that a few days ago, they lost the prototype fabric, the design plans, everything! Nobody on the team can even seem to remember important details of the project!"
-Read the [full puzzle](https://adventofcode.com/2018/day/2).
\ No newline at end of file
+"Wouldn't they have had enough fabric to fill several boxes in the warehouse? They'd be stored together, so the box IDs should be similar. Too bad it would take forever to search the warehouse for *two similar box IDs*..." They walk too far away to hear any more.
+
+Late at night, you sneak to the warehouse - who knows what kinds of paradoxes you could cause if you were discovered - and use your fancy wrist device to quickly scan every box and produce a list of the likely candidates (your puzzle input).
+
+To make sure you didn't miss any, you scan the likely candidate boxes again, counting the number that have an ID containing *exactly two of any letter* and then separately counting those with *exactly three of any letter*. You can multiply those two counts together to get a rudimentary [checksum](https://en.wikipedia.org/wiki/Checksum) and compare it to what your device predicts.
+
+For example, if you see the following box IDs:
+
+
+ - `abcdef` contains no letters that appear exactly two or three times.
+ - `bababc` contains two `a` and three `b`, so it counts for both.
+ - `abbcde` contains two `b`, but no letter appears exactly three times.
+ - `abcccd` contains three `c`, but no letter appears exactly two times.
+ - `aabcdd` contains two `a` and two `d`, but it only counts once.
+ - `abcdee` contains two `e`.
+ - `ababab` contains three `a` and three `b`, but it only counts once.
+
+Of these box IDs, four of them contain a letter which appears exactly twice, and three of them contain a letter which appears exactly three times. Multiplying these together produces a checksum of `4 * 3 = 12`.
+
+*What is the checksum* for your list of box IDs?
+
+
+## --- Part Two ---
+Confident that your list of box IDs is complete, you're ready to find the boxes full of prototype fabric.
+
+The boxes will have IDs which differ by exactly one character at the same position in both strings. For example, given the following box IDs:
+
+```
+abcde
+fghij
+klmno
+pqrst
+fguij
+axcye
+wvxyz
+```
+
+The IDs `abcde` and `axcye` are close, but they differ by two characters (the second and fourth). However, the IDs `fghij` and `fguij` differ by exactly one character, the third (`h` and `u`). Those must be the correct boxes.
+
+*What letters are common between the two correct box IDs?* (In the example above, this is found by removing the differing character from either ID, producing `fgij`.)
+
+
diff --git a/2018/Day02/input.in b/2018/Day02/input.in
index dc37cf34f..cdcf84ba7 100644
Binary files a/2018/Day02/input.in and b/2018/Day02/input.in differ
diff --git a/2018/Day03/README.md b/2018/Day03/README.md
index cc4dad2c6..099b90d08 100644
--- a/2018/Day03/README.md
+++ b/2018/Day03/README.md
@@ -1,6 +1,62 @@
+original source: [https://adventofcode.com/2018/day/3](https://adventofcode.com/2018/day/3)
## --- Day 3: No Matter How You Slice It ---
The Elves managed to locate the chimney-squeeze prototype fabric for Santa's suit (thanks to someone who helpfully wrote its box IDs on the wall of the warehouse in the middle of the night). Unfortunately, anomalies are still affecting them - nobody can even agree on how to *cut* the fabric.
The whole piece of fabric they're working on is a very large square - at least `1000` inches on each side.
-Read the [full puzzle](https://adventofcode.com/2018/day/3).
\ No newline at end of file
+Each Elf has made a *claim* about which area of fabric would be ideal for Santa's suit. All claims have an ID and consist of a single rectangle with edges parallel to the edges of the fabric. Each claim's rectangle is defined as follows:
+
+
+ - The number of inches between the left edge of the fabric and the left edge of the rectangle.
+ - The number of inches between the top edge of the fabric and the top edge of the rectangle.
+ - The width of the rectangle in inches.
+ - The height of the rectangle in inches.
+
+A claim like `#123 @ 3,2: 5x4` means that claim ID `123` specifies a rectangle `3` inches from the left edge, `2` inches from the top edge, `5` inches wide, and `4` inches tall. Visually, it claims the square inches of fabric represented by `#` (and ignores the square inches of fabric represented by `.`) in the diagram below:
+
+```
+...........
+...........
+...#####...
+...#####...
+...#####...
+...#####...
+...........
+...........
+...........
+```
+
+The problem is that many of the claims *overlap*, causing two or more claims to cover part of the same areas. For example, consider the following claims:
+
+```
+#1 @ 1,3: 4x4
+#2 @ 3,1: 4x4
+#3 @ 5,5: 2x2
+```
+
+Visually, these claim the following areas:
+
+```
+........
+...2222.
+...2222.
+.11XX22.
+.11XX22.
+.111133.
+.111133.
+........
+```
+
+The four square inches marked with `X` are claimed by *both `1` and `2`*. (Claim `3`, while adjacent to the others, does not overlap either of them.)
+
+If the Elves all proceed with their own plans, none of them will have enough fabric. *How many square inches of fabric are within two or more claims?*
+
+
+## --- Part Two ---
+Amidst the chaos, you notice that exactly one claim doesn't overlap by even a single square inch of fabric with any other claim. If you can somehow draw attention to it, maybe the Elves will be able to make Santa's suit after all!
+
+For example, in the claims above, only claim `3` is intact after all claims are made.
+
+*What is the ID of the only claim that doesn't overlap?*
+
+
diff --git a/2018/Day03/input.in b/2018/Day03/input.in
index ad9827ff8..c98e5a018 100644
Binary files a/2018/Day03/input.in and b/2018/Day03/input.in differ
diff --git a/2018/Day04/README.md b/2018/Day04/README.md
index 043e4e5a5..b8ee6f39b 100644
--- a/2018/Day04/README.md
+++ b/2018/Day04/README.md
@@ -1,6 +1,66 @@
+original source: [https://adventofcode.com/2018/day/4](https://adventofcode.com/2018/day/4)
## --- Day 4: Repose Record ---
You've sneaked into another supply closet - this time, it's across from the prototype suit manufacturing lab. You need to sneak inside and fix the issues with the suit, but there's a guard stationed outside the lab, so this is as close as you can safely get.
As you search the closet for anything that might help, you discover that you're not the first person to want to sneak in. Covering the walls, someone has spent an hour starting every midnight for the past few months secretly observing this guard post! They've been writing down the ID of *the one guard on duty that night* - the Elves seem to have decided that one guard was enough for the overnight shift - as well as when they fall asleep or wake up while at their post (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2018/day/4).
\ No newline at end of file
+For example, consider the following records, which have already been organized into chronological order:
+
+```
+[1518-11-01 00:00] Guard #10 begins shift
+[1518-11-01 00:05] falls asleep
+[1518-11-01 00:25] wakes up
+[1518-11-01 00:30] falls asleep
+[1518-11-01 00:55] wakes up
+[1518-11-01 23:58] Guard #99 begins shift
+[1518-11-02 00:40] falls asleep
+[1518-11-02 00:50] wakes up
+[1518-11-03 00:05] Guard #10 begins shift
+[1518-11-03 00:24] falls asleep
+[1518-11-03 00:29] wakes up
+[1518-11-04 00:02] Guard #99 begins shift
+[1518-11-04 00:36] falls asleep
+[1518-11-04 00:46] wakes up
+[1518-11-05 00:03] Guard #99 begins shift
+[1518-11-05 00:45] falls asleep
+[1518-11-05 00:55] wakes up
+```
+
+Timestamps are written using `year-month-day hour:minute` format. The guard falling asleep or waking up is always the one whose shift most recently started. Because all asleep/awake times are during the midnight hour (`00:00` - `00:59`), only the minute portion (`00` - `59`) is relevant for those events.
+
+Visually, these records show that the guards are asleep at these times:
+
+```
+Date ID Minute
+ 000000000011111111112222222222333333333344444444445555555555
+ 012345678901234567890123456789012345678901234567890123456789
+11-01 #10 .....####################.....#########################.....
+11-02 #99 ........................................##########..........
+11-03 #10 ........................#####...............................
+11-04 #99 ....................................##########..............
+11-05 #99 .............................................##########.....
+```
+
+The columns are Date, which shows the month-day portion of the relevant day; ID, which shows the guard on duty that day; and Minute, which shows the minutes during which the guard was asleep within the midnight hour. (The Minute column's header shows the minute's ten's digit in the first row and the one's digit in the second row.) Awake is shown as `.`, and asleep is shown as `#`.
+
+Note that guards count as asleep on the minute they fall asleep, and they count as awake on the minute they wake up. For example, because Guard #10 wakes up at 00:25 on 1518-11-01, minute 25 is marked as awake.
+
+If you can figure out the guard most likely to be asleep at a specific time, you might be able to trick that guard into working tonight so you can have the best chance of sneaking in. You have two strategies for choosing the best guard/minute combination.
+
+*Strategy 1:* Find the guard that has the most minutes asleep. What minute does that guard spend asleep the most?
+
+In the example above, Guard #10 spent the most minutes asleep, a total of 50 minutes (20+25+5), while Guard #99 only slept for a total of 30 minutes (10+10+10). Guard #*10* was asleep most during minute *24* (on two days, whereas any other minute the guard was asleep was only seen on one day).
+
+While this example listed the entries in chronological order, your entries are in the order you found them. You'll need to organize them before they can be analyzed.
+
+*What is the ID of the guard you chose multiplied by the minute you chose?* (In the above example, the answer would be `10 * 24 = 240`.)
+
+
+## --- Part Two ---
+*Strategy 2:* Of all guards, which guard is most frequently asleep on the same minute?
+
+In the example above, Guard #*99* spent minute *45* asleep more than any other guard or minute - three times in total. (In all other cases, any guard spent any minute asleep at most twice.)
+
+*What is the ID of the guard you chose multiplied by the minute you chose?* (In the above example, the answer would be `99 * 45 = 4455`.)
+
+
diff --git a/2018/Day04/input.in b/2018/Day04/input.in
index 3675066b8..aba0f2c3d 100644
Binary files a/2018/Day04/input.in and b/2018/Day04/input.in differ
diff --git a/2018/Day05/README.md b/2018/Day05/README.md
index 09a32c2e7..9699efa23 100644
--- a/2018/Day05/README.md
+++ b/2018/Day05/README.md
@@ -1,6 +1,48 @@
+original source: [https://adventofcode.com/2018/day/5](https://adventofcode.com/2018/day/5)
## --- Day 5: Alchemical Reduction ---
You've managed to sneak in to the prototype suit manufacturing lab. The Elves are making decent progress, but are still struggling with the suit's size reduction capabilities.
While the very latest in 1518 alchemical technology might have solved their problem eventually, you can do better. You scan the chemical composition of the suit's material and discover that it is formed by extremely long [polymers](https://en.wikipedia.org/wiki/Polymer) (one of which is available as your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2018/day/5).
\ No newline at end of file
+The polymer is formed by smaller *units* which, when triggered, react with each other such that two adjacent units of the same type and opposite polarity are destroyed. Units' types are represented by letters; units' polarity is represented by capitalization. For instance, `r` and `R` are units with the same type but opposite polarity, whereas `r` and `s` are entirely different types and do not react.
+
+For example:
+
+
+ - In `aA`, `a` and `A` react, leaving nothing behind.
+ - In `abBA`, `bB` destroys itself, leaving `aA`. As above, this then destroys itself, leaving nothing.
+ - In `abAB`, no two adjacent units are of the same type, and so nothing happens.
+ - In `aabAAB`, even though `aa` and `AA` are of the same type, their polarities match, and so nothing happens.
+
+Now, consider a larger example, `dabAcCaCBAcCcaDA`:
+
+```
+dabA*cC*aCBAcCcaDA The first 'cC' is removed.
+dab*Aa*CBAcCcaDA This creates 'Aa', which is removed.
+dabCBA*cCc*aDA Either 'cC' or 'Cc' are removed (the result is the same).
+dabCBAcaDA No further actions can be taken.
+```
+
+After all possible reactions, the resulting polymer contains *10 units*.
+
+*How many units remain after fully reacting the polymer you scanned?* (Note: in this puzzle and others, the input is large; if you copy/paste your input, make sure you get the whole thing.)
+
+
+## --- Part Two ---
+Time to improve the polymer.
+
+One of the unit types is causing problems; it's preventing the polymer from collapsing as much as it should. Your goal is to figure out which unit type is causing the most problems, remove all instances of it (regardless of polarity), fully react the remaining polymer, and measure its length.
+
+For example, again using the polymer `dabAcCaCBAcCcaDA` from above:
+
+
+ - Removing all `A`/`a` units produces `dbcCCBcCcD`. Fully reacting this polymer produces `dbCBcD`, which has length 6.
+ - Removing all `B`/`b` units produces `daAcCaCAcCcaDA`. Fully reacting this polymer produces `daCAcaDA`, which has length 8.
+ - Removing all `C`/`c` units produces `dabAaBAaDA`. Fully reacting this polymer produces `daDA`, which has length 4.
+ - Removing all `D`/`d` units produces `abAcCaCBAcCcaA`. Fully reacting this polymer produces `abCBAc`, which has length 6.
+
+In this example, removing all `C`/`c` units was best, producing the answer *4*.
+
+*What is the length of the shortest polymer you can produce* by removing all units of exactly one type and fully reacting the result?
+
+
diff --git a/2018/Day05/input.in b/2018/Day05/input.in
index c23e0782e..0fec35f2d 100644
Binary files a/2018/Day05/input.in and b/2018/Day05/input.in differ
diff --git a/2018/Day06/README.md b/2018/Day06/README.md
index 47db579bb..ee1d138fc 100644
--- a/2018/Day06/README.md
+++ b/2018/Day06/README.md
@@ -1,6 +1,98 @@
+original source: [https://adventofcode.com/2018/day/6](https://adventofcode.com/2018/day/6)
## --- Day 6: Chronal Coordinates ---
The device on your wrist beeps several times, and once again you feel like you're falling.
"Situation critical," the device announces. "Destination indeterminate. Chronal interference detected. Please specify new target coordinates."
-Read the [full puzzle](https://adventofcode.com/2018/day/6).
\ No newline at end of file
+The device then produces a list of coordinates (your puzzle input). Are they places it thinks are safe or dangerous? It recommends you check manual page 729. The Elves did not give you a manual.
+
+*If they're dangerous,* maybe you can minimize the danger by finding the coordinate that gives the largest distance from the other points.
+
+Using only the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry), determine the *area* around each coordinate by counting the number of [integer](https://en.wikipedia.org/wiki/Integer) X,Y locations that are *closest* to that coordinate (and aren't *tied in distance* to any other coordinate).
+
+Your goal is to find the size of the *largest area* that isn't infinite. For example, consider the following list of coordinates:
+
+```
+1, 1
+1, 6
+8, 3
+3, 4
+5, 5
+8, 9
+```
+
+If we name these coordinates `A` through `F`, we can draw them on a grid, putting `0,0` at the top left:
+
+```
+..........
+.A........
+..........
+........C.
+...D......
+.....E....
+.B........
+..........
+..........
+........F.
+```
+
+This view is partial - the actual grid extends infinitely in all directions. Using the Manhattan distance, each location's closest coordinate can be determined, shown here in lowercase:
+
+```
+aaaaa.cccc
+a*A*aaa.cccc
+aaaddecccc
+aadddecc*C*c
+..d*D*deeccc
+bb.de*E*eecc
+b*B*b.eeee..
+bbb.eeefff
+bbb.eeffff
+bbb.ffff*F*f
+```
+
+Locations shown as `.` are equally far from two or more coordinates, and so they don't count as being closest to any.
+
+In this example, the areas of coordinates A, B, C, and F are infinite - while not shown here, their areas extend forever outside the visible grid. However, the areas of coordinates D and E are finite: D is closest to 9 locations, and E is closest to 17 (both including the coordinate's location itself). Therefore, in this example, the size of the largest area is *17*.
+
+*What is the size of the largest area* that isn't infinite?
+
+
+## --- Part Two ---
+On the other hand, *if the coordinates are safe*, maybe the best you can do is try to find a *region* near as many coordinates as possible.
+
+For example, suppose you want the sum of the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) to all of the coordinates to be *less than 32*. For each location, add up the distances to all of the given coordinates; if the total of those distances is less than 32, that location is within the desired region. Using the same coordinates as above, the resulting region looks like this:
+
+```
+..........
+.A........
+..........
+...#*#*#..C.
+..#D###...
+..###E#...
+.B.###....
+..........
+..........
+........F.
+```
+
+In particular, consider the highlighted location `4,3` located at the top middle of the region. Its calculation is as follows, where `abs()` is the [absolute value](https://en.wikipedia.org/wiki/Absolute_value) function:
+
+
+ - Distance to coordinate A: `abs(4-1) + abs(3-1) = 5`
+ - Distance to coordinate B: `abs(4-1) + abs(3-6) = 6`
+ - Distance to coordinate C: `abs(4-8) + abs(3-3) = 4`
+ - Distance to coordinate D: `abs(4-3) + abs(3-4) = 2`
+ - Distance to coordinate E: `abs(4-5) + abs(3-5) = 3`
+ - Distance to coordinate F: `abs(4-8) + abs(3-9) = 10`
+ - Total distance: `5 + 6 + 4 + 2 + 3 + 10 = 30`
+
+Because the total distance to all coordinates (`30`) is less than 32, the location is *within* the region.
+
+This region, which also includes coordinates D and E, has a total size of *16*.
+
+Your actual region will need to be much larger than this example, though, instead including all locations with a total distance of less than *10000*.
+
+*What is the size of the region containing all locations which have a total distance to all given coordinates of less than 10000?*
+
+
diff --git a/2018/Day06/input.in b/2018/Day06/input.in
index 54e5710fd..e07e4ab45 100644
Binary files a/2018/Day06/input.in and b/2018/Day06/input.in differ
diff --git a/2018/Day07/README.md b/2018/Day07/README.md
index 2dd1cc983..c276ae386 100644
--- a/2018/Day07/README.md
+++ b/2018/Day07/README.md
@@ -1,6 +1,84 @@
+original source: [https://adventofcode.com/2018/day/7](https://adventofcode.com/2018/day/7)
## --- Day 7: The Sum of Its Parts ---
You find yourself standing on a snow-covered coastline; apparently, you landed a little off course. The region is too hilly to see the North Pole from here, but you do spot some Elves that seem to be trying to unpack something that washed ashore. It's quite cold out, so you decide to risk creating a paradox by asking them for directions.
"Oh, are you the search party?" Somehow, you can understand whatever Elves from the year 1018 speak; you assume it's [Ancient Nordic Elvish](/2015/day/6). Could the device on your wrist also be a translator? "Those clothes don't look very warm; take this." They hand you a heavy coat.
-Read the [full puzzle](https://adventofcode.com/2018/day/7).
\ No newline at end of file
+"We do need to find our way back to the North Pole, but we have higher priorities at the moment. You see, believe it or not, this box contains something that will solve all of Santa's transportation problems - at least, that's what it looks like from the pictures in the instructions." It doesn't seem like they can read whatever language it's in, but you can: "Sleigh kit. Some assembly required."
+
+"'Sleigh'? What a wonderful name! You must help us assemble this 'sleigh' at once!" They start excitedly pulling more parts out of the box.
+
+The instructions specify a series of *steps* and requirements about which steps must be finished before others can begin (your puzzle input). Each step is designated by a single letter. For example, suppose you have the following instructions:
+
+```
+Step C must be finished before step A can begin.
+Step C must be finished before step F can begin.
+Step A must be finished before step B can begin.
+Step A must be finished before step D can begin.
+Step B must be finished before step E can begin.
+Step D must be finished before step E can begin.
+Step F must be finished before step E can begin.
+```
+
+Visually, these requirements look like this:
+
+```
+
+ -->A--->B--
+ / \ \
+C -->D----->E
+ \ /
+ ---->F-----
+```
+
+Your first goal is to determine the order in which the steps should be completed. If more than one step is ready, choose the step which is first alphabetically. In this example, the steps would be completed as follows:
+
+
+ - Only *`C`* is available, and so it is done first.
+ - Next, both `A` and `F` are available. *`A`* is first alphabetically, so it is done next.
+ - Then, even though `F` was available earlier, steps `B` and `D` are now also available, and *`B`* is the first alphabetically of the three.
+ - After that, only `D` and `F` are available. `E` is not available because only some of its prerequisites are complete. Therefore, *`D`* is completed next.
+ - *`F`* is the only choice, so it is done next.
+ - Finally, *`E`* is completed.
+
+So, in this example, the correct order is *`CABDFE`*.
+
+*In what order should the steps in your instructions be completed?*
+
+
+## --- Part Two ---
+As you're about to begin construction, four of the Elves offer to help. "The sun will set soon; it'll go faster if we work together." Now, you need to account for multiple people working on steps simultaneously. If multiple steps are available, workers should still begin them in alphabetical order.
+
+Each step takes 60 seconds plus an amount corresponding to its letter: A=1, B=2, C=3, and so on. So, step A takes `60+1=61` seconds, while step Z takes `60+26=86` seconds. No time is required between steps.
+
+To simplify things for the example, however, suppose you only have help from one Elf (a total of two workers) and that each step takes 60 fewer seconds (so that step A takes 1 second and step Z takes 26 seconds). Then, using the same instructions as above, this is how each second would be spent:
+
+```
+Second Worker 1 Worker 2 Done
+ 0 C .
+ 1 C .
+ 2 C .
+ 3 A F C
+ 4 B F CA
+ 5 B F CA
+ 6 D F CAB
+ 7 D F CAB
+ 8 D F CAB
+ 9 D . CABF
+ 10 E . CABFD
+ 11 E . CABFD
+ 12 E . CABFD
+ 13 E . CABFD
+ 14 E . CABFD
+ 15 . . CABFDE
+```
+
+Each row represents one second of time. The Second column identifies how many seconds have passed as of the beginning of that second. Each worker column shows the step that worker is currently doing (or `.` if they are idle). The Done column shows completed steps.
+
+Note that the order of the steps has changed; this is because steps now take time to finish and multiple workers can begin multiple steps simultaneously.
+
+In this example, it would take *15* seconds for two workers to complete these steps.
+
+With *5* workers and the *60+ second* step durations described above, *how long will it take to complete all of the steps?*
+
+
diff --git a/2018/Day07/input.in b/2018/Day07/input.in
index 414e2d7a2..702dcba34 100644
Binary files a/2018/Day07/input.in and b/2018/Day07/input.in differ
diff --git a/2018/Day08/README.md b/2018/Day08/README.md
index 8e314227d..c57df8de9 100644
--- a/2018/Day08/README.md
+++ b/2018/Day08/README.md
@@ -1,6 +1,63 @@
+original source: [https://adventofcode.com/2018/day/8](https://adventofcode.com/2018/day/8)
## --- Day 8: Memory Maneuver ---
The sleigh is much easier to pull than you'd expect for something its weight. Unfortunately, neither you nor the Elves know which way the North Pole is from here.
You check your wrist device for anything that might help. It seems to have some kind of navigation system! Activating the navigation system produces more bad news: "Failed to start navigation system. Could not read software license file."
-Read the [full puzzle](https://adventofcode.com/2018/day/8).
\ No newline at end of file
+The navigation system's license file consists of a list of numbers (your puzzle input). The numbers define a data structure which, when processed, produces some kind of [tree](https://en.wikipedia.org/wiki/Tree_(data_structure)) that can be used to calculate the license number.
+
+The *tree* is made up of *nodes*; a single, outermost node forms the tree's *root*, and it contains all other nodes in the tree (or contains nodes that contain nodes, and so on).
+
+Specifically, a node consists of:
+
+
+ - A *header*, which is always exactly two numbers:
+
+ - The quantity of child nodes.
+ - The quantity of metadata entries.
+
+ - Zero or more *child nodes* (as specified in the header).
+ - One or more *metadata entries* (as specified in the header).
+
+Each child node is itself a node that has its own header, child nodes, and metadata. For example:
+
+```
+2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2
+A----------------------------------
+ B----------- C-----------
+ D-----
+```
+
+In this example, each node of the tree is also marked with an underline starting with a letter for easier identification. In it, there are four nodes:
+
+
+ - `A`, which has `2` child nodes (`B`, `C`) and `3` metadata entries (`1`, `1`, `2`).
+ - `B`, which has `0` child nodes and `3` metadata entries (`10`, `11`, `12`).
+ - `C`, which has `1` child node (`D`) and `1` metadata entry (`2`).
+ - `D`, which has `0` child nodes and `1` metadata entry (`99`).
+
+The first check done on the license file is to simply add up all of the metadata entries. In this example, that sum is `1+1+2+10+11+12+2+99=*138*`.
+
+*What is the sum of all metadata entries?*
+
+
+## --- Part Two ---
+The second check is slightly more complicated: you need to find the value of the root node (`A` in the example above).
+
+The *value of a node* depends on whether it has child nodes.
+
+If a node has *no child nodes*, its value is the sum of its metadata entries. So, the value of node `B` is `10+11+12=33`, and the value of node `D` is `99`.
+
+However, if a node *does have child nodes*, the metadata entries become indexes which refer to those child nodes. A metadata entry of `1` refers to the first child node, `2` to the second, `3` to the third, and so on. The value of this node is the sum of the values of the child nodes referenced by the metadata entries. If a referenced child node does not exist, that reference is skipped. A child node can be referenced multiple time and counts each time it is referenced. A metadata entry of `0` does not refer to any child node.
+
+For example, again using the above nodes:
+
+
+ - Node `C` has one metadata entry, `2`. Because node `C` has only one child node, `2` references a child node which does not exist, and so the value of node `C` is `0`.
+ - Node `A` has three metadata entries: `1`, `1`, and `2`. The `1` references node `A`'s first child node, `B`, and the `2` references node `A`'s second child node, `C`. Because node B has a value of `33` and node `C` has a value of `0`, the value of node `A` is `33+33+0=*66*`.
+
+So, in this example, the value of the root node is `66`.
+
+*What is the value of the root node?*
+
+
diff --git a/2018/Day08/input.in b/2018/Day08/input.in
index 01888be79..6122a2b4a 100644
Binary files a/2018/Day08/input.in and b/2018/Day08/input.in differ
diff --git a/2018/Day09/README.md b/2018/Day09/README.md
index 750be53b5..a0ba94431 100644
--- a/2018/Day09/README.md
+++ b/2018/Day09/README.md
@@ -1,6 +1,63 @@
+original source: [https://adventofcode.com/2018/day/9](https://adventofcode.com/2018/day/9)
## --- Day 9: Marble Mania ---
You talk to the Elves while you wait for your navigation system to initialize. To pass the time, they introduce you to their favorite [marble](https://en.wikipedia.org/wiki/Marble_(toy)) game.
The Elves play this game by taking turns arranging the marbles in a *circle* according to very particular rules. The marbles are numbered starting with `0` and increasing by `1` until every marble has a number.
-Read the [full puzzle](https://adventofcode.com/2018/day/9).
\ No newline at end of file
+First, the marble numbered `0` is placed in the circle. At this point, while it contains only a single marble, it is still a circle: the marble is both clockwise from itself and counter-clockwise from itself. This marble is designated the *current marble*.
+
+Then, each Elf takes a turn placing the *lowest-numbered remaining marble* into the circle between the marbles that are `1` and `2` marbles *clockwise* of the current marble. (When the circle is large enough, this means that there is one marble between the marble that was just placed and the current marble.) The marble that was just placed then becomes the *current marble*.
+
+However, if the marble that is about to be placed has a number which is a multiple of `23`, *something entirely different happens*. First, the current player keeps the marble they would have placed, adding it to their *score*. In addition, the marble `7` marbles *counter-clockwise* from the current marble is *removed* from the circle and *also* added to the current player's score. The marble located immediately *clockwise* of the marble that was removed becomes the new *current marble*.
+
+For example, suppose there are 9 players. After the marble with value `0` is placed in the middle, each player (shown in square brackets) takes a turn. The result of each of those turns would produce circles of marbles like this, where clockwise is to the right and the resulting current marble is in parentheses:
+
+```
+[-] *(0)*
+[1] 0* (1)*
+[2] 0* (2)* 1
+[3] 0 2 1* (3)*
+[4] 0* (4)* 2 1 3
+[5] 0 4 2* (5)* 1 3
+[6] 0 4 2 5 1* (6)* 3
+[7] 0 4 2 5 1 6 3* (7)*
+[8] 0* (8)* 4 2 5 1 6 3 7
+[9] 0 8 4* (9)* 2 5 1 6 3 7
+[1] 0 8 4 9 2*(10)* 5 1 6 3 7
+[2] 0 8 4 9 2 10 5*(11)* 1 6 3 7
+[3] 0 8 4 9 2 10 5 11 1*(12)* 6 3 7
+[4] 0 8 4 9 2 10 5 11 1 12 6*(13)* 3 7
+[5] 0 8 4 9 2 10 5 11 1 12 6 13 3*(14)* 7
+[6] 0 8 4 9 2 10 5 11 1 12 6 13 3 14 7*(15)*
+[7] 0*(16)* 8 4 9 2 10 5 11 1 12 6 13 3 14 7 15
+[8] 0 16 8*(17)* 4 9 2 10 5 11 1 12 6 13 3 14 7 15
+[9] 0 16 8 17 4*(18)* 9 2 10 5 11 1 12 6 13 3 14 7 15
+[1] 0 16 8 17 4 18 9*(19)* 2 10 5 11 1 12 6 13 3 14 7 15
+[2] 0 16 8 17 4 18 9 19 2*(20)*10 5 11 1 12 6 13 3 14 7 15
+[3] 0 16 8 17 4 18 9 19 2 20 10*(21)* 5 11 1 12 6 13 3 14 7 15
+[4] 0 16 8 17 4 18 9 19 2 20 10 21 5*(22)*11 1 12 6 13 3 14 7 15
+[5] 0 16 8 17 4 18*(19)* 2 20 10 21 5 22 11 1 12 6 13 3 14 7 15
+[6] 0 16 8 17 4 18 19 2*(24)*20 10 21 5 22 11 1 12 6 13 3 14 7 15
+[7] 0 16 8 17 4 18 19 2 24 20*(25)*10 21 5 22 11 1 12 6 13 3 14 7 15
+```
+
+The goal is to be the *player with the highest score* after the last marble is used up. Assuming the example above ends after the marble numbered `25`, the winning score is `23+9=*32*` (because player 5 kept marble `23` and removed marble `9`, while no other player got any points in this very short example game).
+
+Here are a few more examples:
+
+
+ - `10` players; last marble is worth `1618` points: high score is *`8317`*
+ - `13` players; last marble is worth `7999` points: high score is *`146373`*
+ - `17` players; last marble is worth `1104` points: high score is *`2764`*
+ - `21` players; last marble is worth `6111` points: high score is *`54718`*
+ - `30` players; last marble is worth `5807` points: high score is *`37305`*
+
+*What is the winning Elf's score?*
+
+
+## --- Part Two ---
+Amused by the speed of your answer, the Elves are curious:
+
+*What would the winning Elf's score be if the number of the last marble were 100 times larger?*
+
+
diff --git a/2018/Day09/input.in b/2018/Day09/input.in
index ec6953af2..fa06400e0 100644
Binary files a/2018/Day09/input.in and b/2018/Day09/input.in differ
diff --git a/2018/Day10/README.md b/2018/Day10/README.md
index 867a88d43..f8e8081c4 100644
--- a/2018/Day10/README.md
+++ b/2018/Day10/README.md
@@ -1,6 +1,155 @@
+original source: [https://adventofcode.com/2018/day/10](https://adventofcode.com/2018/day/10)
## --- Day 10: The Stars Align ---
It's no use; your navigation system simply isn't capable of providing walking directions in the arctic circle, and certainly not in 1018.
The Elves suggest an alternative. In times like these, North Pole rescue operations will arrange points of light in the sky to guide missing Elves back to base. Unfortunately, the message is easy to miss: the points move slowly enough that it takes hours to align them, but have so much momentum that they only stay aligned for a second. If you blink at the wrong time, it might be hours before another message appears.
-Read the [full puzzle](https://adventofcode.com/2018/day/10).
\ No newline at end of file
+You can see these points of light floating in the distance, and record their position in the sky and their velocity, the relative change in position per second (your puzzle input). The coordinates are all given from your perspective; given enough time, those positions and velocities will move the points into a cohesive message!
+
+Rather than wait, you decide to fast-forward the process and calculate what the points will eventually spell.
+
+For example, suppose you note the following points:
+
+```
+position=< 9, 1> velocity=< 0, 2>
+position=< 7, 0> velocity=<-1, 0>
+position=< 3, -2> velocity=<-1, 1>
+position=< 6, 10> velocity=<-2, -1>
+position=< 2, -4> velocity=< 2, 2>
+position=<-6, 10> velocity=< 2, -2>
+position=< 1, 8> velocity=< 1, -1>
+position=< 1, 7> velocity=< 1, 0>
+position=<-3, 11> velocity=< 1, -2>
+position=< 7, 6> velocity=<-1, -1>
+position=<-2, 3> velocity=< 1, 0>
+position=<-4, 3> velocity=< 2, 0>
+position=<10, -3> velocity=<-1, 1>
+position=< 5, 11> velocity=< 1, -2>
+position=< 4, 7> velocity=< 0, -1>
+position=< 8, -2> velocity=< 0, 1>
+position=<15, 0> velocity=<-2, 0>
+position=< 1, 6> velocity=< 1, 0>
+position=< 8, 9> velocity=< 0, -1>
+position=< 3, 3> velocity=<-1, 1>
+position=< 0, 5> velocity=< 0, -1>
+position=<-2, 2> velocity=< 2, 0>
+position=< 5, -2> velocity=< 1, 2>
+position=< 1, 4> velocity=< 2, 1>
+position=<-2, 7> velocity=< 2, -2>
+position=< 3, 6> velocity=<-1, -1>
+position=< 5, 0> velocity=< 1, 0>
+position=<-6, 0> velocity=< 2, 0>
+position=< 5, 9> velocity=< 1, -2>
+position=<14, 7> velocity=<-2, 0>
+position=<-3, 6> velocity=< 2, -1>
+```
+
+Each line represents one point. Positions are given as `#
), open cavern (.
), and starting position of every Goblin (G
) and Elf (E
) (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2018/day/15).
\ No newline at end of file
+Combat proceeds in rounds; in each round, each unit that is still alive takes a turn, resolving all of its actions before the next unit's turn begins. On each unit's turn, it tries to move into range of an enemy (if it isn't already) and then attack (if it is in range).
+
+All units are very disciplined and always follow very strict combat rules. Units never move or attack diagonally, as doing so would be dishonorable. When multiple choices are equally valid, ties are broken in reading order: top-to-bottom, then left-to-right. For instance, the order in which units take their turns within a round is the reading order of their starting positions in that round, regardless of the type of unit or whether other units have moved after the round started. For example:
+
+
+ would take their
+These units: turns in this order:
+ ####### #######
+ #.G.E.# #.1.2.#
+ #E.G.E# #3.4.5#
+ #.G.E.# #.6.7.#
+ ####### #######
+
+
+
+Each unit begins its turn by identifying all possible targets (enemy units). If no targets remain, combat ends.
+
+Then, the unit identifies all of the open squares (.
) that are in range of each target; these are the squares which are adjacent (immediately up, down, left, or right) to any target and which aren't already occupied by a wall or another unit. Alternatively, the unit might already be in range of a target. If the unit is not already in range of a target, and there are no open squares which are in range of a target, the unit ends its turn.
+
+If the unit is already in range of a target, it does not move, but continues its turn with an attack. Otherwise, since it is not in range of a target, it moves.
+
+To move, the unit first considers the squares that are in range and determines which of those squares it could reach in the fewest steps. A step is a single movement to any adjacent (immediately up, down, left, or right) open (.
) square. Units cannot move into walls or other units. The unit does this while considering the current positions of units and does not do any prediction about where units will be later. If the unit cannot reach (find an open path to) any of the squares that are in range, it ends its turn. If multiple squares are in range and tied for being reachable in the fewest steps, the square which is first in reading order is chosen. For example:
+
+
+Targets: In range: Reachable: Nearest: Chosen:
+####### ####### ####### ####### #######
+#E..G.# #E.?G?# #E.@G.# #E.!G.# #E.+G.#
+#...#.# --> #.?.#?# --> #.@.#.# --> #.!.#.# --> #...#.#
+#.G.#G# #?G?#G# #@G@#G# #!G.#G# #.G.#G#
+####### ####### ####### ####### #######
+
+
+
+In the above scenario, the Elf has three targets (the three Goblins):
+
+
+ - Each of the Goblins has open, adjacent squares which are in range (marked with a ?
on the map).
+ - Of those squares, four are reachable (marked @
); the other two (on the right) would require moving through a wall or unit to reach.
+ - Three of these reachable squares are nearest, requiring the fewest steps (only 2
) to reach (marked !
).
+ - Of those, the square which is first in reading order is chosen (+
).
+
+The unit then takes a single step toward the chosen square along the shortest path to that square. If multiple steps would put the unit equally closer to its destination, the unit chooses the step which is first in reading order. (This requires knowing when there is more than one shortest path so that you can consider the first step of each such path.) For example:
+
+
+In range: Nearest: Chosen: Distance: Step:
+####### ####### ####### ####### #######
+#.E...# #.E...# #.E...# #4E212# #..E..#
+#...?.# --> #...!.# --> #...+.# --> #32101# --> #.....#
+#..?G?# #..!G.# #...G.# #432G2# #...G.#
+####### ####### ####### ####### #######
+
+
+
+The Elf sees three squares in range of a target (?
), two of which are nearest (!
), and so the first in reading order is chosen (+
). Under "Distance", each open square is marked with its distance from the destination square; the two squares to which the Elf could move on this turn (down and to the right) are both equally good moves and would leave the Elf 2
steps from being in range of the Goblin. Because the step which is first in reading order is chosen, the Elf moves right one square.
+
+Here's a larger example of movement:
+
+
+Initially:
+#########
+#G..G..G#
+#.......#
+#.......#
+#G..E..G#
+#.......#
+#.......#
+#G..G..G#
+#########
+
+After 1 round:
+#########
+#.G...G.#
+#...G...#
+#...E..G#
+#.G.....#
+#.......#
+#G..G..G#
+#.......#
+#########
+
+After 2 rounds:
+#########
+#..G.G..#
+#...G...#
+#.G.E.G.#
+#.......#
+#G..G..G#
+#.......#
+#.......#
+#########
+
+After 3 rounds:
+#########
+#.......#
+#..GGG..#
+#..GEG..#
+#G..G...#
+#......G#
+#.......#
+#.......#
+#########
+
+
+
+Once the Goblins and Elf reach the positions above, they all are either in range of a target or cannot find any square in range of a target, and so none of the units can move until a unit dies.
+
+After moving (or if the unit began its turn in range of a target), the unit attacks.
+
+To attack, the unit first determines all of the targets that are in range of it by being immediately adjacent to it. If there are no such targets, the unit ends its turn. Otherwise, the adjacent target with the fewest hit points is selected; in a tie, the adjacent target with the fewest hit points which is first in reading order is selected.
+
+The unit deals damage equal to its attack power to the selected target, reducing its hit points by that amount. If this reduces its hit points to 0
or fewer, the selected target dies: its square becomes .
and it takes no further turns.
+
+Each unit, either Goblin or Elf, has 3
attack power and starts with 200
hit points.
+
+For example, suppose the only Elf is about to attack:
+
+
+ HP: HP:
+G.... 9 G.... 9
+..G.. 4 ..G.. 4
+..EG. 2 --> ..E..
+..G.. 2 ..G.. 2
+...G. 1 ...G. 1
+
+
+
+The "HP" column shows the hit points of the Goblin to the left in the corresponding row. The Elf is in range of three targets: the Goblin above it (with 4
hit points), the Goblin to its right (with 2
hit points), and the Goblin below it (also with 2
hit points). Because three targets are in range, the ones with the lowest hit points are selected: the two Goblins with 2
hit points each (one to the right of the Elf and one below the Elf). Of those, the Goblin first in reading order (the one to the right of the Elf) is selected. The selected Goblin's hit points (2
) are reduced by the Elf's attack power (3
), reducing its hit points to -1
, killing it.
+
+After attacking, the unit's turn ends. Regardless of how the unit's turn ends, the next unit in the round takes its turn. If all units have taken turns in this round, the round ends, and a new round begins.
+
+The Elves look quite outnumbered. You need to determine the outcome of the battle: the number of full rounds that were completed (not counting the round in which combat ends) multiplied by the sum of the hit points of all remaining units at the moment combat ends. (Combat only ends when a unit finds no targets during its turn.)
+
+Below is an entire sample combat. Next to each map, each row's units' hit points are listed from left to right.
+
+
+Initially:
+#######
+#.G...# G(200)
+#...EG# E(200), G(200)
+#.#.#G# G(200)
+#..G#E# G(200), E(200)
+#.....#
+#######
+
+After 1 round:
+#######
+#..G..# G(200)
+#...EG# E(197), G(197)
+#.#G#G# G(200), G(197)
+#...#E# E(197)
+#.....#
+#######
+
+After 2 rounds:
+#######
+#...G.# G(200)
+#..GEG# G(200), E(188), G(194)
+#.#.#G# G(194)
+#...#E# E(194)
+#.....#
+#######
+
+Combat ensues; eventually, the top Elf dies:
+
+After 23 rounds:
+#######
+#...G.# G(200)
+#..G.G# G(200), G(131)
+#.#.#G# G(131)
+#...#E# E(131)
+#.....#
+#######
+
+After 24 rounds:
+#######
+#..G..# G(200)
+#...G.# G(131)
+#.#G#G# G(200), G(128)
+#...#E# E(128)
+#.....#
+#######
+
+After 25 rounds:
+#######
+#.G...# G(200)
+#..G..# G(131)
+#.#.#G# G(125)
+#..G#E# G(200), E(125)
+#.....#
+#######
+
+After 26 rounds:
+#######
+#G....# G(200)
+#.G...# G(131)
+#.#.#G# G(122)
+#...#E# E(122)
+#..G..# G(200)
+#######
+
+After 27 rounds:
+#######
+#G....# G(200)
+#.G...# G(131)
+#.#.#G# G(119)
+#...#E# E(119)
+#...G.# G(200)
+#######
+
+After 28 rounds:
+#######
+#G....# G(200)
+#.G...# G(131)
+#.#.#G# G(116)
+#...#E# E(113)
+#....G# G(200)
+#######
+
+More combat ensues; eventually, the bottom Elf dies:
+
+After 47 rounds:
+#######
+#G....# G(200)
+#.G...# G(131)
+#.#.#G# G(59)
+#...#.#
+#....G# G(200)
+#######
+
+
+
+Before the 48th round can finish, the top-left Goblin finds that there are no targets remaining, and so combat ends. So, the number of full rounds that were completed is 47
, and the sum of the hit points of all remaining units is 200+131+59+200 = 590
. From these, the outcome of the battle is 47 * 590 = 27730
.
+
+Here are a few example summarized combats:
+
+
+####### #######
+#G..#E# #...#E# E(200)
+#E#E.E# #E#...# E(197)
+#G.##.# --> #.E##.# E(185)
+#...#E# #E..#E# E(200), E(200)
+#...E.# #.....#
+####### #######
+
+Combat ends after 37 full rounds
+Elves win with 982 total hit points left
+Outcome: 37 * 982 = 36334
+
+
+
+
+####### #######
+#E..EG# #.E.E.# E(164), E(197)
+#.#G.E# #.#E..# E(200)
+#E.##E# --> #E.##.# E(98)
+#G..#.# #.E.#.# E(200)
+#..E#.# #...#.#
+####### #######
+
+Combat ends after 46 full rounds
+Elves win with 859 total hit points left
+Outcome: 46 * 859 = 39514
+
+
+
+
+####### #######
+#E.G#.# #G.G#.# G(200), G(98)
+#.#G..# #.#G..# G(200)
+#G.#.G# --> #..#..#
+#G..#.# #...#G# G(95)
+#...E.# #...G.# G(200)
+####### #######
+
+Combat ends after 35 full rounds
+Goblins win with 793 total hit points left
+Outcome: 35 * 793 = 27755
+
+
+
+
+####### #######
+#.E...# #.....#
+#.#..G# #.#G..# G(200)
+#.###.# --> #.###.#
+#E#G#G# #.#.#.#
+#...#G# #G.G#G# G(98), G(38), G(200)
+####### #######
+
+Combat ends after 54 full rounds
+Goblins win with 536 total hit points left
+Outcome: 54 * 536 = 28944
+
+
+
+
+######### #########
+#G......# #.G.....# G(137)
+#.E.#...# #G.G#...# G(200), G(200)
+#..##..G# #.G##...# G(200)
+#...##..# --> #...##..#
+#...#...# #.G.#...# G(200)
+#.G...G.# #.......#
+#.....G.# #.......#
+######### #########
+
+Combat ends after 20 full rounds
+Goblins win with 937 total hit points left
+Outcome: 20 * 937 = 18740
+
+
+
+What is the outcome of the combat described in your puzzle input?
+
+
+## --- Part Two ---
+According to your calculations, the Elves are going to lose badly. Surely, you won't mess up the timeline too much if you give them just a little advanced technology, right?
+
+You need to make sure the Elves not only win, but also suffer no losses: even the death of a single Elf is unacceptable.
+
+However, you can't go too far: larger changes will be more likely to permanently alter spacetime.
+
+So, you need to find the outcome of the battle in which the Elves have the lowest integer attack power (at least 4
) that allows them to win without a single death. The Goblins always have an attack power of 3
.
+
+In the first summarized example above, the lowest attack power the Elves need to win without losses is 15
:
+
+
+####### #######
+#.G...# #..E..# E(158)
+#...EG# #...E.# E(14)
+#.#.#G# --> #.#.#.#
+#..G#E# #...#.#
+#.....# #.....#
+####### #######
+
+Combat ends after 29 full rounds
+Elves win with 172 total hit points left
+Outcome: 29 * 172 = 4988
+
+
+
+In the second example above, the Elves need only 4
attack power:
+
+
+####### #######
+#E..EG# #.E.E.# E(200), E(23)
+#.#G.E# #.#E..# E(200)
+#E.##E# --> #E.##E# E(125), E(200)
+#G..#.# #.E.#.# E(200)
+#..E#.# #...#.#
+####### #######
+
+Combat ends after 33 full rounds
+Elves win with 948 total hit points left
+Outcome: 33 * 948 = 31284
+
+
+
+In the third example above, the Elves need 15
attack power:
+
+
+####### #######
+#E.G#.# #.E.#.# E(8)
+#.#G..# #.#E..# E(86)
+#G.#.G# --> #..#..#
+#G..#.# #...#.#
+#...E.# #.....#
+####### #######
+
+Combat ends after 37 full rounds
+Elves win with 94 total hit points left
+Outcome: 37 * 94 = 3478
+
+
+
+In the fourth example above, the Elves need 12
attack power:
+
+
+####### #######
+#.E...# #...E.# E(14)
+#.#..G# #.#..E# E(152)
+#.###.# --> #.###.#
+#E#G#G# #.#.#.#
+#...#G# #...#.#
+####### #######
+
+Combat ends after 39 full rounds
+Elves win with 166 total hit points left
+Outcome: 39 * 166 = 6474
+
+
+
+In the last example above, the lone Elf needs 34
attack power:
+
+
+######### #########
+#G......# #.......#
+#.E.#...# #.E.#...# E(38)
+#..##..G# #..##...#
+#...##..# --> #...##..#
+#...#...# #...#...#
+#.G...G.# #.......#
+#.....G.# #.......#
+######### #########
+
+Combat ends after 30 full rounds
+Elves win with 38 total hit points left
+Outcome: 30 * 38 = 1140
+
+
+
+After increasing the Elves' attack power until it is just barely enough for them to win without any Elves dying, what is the outcome of the combat described in your puzzle input?
+
+
diff --git a/2018/Day15/input.in b/2018/Day15/input.in
index 0ea43d55c..867d0aa68 100644
Binary files a/2018/Day15/input.in and b/2018/Day15/input.in differ
diff --git a/2018/Day16/README.md b/2018/Day16/README.md
index 0c41ed9df..59403e204 100644
--- a/2018/Day16/README.md
+++ b/2018/Day16/README.md
@@ -1,6 +1,88 @@
+original source: [https://adventofcode.com/2018/day/16](https://adventofcode.com/2018/day/16)
## --- Day 16: Chronal Classification ---
As you see the Elves defend their hot chocolate successfully, you go back to falling through time. This is going to become a problem.
If you're ever going to return to your own time, you need to understand how this device on your wrist works. You have a little while before you reach your next destination, and with a bit of trial and error, you manage to pull up a programming manual on the device's tiny screen.
-Read the [full puzzle](https://adventofcode.com/2018/day/16).
\ No newline at end of file
+According to the manual, the device has four [registers](https://en.wikipedia.org/wiki/Hardware_register) (numbered `0` through `3`) that can be manipulated by [instructions](https://en.wikipedia.org/wiki/Instruction_set_architecture#Instructions) containing one of 16 opcodes. The registers start with the value `0`.
+
+Every instruction consists of four values: an *opcode*, two *inputs* (named `A` and `B`), and an *output* (named `C`), in that order. The opcode specifies the behavior of the instruction and how the inputs are interpreted. The output, `C`, is always treated as a register.
+
+In the opcode descriptions below, if something says "*value `A`*", it means to take the number given as `A` *literally*. (This is also called an "immediate" value.) If something says "*register `A`*", it means to use the number given as `A` to read from (or write to) the *register with that number*. So, if the opcode `addi` adds register `A` and value `B`, storing the result in register `C`, and the instruction `addi 0 7 3` is encountered, it would add `7` to the value contained by register `0` and store the sum in register `3`, never modifying registers `0`, `1`, or `2` in the process.
+
+Many opcodes are similar except for how they interpret their arguments. The opcodes fall into seven general categories:
+
+Addition:
+
+
+ - `addr` (add register) stores into register `C` the result of adding register `A` and register `B`.
+ - `addi` (add immediate) stores into register `C` the result of adding register `A` and value `B`.
+
+Multiplication:
+
+
+ - `mulr` (multiply register) stores into register `C` the result of multiplying register `A` and register `B`.
+ - `muli` (multiply immediate) stores into register `C` the result of multiplying register `A` and value `B`.
+
+[Bitwise AND](https://en.wikipedia.org/wiki/Bitwise_AND):
+
+
+ - `banr` (bitwise AND register) stores into register `C` the result of the bitwise AND of register `A` and register `B`.
+ - `bani` (bitwise AND immediate) stores into register `C` the result of the bitwise AND of register `A` and value `B`.
+
+[Bitwise OR](https://en.wikipedia.org/wiki/Bitwise_OR):
+
+
+ - `borr` (bitwise OR register) stores into register `C` the result of the bitwise OR of register `A` and register `B`.
+ - `bori` (bitwise OR immediate) stores into register `C` the result of the bitwise OR of register `A` and value `B`.
+
+Assignment:
+
+
+ - `setr` (set register) copies the contents of register `A` into register `C`. (Input `B` is ignored.)
+ - `seti` (set immediate) stores value `A` into register `C`. (Input `B` is ignored.)
+
+Greater-than testing:
+
+
+ - `gtir` (greater-than immediate/register) sets register `C` to `1` if value `A` is greater than register `B`. Otherwise, register `C` is set to `0`.
+ - `gtri` (greater-than register/immediate) sets register `C` to `1` if register `A` is greater than value `B`. Otherwise, register `C` is set to `0`.
+ - `gtrr` (greater-than register/register) sets register `C` to `1` if register `A` is greater than register `B`. Otherwise, register `C` is set to `0`.
+
+Equality testing:
+
+
+ - `eqir` (equal immediate/register) sets register `C` to `1` if value `A` is equal to register `B`. Otherwise, register `C` is set to `0`.
+ - `eqri` (equal register/immediate) sets register `C` to `1` if register `A` is equal to value `B`. Otherwise, register `C` is set to `0`.
+ - `eqrr` (equal register/register) sets register `C` to `1` if register `A` is equal to register `B`. Otherwise, register `C` is set to `0`.
+
+Unfortunately, while the manual gives the *name* of each opcode, it doesn't seem to indicate the *number*. However, you can monitor the CPU to see the contents of the registers before and after instructions are executed to try to work them out. Each opcode has a number from `0` through `15`, but the manual doesn't say which is which. For example, suppose you capture the following sample:
+
+```
+Before: [3, 2, 1, 1]
+9 2 1 2
+After: [3, 2, 2, 1]
+```
+
+This sample shows the effect of the instruction `9 2 1 2` on the registers. Before the instruction is executed, register `0` has value `3`, register `1` has value `2`, and registers `2` and `3` have value `1`. After the instruction is executed, register `2`'s value becomes `2`.
+
+The instruction itself, `9 2 1 2`, means that opcode `9` was executed with `A=2`, `B=1`, and `C=2`. Opcode `9` could be any of the 16 opcodes listed above, but only three of them behave in a way that would cause the result shown in the sample:
+
+
+ - Opcode `9` could be `mulr`: register `2` (which has a value of `1`) times register `1` (which has a value of `2`) produces `2`, which matches the value stored in the output register, register `2`.
+ - Opcode `9` could be `addi`: register `2` (which has a value of `1`) plus value `1` produces `2`, which matches the value stored in the output register, register `2`.
+ - Opcode `9` could be `seti`: value `2` matches the value stored in the output register, register `2`; the number given for `B` is irrelevant.
+
+None of the other opcodes produce the result captured in the sample. Because of this, the sample above *behaves like three opcodes*.
+
+You collect many of these samples (the first section of your puzzle input). The manual also includes a small test program (the second section of your puzzle input) - you can *ignore it for now*.
+
+Ignoring the opcode numbers, *how many samples in your puzzle input behave like three or more opcodes?*
+
+
+## --- Part Two ---
+Using the samples you collected, work out the number of each opcode and execute the test program (the second section of your puzzle input).
+
+*What value is contained in register `0` after executing the test program?*
+
+
diff --git a/2018/Day16/input.in b/2018/Day16/input.in
index 75cac132a..9b004c04e 100644
Binary files a/2018/Day16/input.in and b/2018/Day16/input.in differ
diff --git a/2018/Day17/README.md b/2018/Day17/README.md
index 16a5873ac..38d4bdc86 100644
--- a/2018/Day17/README.md
+++ b/2018/Day17/README.md
@@ -1,6 +1,179 @@
+original source: [https://adventofcode.com/2018/day/17](https://adventofcode.com/2018/day/17)
## --- Day 17: Reservoir Research ---
You arrive in the year 18. If it weren't for the coat you got in 1018, you would be very cold: the North Pole base hasn't even been constructed.
Rather, it hasn't been constructed *yet*. The Elves are making a little progress, but there's not a lot of liquid water in this climate, so they're getting very dehydrated. Maybe there's more underground?
-Read the [full puzzle](https://adventofcode.com/2018/day/17).
\ No newline at end of file
+You scan a two-dimensional vertical slice of the ground nearby and discover that it is mostly *sand* with veins of *clay*. The scan only provides data with a granularity of *square meters*, but it should be good enough to determine how much water is trapped there. In the scan, `x` represents the distance to the right, and `y` represents the distance down. There is also a *spring of water* near the surface at `x=500, y=0`. The scan identifies *which square meters are clay* (your puzzle input).
+
+For example, suppose your scan shows the following veins of clay:
+
+```
+x=495, y=2..7
+y=7, x=495..501
+x=501, y=3..7
+x=498, y=2..4
+x=506, y=1..2
+x=498, y=10..13
+x=504, y=10..13
+y=13, x=498..504
+```
+
+Rendering clay as `#`, sand as `.`, and the water spring as `+`, and with `x` increasing to the right and `y` increasing downward, this becomes:
+
+```
+ 44444455555555
+ 99999900000000
+ 45678901234567
+ 0 ......+.......
+ 1 ............#.
+ 2 .#..#.......#.
+ 3 .#..#..#......
+ 4 .#..#..#......
+ 5 .#.....#......
+ 6 .#.....#......
+ 7 .#######......
+ 8 ..............
+ 9 ..............
+10 ....#.....#...
+11 ....#.....#...
+12 ....#.....#...
+13 ....#######...
+```
+
+The spring of water will produce water *forever*. Water can move through sand, but is blocked by clay. Water *always moves down* when possible, and spreads to the left and right otherwise, filling space that has clay on both sides and falling out otherwise.
+
+For example, if five squares of water are created, they will flow downward until they reach the clay and settle there. Water that has come to rest is shown here as `~`, while sand through which water has passed (but which is now dry again) is shown as `|`:
+
+```
+......+.......
+......|.....#.
+.#..#.|.....#.
+.#..#.|#......
+.#..#.|#......
+.#....|#......
+.#~~~~~#......
+.#######......
+..............
+..............
+....#.....#...
+....#.....#...
+....#.....#...
+....#######...
+```
+
+Two squares of water can't occupy the same location. If another five squares of water are created, they will settle on the first five, filling the clay reservoir a little more:
+
+```
+......+.......
+......|.....#.
+.#..#.|.....#.
+.#..#.|#......
+.#..#.|#......
+.#~~~~~#......
+.#~~~~~#......
+.#######......
+..............
+..............
+....#.....#...
+....#.....#...
+....#.....#...
+....#######...
+```
+
+Water pressure does not apply in this scenario. If another four squares of water are created, they will stay on the right side of the barrier, and no water will reach the left side:
+
+```
+......+.......
+......|.....#.
+.#..#.|.....#.
+.#..#~~#......
+.#..#~~#......
+.#~~~~~#......
+.#~~~~~#......
+.#######......
+..............
+..............
+....#.....#...
+....#.....#...
+....#.....#...
+....#######...
+```
+
+At this point, the top reservoir overflows. While water can reach the tiles above the surface of the water, it cannot settle there, and so the next five squares of water settle like this:
+
+```
+......+.......
+......|.....#.
+.#..#*|*|||...#.
+.#..#~~#|.....
+.#..#~~#|.....
+.#~~~~~#|.....
+.#~~~~~#|.....
+.#######|.....
+........|.....
+........|.....
+....#...|.#...
+....#...|.#...
+....#~~~~~#...
+....#######...
+```
+
+Note especially the leftmost `|`: the new squares of water can reach this tile, but cannot stop there. Instead, eventually, they all fall to the right and settle in the reservoir below.
+
+After 10 more squares of water, the bottom reservoir is also full:
+
+```
+......+.......
+......|.....#.
+.#..#||||...#.
+.#..#~~#|.....
+.#..#~~#|.....
+.#~~~~~#|.....
+.#~~~~~#|.....
+.#######|.....
+........|.....
+........|.....
+....#~~~~~#...
+....#~~~~~#...
+....#~~~~~#...
+....#######...
+```
+
+Finally, while there is nowhere left for the water to settle, it can reach a few more tiles before overflowing beyond the bottom of the scanned data:
+
+```
+......+....... (line not counted: above minimum y value)
+......|.....#.
+.#..#||||...#.
+.#..#~~#|.....
+.#..#~~#|.....
+.#~~~~~#|.....
+.#~~~~~#|.....
+.#######|.....
+........|.....
+...|||||||||..
+...|#~~~~~#|..
+...|#~~~~~#|..
+...|#~~~~~#|..
+...|#######|..
+...|.......|.. (line not counted: below maximum y value)
+...|.......|.. (line not counted: below maximum y value)
+...|.......|.. (line not counted: below maximum y value)
+```
+
+How many tiles can be reached by the water? *To prevent counting forever*, ignore tiles with a `y` coordinate smaller than the smallest `y` coordinate in your scan data or larger than the largest one. Any `x` coordinate is valid. In this example, the lowest `y` coordinate given is `1`, and the highest is `13`, causing the water spring (in row `0`) and the water falling off the bottom of the render (in rows `14` through infinity) to be ignored.
+
+So, in the example above, counting both water at rest (`~`) and other sand tiles the water can hypothetically reach (`|`), the total number of tiles the water can reach is `*57*`.
+
+*How many tiles can the water reach* within the range of `y` values in your scan?
+
+
+## --- Part Two ---
+After a very long time, the water spring will run dry. How much water will be retained?
+
+In the example above, water that won't eventually drain out is shown as `~`, a total of `*29*` tiles.
+
+*How many water tiles are left* after the water spring stops producing water and all remaining water not at rest has drained?
+
+
diff --git a/2018/Day17/input.in b/2018/Day17/input.in
index 47120cff7..988a8b289 100644
Binary files a/2018/Day17/input.in and b/2018/Day17/input.in differ
diff --git a/2018/Day18/README.md b/2018/Day18/README.md
index 10baaa900..66420ad69 100644
--- a/2018/Day18/README.md
+++ b/2018/Day18/README.md
@@ -1,6 +1,166 @@
+original source: [https://adventofcode.com/2018/day/18](https://adventofcode.com/2018/day/18)
## --- Day 18: Settlers of The North Pole ---
On the outskirts of the North Pole base construction project, many Elves are collecting lumber.
The lumber collection area is 50 acres by 50 acres; each acre can be either *open ground* (`.`), *trees* (`|`), or a *lumberyard* (`#`). You take a scan of the area (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2018/day/18).
\ No newline at end of file
+Strange magic is at work here: each minute, the landscape looks entirely different. In exactly *one minute*, an open acre can fill with trees, a wooded acre can be converted to a lumberyard, or a lumberyard can be cleared to open ground (the lumber having been sent to other projects).
+
+The change to each acre is based entirely on *the contents of that acre* as well as *the number of open, wooded, or lumberyard acres adjacent to it* at the start of each minute. Here, "adjacent" means any of the eight acres surrounding that acre. (Acres on the edges of the lumber collection area might have fewer than eight adjacent acres; the missing acres aren't counted.)
+
+In particular:
+
+
+ - An *open* acre will become filled with *trees* if *three or more* adjacent acres contained trees. Otherwise, nothing happens.
+ - An acre filled with *trees* will become a *lumberyard* if *three or more* adjacent acres were lumberyards. Otherwise, nothing happens.
+ - An acre containing a *lumberyard* will remain a *lumberyard* if it was adjacent to *at least one other lumberyard and at least one acre containing trees*. Otherwise, it becomes *open*.
+
+These changes happen across all acres *simultaneously*, each of them using the state of all acres at the beginning of the minute and changing to their new form by the end of that same minute. Changes that happen during the minute don't affect each other.
+
+For example, suppose the lumber collection area is instead only 10 by 10 acres with this initial configuration:
+
+```
+Initial state:
+.#.#...|#.
+.....#|##|
+.|..|...#.
+..|#.....#
+#.#|||#|#|
+...#.||...
+.|....|...
+||...#|.#|
+|.||||..|.
+...#.|..|.
+
+After 1 minute:
+.......##.
+......|###
+.|..|...#.
+..|#||...#
+..##||.|#|
+...#||||..
+||...|||..
+|||||.||.|
+||||||||||
+....||..|.
+
+After 2 minutes:
+.......#..
+......|#..
+.|.|||....
+..##|||..#
+..###|||#|
+...#|||||.
+|||||||||.
+||||||||||
+||||||||||
+.|||||||||
+
+After 3 minutes:
+.......#..
+....|||#..
+.|.||||...
+..###|||.#
+...##|||#|
+.||##|||||
+||||||||||
+||||||||||
+||||||||||
+||||||||||
+
+After 4 minutes:
+.....|.#..
+...||||#..
+.|.#||||..
+..###||||#
+...###||#|
+|||##|||||
+||||||||||
+||||||||||
+||||||||||
+||||||||||
+
+After 5 minutes:
+....|||#..
+...||||#..
+.|.##||||.
+..####|||#
+.|.###||#|
+|||###||||
+||||||||||
+||||||||||
+||||||||||
+||||||||||
+
+After 6 minutes:
+...||||#..
+...||||#..
+.|.###|||.
+..#.##|||#
+|||#.##|#|
+|||###||||
+||||#|||||
+||||||||||
+||||||||||
+||||||||||
+
+After 7 minutes:
+...||||#..
+..||#|##..
+.|.####||.
+||#..##||#
+||##.##|#|
+|||####|||
+|||###||||
+||||||||||
+||||||||||
+||||||||||
+
+After 8 minutes:
+..||||##..
+..|#####..
+|||#####|.
+||#...##|#
+||##..###|
+||##.###||
+|||####|||
+||||#|||||
+||||||||||
+||||||||||
+
+After 9 minutes:
+..||###...
+.||#####..
+||##...##.
+||#....###
+|##....##|
+||##..###|
+||######||
+|||###||||
+||||||||||
+||||||||||
+
+After 10 minutes:
+.||##.....
+||###.....
+||##......
+|##.....##
+|##.....##
+|##....##|
+||##.####|
+||#####|||
+||||#|||||
+||||||||||
+```
+
+After 10 minutes, there are `37` wooded acres and `31` lumberyards. Multiplying the number of wooded acres by the number of lumberyards gives the total *resource value* after ten minutes: `37 * 31 = *1147*`.
+
+*What will the total resource value of the lumber collection area be after 10 minutes?*
+
+
+## --- Part Two ---
+This important natural resource will need to last for at least thousands of years. Are the Elves collecting this lumber sustainably?
+
+*What will the total resource value of the lumber collection area be after 1000000000 minutes?*
+
+
diff --git a/2018/Day18/input.in b/2018/Day18/input.in
index 5babc989e..c5a08e93a 100644
Binary files a/2018/Day18/input.in and b/2018/Day18/input.in differ
diff --git a/2018/Day19/README.md b/2018/Day19/README.md
index b2070b233..7930f7a49 100644
--- a/2018/Day19/README.md
+++ b/2018/Day19/README.md
@@ -1,6 +1,58 @@
+original source: [https://adventofcode.com/2018/day/19](https://adventofcode.com/2018/day/19)
## --- Day 19: Go With The Flow ---
With the Elves well on their way constructing the North Pole base, you turn your attention back to understanding the inner workings of programming the device.
You can't help but notice that the [device's opcodes](16) don't contain any *flow control* like jump instructions. The device's [manual](16) goes on to explain:
-Read the [full puzzle](https://adventofcode.com/2018/day/19).
\ No newline at end of file
+"In programs where flow control is required, the [instruction pointer](https://en.wikipedia.org/wiki/Program_counter) can be *bound to a register* so that it can be manipulated directly. This way, `setr`/`seti` can function as absolute jumps, `addr`/`addi` can function as relative jumps, and other opcodes can cause truly fascinating effects."
+
+This mechanism is achieved through a declaration like `#ip 1`, which would modify register `1` so that accesses to it let the program indirectly access the instruction pointer itself. To compensate for this kind of binding, there are now *six* registers (numbered `0` through `5`); the five not bound to the instruction pointer behave as normal. Otherwise, the same rules apply as [the last time you worked with this device](16).
+
+When the *instruction pointer* is bound to a register, its value is written to that register just before each instruction is executed, and the value of that register is written back to the instruction pointer immediately after each instruction finishes execution. Afterward, move to the next instruction by adding one to the instruction pointer, even if the value in the instruction pointer was just updated by an instruction. (Because of this, instructions must effectively set the instruction pointer to the instruction *before* the one they want executed next.)
+
+The instruction pointer is `0` during the first instruction, `1` during the second, and so on. If the instruction pointer ever causes the device to attempt to load an instruction outside the instructions defined in the program, the program instead immediately halts. The instruction pointer starts at `0`.
+
+It turns out that this new information is already proving useful: the CPU in the device is not very powerful, and a background process is occupying most of its time. You dump the background process' declarations and instructions to a file (your puzzle input), making sure to use the names of the opcodes rather than the numbers.
+
+For example, suppose you have the following program:
+
+```
+#ip 0
+seti 5 0 1
+seti 6 0 2
+addi 0 1 0
+addr 1 2 3
+setr 1 0 0
+seti 8 0 4
+seti 9 0 5
+```
+
+When executed, the following instructions are executed. Each line contains the value of the instruction pointer at the time the instruction started, the values of the six registers before executing the instructions (in square brackets), the instruction itself, and the values of the six registers after executing the instruction (also in square brackets).
+
+```
+ip=0 [0, 0, 0, 0, 0, 0] seti 5 0 1 [0, 5, 0, 0, 0, 0]
+ip=1 [1, 5, 0, 0, 0, 0] seti 6 0 2 [1, 5, 6, 0, 0, 0]
+ip=2 [2, 5, 6, 0, 0, 0] addi 0 1 0 [3, 5, 6, 0, 0, 0]
+ip=4 [4, 5, 6, 0, 0, 0] setr 1 0 0 [5, 5, 6, 0, 0, 0]
+ip=6 [6, 5, 6, 0, 0, 0] seti 9 0 5 [6, 5, 6, 0, 0, 9]
+```
+
+In detail, when running this program, the following events occur:
+
+
+ - The first line (`#ip 0`) indicates that the instruction pointer should be bound to register `0` in this program. This is not an instruction, and so the value of the instruction pointer does not change during the processing of this line.
+ - The instruction pointer contains `0`, and so the first instruction is executed (`seti 5 0 1`). It updates register `0` to the current instruction pointer value (`0`), sets register `1` to `5`, sets the instruction pointer to the value of register `0` (which has no effect, as the instruction did not modify register `0`), and then adds one to the instruction pointer.
+ - The instruction pointer contains `1`, and so the second instruction, `seti 6 0 2`, is executed. This is very similar to the instruction before it: `6` is stored in register `2`, and the instruction pointer is left with the value `2`.
+ - The instruction pointer is `2`, which points at the instruction `addi 0 1 0`. This is like a *relative jump*: the value of the instruction pointer, `2`, is loaded into register `0`. Then, `addi` finds the result of adding the value in register `0` and the value `1`, storing the result, `3`, back in register `0`. Register `0` is then copied back to the instruction pointer, which will cause it to end up `1` larger than it would have otherwise and skip the next instruction (`addr 1 2 3`) entirely. Finally, `1` is added to the instruction pointer.
+ - The instruction pointer is `4`, so the instruction `setr 1 0 0` is run. This is like an *absolute jump*: it copies the value contained in register `1`, `5`, into register `0`, which causes it to end up in the instruction pointer. The instruction pointer is then incremented, leaving it at `6`.
+ - The instruction pointer is `6`, so the instruction `seti 9 0 5` stores `9` into register `5`. The instruction pointer is incremented, causing it to point outside the program, and so the program ends.
+
+*What value is left in register `0`* when the background process halts?
+
+
+## --- Part Two ---
+A new background process immediately spins up in its place. It appears identical, but on closer inspection, you notice that *this time, register `0` started with the value `1`*.
+
+*What value is left in register `0`* when this new background process halts?
+
+
diff --git a/2018/Day19/input.in b/2018/Day19/input.in
index 07bc89717..99698801d 100644
Binary files a/2018/Day19/input.in and b/2018/Day19/input.in differ
diff --git a/2018/Day20/README.md b/2018/Day20/README.md
index 195e256fe..d1836d96d 100644
--- a/2018/Day20/README.md
+++ b/2018/Day20/README.md
@@ -1,6 +1,164 @@
+original source: [https://adventofcode.com/2018/day/20](https://adventofcode.com/2018/day/20)
## --- Day 20: A Regular Map ---
While you were learning about instruction pointers, the Elves made considerable progress. When you look up, you discover that the North Pole base construction project has completely surrounded you.
The area you are in is made up entirely of *rooms* and *doors*. The rooms are arranged in a grid, and rooms only connect to adjacent rooms when a door is present between them.
-Read the [full puzzle](https://adventofcode.com/2018/day/20).
\ No newline at end of file
+For example, drawing rooms as `.`, walls as `#`, doors as `|` or `-`, your current position as `X`, and where north is up, the area you're in might look like this:
+
+```
+#####
+#.|.#
+#-###
+#.|X#
+#####
+```
+
+You get the attention of a passing construction Elf and ask for a map. "I don't have time to draw out a map of this place - it's *huge*. Instead, I can give you directions to *every room in the facility*!" He writes down some directions on a piece of parchment and runs off. In the example above, the instructions might have been `^WNE$`, a [regular expression](https://en.wikipedia.org/wiki/Regular_expression) or "*regex*" (your puzzle input).
+
+The regex matches routes (like `WNE` for "west, north, east") that will take you from your current room through various doors in the facility. In aggregate, the routes will take you through *every door in the facility at least once*; mapping out all of these routes will let you build a proper map and find your way around.
+
+`^` and `$` are at the beginning and end of your regex; these just mean that the regex doesn't match anything outside the routes it describes. (Specifically, `^` matches the start of the route, and `$` matches the end of it.) These characters will not appear elsewhere in the regex.
+
+The rest of the regex matches various sequences of the characters `N` (north), `S` (south), `E` (east), and `W` (west). In the example above, `^WNE$` matches only one route, `WNE`, which means you can move *west, then north, then east* from your current position. Sequences of letters like this always match that exact route in the same order.
+
+Sometimes, the route can *branch*. A branch is given by a *list of options* separated by pipes (`|`) and wrapped in parentheses. So, `^N(E|W)N$` contains a branch: after going north, you must choose to go *either east or west* before finishing your route by going north again. By tracing out the possible routes after branching, you can determine where the doors are and, therefore, where the rooms are in the facility.
+
+For example, consider this regex: `^ENWWW(NEEE|SSE(EE|N))$`
+
+This regex begins with `ENWWW`, which means that from your current position, all routes must begin by moving east, north, and then west three times, in that order. After this, there is a branch. Before you consider the branch, this is what you know about the map so far, with doors you aren't sure about marked with a `?`:
+
+```
+#?#?#?#?#
+?.|.|.|.?
+#?#?#?#-#
+ ?X|.?
+ #?#?#
+```
+
+After this point, there is `(NEEE|SSE(EE|N))`. This gives you exactly two options: `NEEE` and `SSE(EE|N)`. By following `NEEE`, the map now looks like this:
+
+```
+#?#?#?#?#
+?.|.|.|.?
+#-#?#?#?#
+?.|.|.|.?
+#?#?#?#-#
+ ?X|.?
+ #?#?#
+```
+
+Now, only `SSE(EE|N)` remains. Because it is in the same parenthesized group as `NEEE`, it starts from the same room `NEEE` started in. It states that starting from that point, there exist doors which will allow you to move south twice, then east; this ends up at another branch. After that, you can either move east twice or north once. This information fills in the rest of the doors:
+
+```
+#?#?#?#?#
+?.|.|.|.?
+#-#?#?#?#
+?.|.|.|.?
+#-#?#?#-#
+?.?.?X|.?
+#-#-#?#?#
+?.|.|.|.?
+#?#?#?#?#
+```
+
+Once you've followed all possible routes, you know the remaining unknown parts are all walls, producing a finished map of the facility:
+
+```
+#########
+#.|.|.|.#
+#-#######
+#.|.|.|.#
+#-#####-#
+#.#.#X|.#
+#-#-#####
+#.|.|.|.#
+#########
+```
+
+Sometimes, a list of options can have an *empty option*, like `(NEWS|WNSE|)`. This means that routes at this point could effectively skip the options in parentheses and move on immediately. For example, consider this regex and the corresponding map:
+
+```
+^ENNWSWW(NEWS|)SSSEEN(WNSE|)EE(SWEN|)NNN$
+
+###########
+#.|.#.|.#.#
+#-###-#-#-#
+#.|.|.#.#.#
+#-#####-#-#
+#.#.#X|.#.#
+#-#-#####-#
+#.#.|.|.|.#
+#-###-###-#
+#.|.|.#.|.#
+###########
+```
+
+This regex has one main route which, at three locations, can optionally include additional detours and be valid: `(NEWS|)`, `(WNSE|)`, and `(SWEN|)`. Regardless of which option is taken, the route continues from the position it is left at after taking those steps. So, for example, this regex matches all of the following routes (and more that aren't listed here):
+
+
+ - `ENNWSWWSSSEENEENNN`
+ - `ENNWSWW*NEWS*SSSEENEENNN`
+ - `ENNWSWW*NEWS*SSSEENEE*SWEN*NNN`
+ - `ENNWSWWSSSEEN*WNSE*EENNN`
+
+By following the various routes the regex matches, a full map of all of the doors and rooms in the facility can be assembled.
+
+To get a sense for the size of this facility, you'd like to determine which room is *furthest* from you: specifically, you would like to find the room for which the *shortest path to that room would require passing through the most doors*.
+
+
+ - In the first example (`^WNE$`), this would be the north-east corner `*3*` doors away.
+ - In the second example (`^ENWWW(NEEE|SSE(EE|N))$`), this would be the south-east corner `*10*` doors away.
+ - In the third example (`^ENNWSWW(NEWS|)SSSEEN(WNSE|)EE(SWEN|)NNN$`), this would be the north-east corner `*18*` doors away.
+
+Here are a few more examples:
+
+```
+Regex: ^ESSWWN(E|NNENN(EESS(WNSE|)SSS|WWWSSSSE(SW|NNNE)))$
+Furthest room requires passing 23 doors
+
+#############
+#.|.|.|.|.|.#
+#-#####-###-#
+#.#.|.#.#.#.#
+#-#-###-#-#-#
+#.#.#.|.#.|.#
+#-#-#-#####-#
+#.#.#.#X|.#.#
+#-#-#-###-#-#
+#.|.#.|.#.#.#
+###-#-###-#-#
+#.|.#.|.|.#.#
+#############
+```
+
+```
+Regex: ^WSSEESWWWNW(S|NENNEEEENN(ESSSSW(NWSW|SSEN)|WSWWN(E|WWS(E|SS))))$
+Furthest room requires passing 31 doors
+
+###############
+#.|.|.|.#.|.|.#
+#-###-###-#-#-#
+#.|.#.|.|.#.#.#
+#-#########-#-#
+#.#.|.|.|.|.#.#
+#-#-#########-#
+#.#.#.|X#.|.#.#
+###-#-###-#-#-#
+#.|.#.#.|.#.|.#
+#-###-#####-###
+#.|.#.|.|.#.#.#
+#-#-#####-#-#-#
+#.#.|.|.|.#.|.#
+###############
+```
+
+*What is the largest number of doors you would be required to pass through to reach a room?* That is, find the room for which the shortest path from your starting location to that room would require passing through the most doors; what is the fewest doors you can pass through to reach it?
+
+
+## --- Part Two ---
+Okay, so the facility is *big*.
+
+*How many rooms have a shortest path from your current location that pass through at least `1000` doors?*
+
+
diff --git a/2018/Day20/input.in b/2018/Day20/input.in
index 84ee2d7a1..e4f0cfaf9 100644
Binary files a/2018/Day20/input.in and b/2018/Day20/input.in differ
diff --git a/2018/Day21/README.md b/2018/Day21/README.md
index f7558e4d8..6f26f0a28 100644
--- a/2018/Day21/README.md
+++ b/2018/Day21/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2018/day/21](https://adventofcode.com/2018/day/21)
## --- Day 21: Chronal Conversion ---
You should have been watching where you were going, because as you wander the new North Pole base, you trip and fall into a very deep hole!
Just kidding. You're falling through time again.
-Read the [full puzzle](https://adventofcode.com/2018/day/21).
\ No newline at end of file
+If you keep up your current pace, you should have resolved all of the temporal anomalies by the next time the device activates. Since you have very little interest in browsing history in 500-year increments for the rest of your life, you need to find a way to get back to your present time.
+
+After a little research, you discover two important facts about the behavior of the device:
+
+First, you discover that the device is hard-wired to always send you back in time in 500-year increments. Changing this is probably not feasible.
+
+Second, you discover the *activation system* (your puzzle input) for the time travel module. Currently, it appears to *run forever without halting*.
+
+If you can cause the activation system to *halt* at a specific moment, maybe you can make the device send you so far back in time that you cause an [integer underflow](https://cwe.mitre.org/data/definitions/191.html) *in time itself* and wrap around back to your current time!
+
+The device executes the program as specified in [manual section one](16) and [manual section two](19).
+
+Your goal is to figure out how the program works and cause it to halt. You can only control *register `0`*; every other register begins at `0` as usual.
+
+Because time travel is a dangerous activity, the activation system begins with a few instructions which verify that *bitwise AND* (via `bani`) does a *numeric* operation and *not* an operation as if the inputs were interpreted as strings. If the test fails, it enters an infinite loop re-running the test instead of allowing the program to execute normally. If the test passes, the program continues, and assumes that *all other bitwise operations* (`banr`, `bori`, and `borr`) also interpret their inputs as *numbers*. (Clearly, the Elves who wrote this system were worried that someone might introduce a bug while trying to emulate this system with a scripting language.)
+
+*What is the lowest non-negative integer value for register `0` that causes the program to halt after executing the fewest instructions?* (Executing the same instruction multiple times counts as multiple instructions executed.)
+
+
+## --- Part Two ---
+In order to determine the timing window for your underflow exploit, you also need an upper bound:
+
+*What is the lowest non-negative integer value for register `0` that causes the program to halt after executing the most instructions?* (The program must actually halt; running forever does not count as halting.)
+
+
diff --git a/2018/Day21/Solution.cs b/2018/Day21/Solution.cs
index f7ed345ae..c762cecca 100644
--- a/2018/Day21/Solution.cs
+++ b/2018/Day21/Solution.cs
@@ -1,65 +1,112 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
+using System.Reflection;
+using System.Runtime.Loader;
+using System.Text;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.CSharp;
+using Microsoft.CodeAnalysis.Emit;
namespace AdventOfCode.Y2018.Day21;
[ProblemName("Chronal Conversion")]
class Solution : Solver {
- public object PartOne(string input) => Run(input).First();
- public object PartTwo(string input) => Run(input).Last();
+ public object PartOne(string input) => Run("one", input).First();
+ public object PartTwo(string input) => Run("two", input).Last();
- public IEnumerable12
, divide by 3 and round down to get 4
, then subtract 2 to get 2
.
+ - For a mass of 14
, dividing by 3 and rounding down still yields 4
, so the fuel required is also 2
.
+ - For a mass of 1969
, the fuel required is 654
.
+ - For a mass of 100756
, the fuel required is 33583
.
+
+The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.
+
+What is the sum of the fuel requirements for all of the modules on your spacecraft?
+
+
+## --- Part Two ---
+During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.
+
+Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2. However, that fuel also requires fuel, and that fuel requires fuel, and so on. Any mass that would require negative fuel should instead be treated as if it requires zero fuel; the remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside the scope of this calculation.
+
+So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:
+
+
+ - A module of mass 14
requires 2
fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is 0
, which would call for a negative fuel), so the total fuel required is still just 2
.
+ - At first, a module of mass 1969
requires 654
fuel. Then, this fuel requires 216
more fuel (654 / 3 - 2
). 216
then requires 70
more fuel, which requires 21
fuel, which requires 5
fuel, which requires no further fuel. So, the total fuel required for a module of mass 1969
is 654 + 216 + 70 + 21 + 5 = 966
.
+ - The fuel required by a module of mass 100756
and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346
.
+
+What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)
+
+
diff --git a/2019/Day01/input.in b/2019/Day01/input.in
index 2db97c2a8..e5a50620c 100644
Binary files a/2019/Day01/input.in and b/2019/Day01/input.in differ
diff --git a/2019/Day02/README.md b/2019/Day02/README.md
index d7c41c9ef..c7a84d94a 100644
--- a/2019/Day02/README.md
+++ b/2019/Day02/README.md
@@ -1,6 +1,82 @@
+original source: [https://adventofcode.com/2019/day/2](https://adventofcode.com/2019/day/2)
## --- Day 2: 1202 Program Alarm ---
On the way to your [gravity assist](https://en.wikipedia.org/wiki/Gravity_assist) around the Moon, your ship computer beeps angrily about a "[1202 program alarm](https://www.hq.nasa.gov/alsj/a11/a11.landing.html#1023832)". On the radio, an Elf is already explaining how to handle the situation: "Don't worry, that's perfectly norma--" The ship computer [bursts into flames](https://en.wikipedia.org/wiki/Halt_and_Catch_Fire).
You notify the Elves that the computer's [magic smoke](https://en.wikipedia.org/wiki/Magic_smoke) seems to have escaped. "That computer ran *Intcode* programs like the gravity assist program it was working on; surely there are enough spare parts up there to build a new Intcode computer!"
-Read the [full puzzle](https://adventofcode.com/2019/day/2).
\ No newline at end of file
+An Intcode program is a list of [integers](https://en.wikipedia.org/wiki/Integer) separated by commas (like `1,0,0,3,99`). To run one, start by looking at the first integer (called position `0`). Here, you will find an *opcode* - either `1`, `2`, or `99`. The opcode indicates what to do; for example, `99` means that the program is finished and should immediately halt. Encountering an unknown opcode means something went wrong.
+
+Opcode `1` *adds* together numbers read from two positions and stores the result in a third position. The three integers *immediately after* the opcode tell you these three positions - the first two indicate the *positions* from which you should read the input values, and the third indicates the *position* at which the output should be stored.
+
+For example, if your Intcode computer encounters `1,10,20,30`, it should read the values at positions `10` and `20`, add those values, and then overwrite the value at position `30` with their sum.
+
+Opcode `2` works exactly like opcode `1`, except it *multiplies* the two inputs instead of adding them. Again, the three integers after the opcode indicate *where* the inputs and outputs are, not their values.
+
+Once you're done processing an opcode, *move to the next one* by stepping forward `4` positions.
+
+For example, suppose you have the following program:
+
+```
+1,9,10,3,2,3,11,0,99,30,40,50
+```
+
+For the purposes of illustration, here is the same program split into multiple lines:
+
+```
+1,9,10,3,
+2,3,11,0,
+99,
+30,40,50
+```
+
+The first four integers, `1,9,10,3`, are at positions `0`, `1`, `2`, and `3`. Together, they represent the first opcode (`1`, addition), the positions of the two inputs (`9` and `10`), and the position of the output (`3`). To handle this opcode, you first need to get the values at the input positions: position `9` contains `30`, and position `10` contains `40`. *Add* these numbers together to get `70`. Then, store this value at the output position; here, the output position (`3`) is *at* position `3`, so it overwrites itself. Afterward, the program looks like this:
+
+```
+1,9,10,*70*,
+2,3,11,0,
+99,
+30,40,50
+```
+
+Step forward `4` positions to reach the next opcode, `2`. This opcode works just like the previous, but it multiplies instead of adding. The inputs are at positions `3` and `11`; these positions contain `70` and `50` respectively. Multiplying these produces `3500`; this is stored at position `0`:
+
+```
+*3500*,9,10,70,
+2,3,11,0,
+99,
+30,40,50
+```
+
+Stepping forward `4` more positions arrives at opcode `99`, halting the program.
+
+Here are the initial and final states of a few more small programs:
+
+
+ - `1,0,0,0,99` becomes `*2*,0,0,0,99` (`1 + 1 = 2`).
+ - `2,3,0,3,99` becomes `2,3,0,*6*,99` (`3 * 2 = 6`).
+ - `2,4,4,5,99,0` becomes `2,4,4,5,99,*9801*` (`99 * 99 = 9801`).
+ - `1,1,1,4,99,5,6,0,99` becomes `*30*,1,1,4,*2*,5,6,0,99`.
+
+Once you have a working computer, the first step is to restore the gravity assist program (your puzzle input) to the "1202 program alarm" state it had just before the last computer caught fire. To do this, *before running the program*, replace position `1` with the value `12` and replace position `2` with the value `2`. *What value is left at position `0`* after the program halts?
+
+
+## --- Part Two ---
+"Good, the new computer seems to be working correctly! *Keep it nearby* during this mission - you'll probably use it again. Real Intcode computers support many more features than your new one, but we'll let you know what they are as you need them."
+
+"However, your current priority should be to complete your gravity assist around the Moon. For this mission to succeed, we should settle on some terminology for the parts you've already built."
+
+Intcode programs are given as a list of integers; these values are used as the initial state for the computer's *memory*. When you run an Intcode program, make sure to start by initializing memory to the program's values. A position in memory is called an *address* (for example, the first value in memory is at "address 0").
+
+Opcodes (like `1`, `2`, or `99`) mark the beginning of an *instruction*. The values used immediately after an opcode, if any, are called the instruction's *parameters*. For example, in the instruction `1,2,3,4`, `1` is the opcode; `2`, `3`, and `4` are the parameters. The instruction `99` contains only an opcode and has no parameters.
+
+The address of the current instruction is called the *instruction pointer*; it starts at `0`. After an instruction finishes, the instruction pointer increases by *the number of values in the instruction*; until you add more instructions to the computer, this is always `4` (`1` opcode + `3` parameters) for the add and multiply instructions. (The halt instruction would increase the instruction pointer by `1`, but it halts the program instead.)
+
+"With terminology out of the way, we're ready to proceed. To complete the gravity assist, you need to *determine what pair of inputs produces the output `19690720`*."
+
+The inputs should still be provided to the program by replacing the values at addresses `1` and `2`, just like before. In this program, the value placed in address `1` is called the *noun*, and the value placed in address `2` is called the *verb*. Each of the two input values will be between `0` and `99`, inclusive.
+
+Once the program has halted, its output is available at address `0`, also just like before. Each time you try a pair of inputs, make sure you first *reset the computer's memory to the values in the program* (your puzzle input) - in other words, don't reuse memory from a previous attempt.
+
+Find the input *noun* and *verb* that cause the program to produce the output `19690720`. *What is `100 * noun + verb`?* (For example, if `noun=12` and `verb=2`, the answer would be `1202`.)
+
+
diff --git a/2019/Day02/input.in b/2019/Day02/input.in
index 3cff00467..e416fb09e 100644
Binary files a/2019/Day02/input.in and b/2019/Day02/input.in differ
diff --git a/2019/Day03/README.md b/2019/Day03/README.md
index a2d766739..65613a39b 100644
--- a/2019/Day03/README.md
+++ b/2019/Day03/README.md
@@ -1,6 +1,86 @@
+original source: [https://adventofcode.com/2019/day/3](https://adventofcode.com/2019/day/3)
## --- Day 3: Crossed Wires ---
The gravity assist was successful, and you're well on your way to the Venus refuelling station. During the rush back on Earth, the fuel management system wasn't completely installed, so that's next on the priority list.
Opening the front panel reveals a jumble of wires. Specifically, *two wires* are connected to a central port and extend outward on a grid. You trace the path each wire takes as it leaves the central port, one wire per line of text (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2019/day/3).
\ No newline at end of file
+The wires twist and turn, but the two wires occasionally cross paths. To fix the circuit, you need to *find the intersection point closest to the central port*. Because the wires are on a grid, use the [Manhattan distance](https://en.wikipedia.org/wiki/Taxicab_geometry) for this measurement. While the wires do technically cross right at the central port where they both start, this point does not count, nor does a wire count as crossing with itself.
+
+For example, if the first wire's path is `R8,U5,L5,D3`, then starting from the central port (`o`), it goes right `8`, up `5`, left `5`, and finally down `3`:
+
+```
+...........
+...........
+...........
+....+----+.
+....|....|.
+....|....|.
+....|....|.
+.........|.
+.o-------+.
+...........
+```
+
+Then, if the second wire's path is `U7,R6,D4,L4`, it goes up `7`, right `6`, down `4`, and left `4`:
+
+```
+...........
+.+-----+...
+.|.....|...
+.|..+--X-+.
+.|..|..|.|.
+.|.-*X*--+.|.
+.|..|....|.
+.|.......|.
+.o-------+.
+...........
+```
+
+These wires cross at two locations (marked `X`), but the lower-left one is closer to the central port: its distance is `3 + 3 = 6`.
+
+Here are a few more examples:
+
+
+ - `R75,D30,R83,U83,L12,D49,R71,U7,L72
+U62,R66,U55,R34,D71,R55,D58,R83` = distance `159`
+ - `R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
+U98,R91,D20,R16,D67,R40,U7,R15,U6,R7` = distance `135`
+
+*What is the Manhattan distance* from the central port to the closest intersection?
+
+
+## --- Part Two ---
+It turns out that this circuit is very timing-sensitive; you actually need to *minimize the signal delay*.
+
+To do this, calculate the *number of steps* each wire takes to reach each intersection; choose the intersection where the *sum of both wires' steps* is lowest. If a wire visits a position on the grid multiple times, use the steps value from the *first* time it visits that position when calculating the total value of a specific intersection.
+
+The number of steps a wire takes is the total number of grid squares the wire has entered to get to that location, including the intersection being considered. Again consider the example from above:
+
+```
+...........
+.+-----+...
+.|.....|...
+.|..+--X-+.
+.|..|..|.|.
+.|.-X--+.|.
+.|..|....|.
+.|.......|.
+.o-------+.
+...........
+```
+
+In the above example, the intersection closest to the central port is reached after `8+5+5+2 = *20*` steps by the first wire and `7+6+4+3 = *20*` steps by the second wire for a total of `20+20 = *40*` steps.
+
+However, the top-right intersection is better: the first wire takes only `8+5+2 = *15*` and the second wire takes only `7+6+2 = *15*`, a total of `15+15 = *30*` steps.
+
+Here are the best steps for the extra examples from above:
+
+
+ - `R75,D30,R83,U83,L12,D49,R71,U7,L72
+U62,R66,U55,R34,D71,R55,D58,R83` = `610` steps
+ - `R98,U47,R26,D63,R33,U87,L62,D20,R33,U53,R51
+U98,R91,D20,R16,D67,R40,U7,R15,U6,R7` = `410` steps
+
+*What is the fewest combined steps the wires must take to reach an intersection?*
+
+
diff --git a/2019/Day03/input.in b/2019/Day03/input.in
index e840a410a..8acc0f837 100644
Binary files a/2019/Day03/input.in and b/2019/Day03/input.in differ
diff --git a/2019/Day04/README.md b/2019/Day04/README.md
index 1145b177d..86ce6c205 100644
--- a/2019/Day04/README.md
+++ b/2019/Day04/README.md
@@ -1,6 +1,35 @@
+original source: [https://adventofcode.com/2019/day/4](https://adventofcode.com/2019/day/4)
## --- Day 4: Secure Container ---
You arrive at the Venus fuel depot only to discover it's protected by a password. The Elves had written the password on a sticky note, but someone threw it out.
However, they do remember a few key facts about the password:
-Read the [full puzzle](https://adventofcode.com/2019/day/4).
\ No newline at end of file
+
+ - It is a six-digit number.
+ - The value is within the range given in your puzzle input.
+ - Two adjacent digits are the same (like `22` in `1*22*345`).
+ - Going from left to right, the digits *never decrease*; they only ever increase or stay the same (like `111123` or `135679`).
+
+Other than the range rule, the following are true:
+
+
+ - `111111` meets these criteria (double `11`, never decreases).
+ - `2234*50*` does not meet these criteria (decreasing pair of digits `50`).
+ - `123789` does not meet these criteria (no double).
+
+*How many different passwords* within the range given in your puzzle input meet these criteria?
+
+
+## --- Part Two ---
+An Elf just remembered one more important detail: the two adjacent matching digits *are not part of a larger group of matching digits*.
+
+Given this additional criterion, but still ignoring the range rule, the following are now true:
+
+
+ - `112233` meets these criteria because the digits never decrease and all repeated digits are exactly two digits long.
+ - `123*444*` no longer meets the criteria (the repeated `44` is part of a larger group of `444`).
+ - `111122` meets the criteria (even though `1` is repeated more than twice, it still contains a double `22`).
+
+*How many different passwords* within the range given in your puzzle input meet all of the criteria?
+
+
diff --git a/2019/Day04/input.in b/2019/Day04/input.in
index 079b7dd74..4d7fa7f98 100644
Binary files a/2019/Day04/input.in and b/2019/Day04/input.in differ
diff --git a/2019/Day05/README.md b/2019/Day05/README.md
index b3908d680..e7c2cefda 100644
--- a/2019/Day05/README.md
+++ b/2019/Day05/README.md
@@ -1,6 +1,102 @@
+original source: [https://adventofcode.com/2019/day/5](https://adventofcode.com/2019/day/5)
## --- Day 5: Sunny with a Chance of Asteroids ---
You're starting to sweat as the ship makes its way toward Mercury. The Elves suggest that you get the air conditioner working by upgrading your ship computer to support the Thermal Environment Supervision Terminal.
The Thermal Environment Supervision Terminal (TEST) starts by running a *diagnostic program* (your puzzle input). The TEST diagnostic program will run on [your existing Intcode computer](2) after a few modifications:
-Read the [full puzzle](https://adventofcode.com/2019/day/5).
\ No newline at end of file
+*First*, you'll need to add *two new instructions*:
+
+
+ - Opcode `3` takes a single integer as *input* and saves it to the address given by its only parameter. For example, the instruction `3,50` would take an input value and store it at address `50`.
+ - Opcode `4` *outputs* the value of its only parameter. For example, the instruction `4,50` would output the value at address `50`.
+
+Programs that use these instructions will come with documentation that explains what should be connected to the input and output. The program `3,0,4,0,99` outputs whatever it gets as input, then halts.
+
+*Second*, you'll need to add support for *parameter modes*:
+
+Each parameter of an instruction is handled based on its parameter mode. Right now, your ship computer already understands parameter mode `0`, *position mode*, which causes the parameter to be interpreted as a *position* - if the parameter is `50`, its value is *the value stored at address `50` in memory*. Until now, all parameters have been in position mode.
+
+Now, your ship computer will also need to handle parameters in mode `1`, *immediate mode*. In immediate mode, a parameter is interpreted as a *value* - if the parameter is `50`, its value is simply *`50`*.
+
+Parameter modes are stored in the same value as the instruction's opcode. The opcode is a two-digit number based only on the ones and tens digit of the value, that is, the opcode is the rightmost two digits of the first value in an instruction. Parameter modes are single digits, one per parameter, read right-to-left from the opcode: the first parameter's mode is in the hundreds digit, the second parameter's mode is in the thousands digit, the third parameter's mode is in the ten-thousands digit, and so on. Any missing modes are `0`.
+
+For example, consider the program `1002,4,3,4,33`.
+
+The first instruction, `1002,4,3,4`, is a *multiply* instruction - the rightmost two digits of the first value, `02`, indicate opcode `2`, multiplication. Then, going right to left, the parameter modes are `0` (hundreds digit), `1` (thousands digit), and `0` (ten-thousands digit, not present and therefore zero):
+
+```
+ABCDE
+ 1002
+
+DE - two-digit opcode, 02 == opcode 2
+ C - mode of 1st parameter, 0 == position mode
+ B - mode of 2nd parameter, 1 == immediate mode
+ A - mode of 3rd parameter, 0 == position mode,
+ omitted due to being a leading zero
+```
+
+This instruction multiplies its first two parameters. The first parameter, `4` in position mode, works like it did before - its value is the value stored at address `4` (`33`). The second parameter, `3` in immediate mode, simply has value `3`. The result of this operation, `33 * 3 = 99`, is written according to the third parameter, `4` in position mode, which also works like it did before - `99` is written to address `4`.
+
+Parameters that an instruction writes to will *never be in immediate mode*.
+
+*Finally*, some notes:
+
+
+ - It is important to remember that the instruction pointer should increase by *the number of values in the instruction* after the instruction finishes. Because of the new instructions, this amount is no longer always `4`.
+ - Integers can be negative: `1101,100,-1,4,0` is a valid program (find `100 + -1`, store the result in position `4`).
+
+The TEST diagnostic program will start by requesting from the user the ID of the system to test by running an *input* instruction - provide it `1`, the ID for the ship's air conditioner unit.
+
+It will then perform a series of diagnostic tests confirming that various parts of the Intcode computer, like parameter modes, function correctly. For each test, it will run an *output* instruction indicating how far the result of the test was from the expected value, where `0` means the test was successful. Non-zero outputs mean that a function is not working correctly; check the instructions that were run before the output instruction to see which one failed.
+
+Finally, the program will output a *diagnostic code* and immediately halt. This final output isn't an error; an output followed immediately by a halt means the program finished. If all outputs were zero except the diagnostic code, the diagnostic program ran successfully.
+
+After providing `1` to the only input instruction and passing all the tests, *what diagnostic code does the program produce?*
+
+
+## --- Part Two ---
+The air conditioner comes online! Its cold air feels good for a while, but then the TEST alarms start to go off. Since the air conditioner can't vent its heat anywhere but back into the spacecraft, it's actually making the air inside the ship *warmer*.
+
+Instead, you'll need to use the TEST to extend the [thermal radiators](https://en.wikipedia.org/wiki/Spacecraft_thermal_control). Fortunately, the diagnostic program (your puzzle input) is already equipped for this. Unfortunately, your Intcode computer is not.
+
+Your computer is only missing a few opcodes:
+
+
+ - Opcode `5` is *jump-if-true*: if the first parameter is *non-zero*, it sets the instruction pointer to the value from the second parameter. Otherwise, it does nothing.
+ - Opcode `6` is *jump-if-false*: if the first parameter *is zero*, it sets the instruction pointer to the value from the second parameter. Otherwise, it does nothing.
+ - Opcode `7` is *less than*: if the first parameter is *less than* the second parameter, it stores `1` in the position given by the third parameter. Otherwise, it stores `0`.
+ - Opcode `8` is *equals*: if the first parameter is *equal to* the second parameter, it stores `1` in the position given by the third parameter. Otherwise, it stores `0`.
+
+Like all instructions, these instructions need to support *parameter modes* as described above.
+
+Normally, after an instruction is finished, the instruction pointer increases by the number of values in that instruction. *However*, if the instruction modifies the instruction pointer, that value is used and the instruction pointer is *not automatically increased*.
+
+For example, here are several programs that take one input, compare it to the value `8`, and then produce one output:
+
+
+ - `3,9,8,9,10,9,4,9,99,-1,8` - Using *position mode*, consider whether the input is *equal to* `8`; output `1` (if it is) or `0` (if it is not).
+ - `3,9,7,9,10,9,4,9,99,-1,8` - Using *position mode*, consider whether the input is *less than* `8`; output `1` (if it is) or `0` (if it is not).
+ - `3,3,1108,-1,8,3,4,3,99` - Using *immediate mode*, consider whether the input is *equal to* `8`; output `1` (if it is) or `0` (if it is not).
+ - `3,3,1107,-1,8,3,4,3,99` - Using *immediate mode*, consider whether the input is *less than *`8`; output `1` (if it is) or `0` (if it is not).
+
+Here are some jump tests that take an input, then output `0` if the input was zero or `1` if the input was non-zero:
+
+
+ - `3,12,6,12,15,1,13,14,13,4,13,99,-1,0,1,9` (using *position mode*)
+ - `3,3,1105,-1,9,1101,0,0,12,4,12,99,1` (using *immediate mode*)
+
+Here's a larger example:
+
+```
+3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,
+1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,
+999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99
+```
+
+The above example program uses an input instruction to ask for a single number. The program will then output `999` if the input value is below `8`, output `1000` if the input value is equal to `8`, or output `1001` if the input value is greater than `8`.
+
+This time, when the TEST diagnostic program runs its input instruction to get the ID of the system to test, *provide it `5`*, the ID for the ship's thermal radiator controller. This diagnostic test suite only outputs one number, the *diagnostic code*.
+
+*What is the diagnostic code for system ID `5`?*
+
+
diff --git a/2019/Day05/input.in b/2019/Day05/input.in
index 0d4db2def..5715d4bcb 100644
Binary files a/2019/Day05/input.in and b/2019/Day05/input.in differ
diff --git a/2019/Day06/README.md b/2019/Day06/README.md
index 44651a79a..5d9340383 100644
--- a/2019/Day06/README.md
+++ b/2019/Day06/README.md
@@ -1,6 +1,122 @@
+original source: [https://adventofcode.com/2019/day/6](https://adventofcode.com/2019/day/6)
## --- Day 6: Universal Orbit Map ---
You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often involves transferring between orbits, the orbit maps here are useful for finding efficient routes between, for example, you and Santa. You download a map of the local orbits (your puzzle input).
Except for the universal Center of Mass (`COM`), every object in space is in orbit around exactly one other object. An [orbit](https://en.wikipedia.org/wiki/Orbit) looks roughly like this:
-Read the [full puzzle](https://adventofcode.com/2019/day/6).
\ No newline at end of file
+```
+ \
+ \
+ |
+ |
+AAA--> o o <--BBB
+ |
+ |
+ /
+ /
+```
+
+In this diagram, the object `BBB` is in orbit around `AAA`. The path that `BBB` takes around `AAA` (drawn with lines) is only partly shown. In the map data, this orbital relationship is written `AAA)BBB`, which means "`BBB` is in orbit around `AAA`".
+
+Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the download. To verify maps, the Universal Orbit Map facility uses *orbit count checksums* - the total number of *direct orbits* (like the one shown above) and *indirect orbits*.
+
+
+Whenever `A` orbits `B` and `B` orbits `C`, then `A` *indirectly orbits* `C`. This chain can be any number of objects long: if `A` orbits `B`, `B` orbits `C`, and `C` orbits `D`, then `A` indirectly orbits `D`.
+For example, suppose you have the following map:
+
+```
+COM)B
+B)C
+C)D
+D)E
+E)F
+B)G
+G)H
+D)I
+E)J
+J)K
+K)L
+```
+
+Visually, the above map of orbits looks like this:
+
+```
+ G - H J - K - L
+ / /
+COM - B - C - D - E - F
+ \
+ I
+```
+
+In this visual representation, when two objects are connected by a line, the one on the right directly orbits the one on the left.
+
+Here, we can count the total number of orbits as follows:
+
+
+ - `D` directly orbits `C` and indirectly orbits `B` and `COM`, a total of `3` orbits.
+ - `L` directly orbits `K` and indirectly orbits `J`, `E`, `D`, `C`, `B`, and `COM`, a total of `7` orbits.
+ - `COM` orbits nothing.
+
+The total number of direct and indirect orbits in this example is `*42*`.
+
+*What is the total number of direct and indirect orbits* in your map data?
+
+
+## --- Part Two ---
+Now, you just need to figure out how many *orbital transfers* you (`YOU`) need to take to get to Santa (`SAN`).
+
+You start at the object `YOU` are orbiting; your destination is the object `SAN` is orbiting. An orbital transfer lets you move from any object to an object orbiting or orbited by that object.
+
+For example, suppose you have the following map:
+
+```
+COM)B
+B)C
+C)D
+D)E
+E)F
+B)G
+G)H
+D)I
+E)J
+J)K
+K)L
+K)YOU
+I)SAN
+```
+
+Visually, the above map of orbits looks like this:
+
+```
+ *YOU*
+ */*
+ G - H *J - K* - L
+ / */*
+COM - B - C - *D - E* - F
+ *\*
+ *I - SAN*
+```
+
+In this example, `YOU` are in orbit around `K`, and `SAN` is in orbit around `I`. To move from `K` to `I`, a minimum of `4` orbital transfers are required:
+
+
+ - `K` to `J`
+ - `J` to `E`
+ - `E` to `D`
+ - `D` to `I`
+
+Afterward, the map of orbits looks like this:
+
+```
+ G - H J - K - L
+ / /
+COM - B - C - D - E - F
+ \
+ I - SAN
+ *\*
+ *YOU*
+```
+
+*What is the minimum number of orbital transfers required* to move from the object `YOU` are orbiting to the object `SAN` is orbiting? (Between the objects they are orbiting - *not* between `YOU` and `SAN`.)
+
+
diff --git a/2019/Day06/input.in b/2019/Day06/input.in
index f2e87ab51..3e21de8e1 100644
Binary files a/2019/Day06/input.in and b/2019/Day06/input.in differ
diff --git a/2019/Day07/README.md b/2019/Day07/README.md
index d25f07a2a..1e76119ad 100644
--- a/2019/Day07/README.md
+++ b/2019/Day07/README.md
@@ -1,6 +1,99 @@
+original source: [https://adventofcode.com/2019/day/7](https://adventofcode.com/2019/day/7)
## --- Day 7: Amplification Circuit ---
Based on the navigational maps, you're going to need to send more power to your ship's thrusters to reach Santa in time. To do this, you'll need to configure a series of [amplifiers](https://en.wikipedia.org/wiki/Amplifier) already installed on the ship.
There are five amplifiers connected in series; each one receives an input signal and produces an output signal. They are connected such that the first amplifier's output leads to the second amplifier's input, the second amplifier's output leads to the third amplifier's input, and so on. The first amplifier's input value is `0`, and the last amplifier's output leads to your ship's thrusters.
-Read the [full puzzle](https://adventofcode.com/2019/day/7).
\ No newline at end of file
+```
+ O-------O O-------O O-------O O-------O O-------O
+0 ->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-> (to thrusters)
+ O-------O O-------O O-------O O-------O O-------O
+```
+
+The Elves have sent you some *Amplifier Controller Software* (your puzzle input), a program that should run on your [existing Intcode computer](5). Each amplifier will need to run a copy of the program.
+
+When a copy of the program starts running on an amplifier, it will first use an input instruction to ask the amplifier for its current *phase setting* (an integer from `0` to `4`). Each phase setting is used *exactly once*, but the Elves can't remember which amplifier needs which phase setting.
+
+The program will then call another input instruction to get the amplifier's input signal, compute the correct output signal, and supply it back to the amplifier with an output instruction. (If the amplifier has not yet received an input signal, it waits until one arrives.)
+
+Your job is to *find the largest output signal that can be sent to the thrusters* by trying every possible combination of phase settings on the amplifiers. Make sure that memory is not shared or reused between copies of the program.
+
+For example, suppose you want to try the phase setting sequence `3,1,2,4,0`, which would mean setting amplifier `A` to phase setting `3`, amplifier `B` to setting `1`, `C` to `2`, `D` to `4`, and `E` to `0`. Then, you could determine the output signal that gets sent from amplifier `E` to the thrusters with the following steps:
+
+
+ - Start the copy of the amplifier controller software that will run on amplifier `A`. At its first input instruction, provide it the amplifier's phase setting, `3`. At its second input instruction, provide it the input signal, `0`. After some calculations, it will use an output instruction to indicate the amplifier's output signal.
+ - Start the software for amplifier `B`. Provide it the phase setting (`1`) and then whatever output signal was produced from amplifier `A`. It will then produce a new output signal destined for amplifier `C`.
+ - Start the software for amplifier `C`, provide the phase setting (`2`) and the value from amplifier `B`, then collect its output signal.
+ - Run amplifier `D`'s software, provide the phase setting (`4`) and input value, and collect its output signal.
+ - Run amplifier `E`'s software, provide the phase setting (`0`) and input value, and collect its output signal.
+
+The final output signal from amplifier `E` would be sent to the thrusters. However, this phase setting sequence may not have been the best one; another sequence might have sent a higher signal to the thrusters.
+
+Here are some example programs:
+
+
+ - Max thruster signal *`43210`* (from phase setting sequence `4,3,2,1,0`):
+```
+3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0
+```
+
+ - Max thruster signal *`54321`* (from phase setting sequence `0,1,2,3,4`):
+```
+3,23,3,24,1002,24,10,24,1002,23,-1,23,
+101,5,23,23,1,24,23,23,4,23,99,0,0
+```
+
+ - Max thruster signal *`65210`* (from phase setting sequence `1,0,4,3,2`):
+```
+3,31,3,32,1002,32,10,32,1001,31,-2,31,1007,31,0,33,
+1002,33,7,33,1,33,31,31,1,32,31,31,4,31,99,0,0,0
+```
+
+
+Try every combination of phase settings on the amplifiers. *What is the highest signal that can be sent to the thrusters?*
+
+
+## --- Part Two ---
+It's no good - in this configuration, the amplifiers can't generate a large enough output signal to produce the thrust you'll need. The Elves quickly talk you through rewiring the amplifiers into a *feedback loop*:
+
+```
+ O-------O O-------O O-------O O-------O O-------O
+0 -+->| Amp A |->| Amp B |->| Amp C |->| Amp D |->| Amp E |-.
+ | O-------O O-------O O-------O O-------O O-------O |
+ | |
+ '--------------------------------------------------------+
+ |
+ v
+ (to thrusters)
+```
+
+Most of the amplifiers are connected as they were before; amplifier `A`'s output is connected to amplifier `B`'s input, and so on. *However,* the output from amplifier `E` is now connected into amplifier `A`'s input. This creates the feedback loop: the signal will be sent through the amplifiers *many times*.
+
+In feedback loop mode, the amplifiers need *totally different phase settings*: integers from `5` to `9`, again each used exactly once. These settings will cause the Amplifier Controller Software to repeatedly take input and produce output many times before halting. Provide each amplifier its phase setting at its first input instruction; all further input/output instructions are for signals.
+
+Don't restart the Amplifier Controller Software on any amplifier during this process. Each one should continue receiving and sending signals until it halts.
+
+All signals sent or received in this process will be between pairs of amplifiers except the very first signal and the very last signal. To start the process, a `0` signal is sent to amplifier `A`'s input *exactly once*.
+
+Eventually, the software on the amplifiers will halt after they have processed the final loop. When this happens, the last output signal from amplifier `E` is sent to the thrusters. Your job is to *find the largest output signal that can be sent to the thrusters* using the new phase settings and feedback loop arrangement.
+
+Here are some example programs:
+
+
+ - Max thruster signal *`139629729`* (from phase setting sequence `9,8,7,6,5`):
+```
+3,26,1001,26,-4,26,3,27,1002,27,2,27,1,27,26,
+27,4,27,1001,28,-1,28,1005,28,6,99,0,0,5
+```
+
+ - Max thruster signal *`18216`* (from phase setting sequence `9,7,8,5,6`):
+```
+3,52,1001,52,-5,52,3,53,1,52,56,54,1007,54,5,55,1005,55,26,1001,54,
+-5,54,1105,1,12,1,53,54,53,1008,54,0,55,1001,55,1,55,2,53,55,53,4,
+53,1001,56,-1,56,1005,56,6,99,0,0,0,0,10
+```
+
+
+Try every combination of the new phase settings on the amplifier feedback loop. *What is the highest signal that can be sent to the thrusters?*
+
+
diff --git a/2019/Day07/input.in b/2019/Day07/input.in
index 85edf7132..4c51e833e 100644
Binary files a/2019/Day07/input.in and b/2019/Day07/input.in differ
diff --git a/2019/Day08/README.md b/2019/Day08/README.md
index 50bec7cf7..5e7173b40 100644
--- a/2019/Day08/README.md
+++ b/2019/Day08/README.md
@@ -1,6 +1,66 @@
+original source: [https://adventofcode.com/2019/day/8](https://adventofcode.com/2019/day/8)
## --- Day 8: Space Image Format ---
The Elves' spirits are lifted when they realize you have an opportunity to reboot one of their Mars rovers, and so they are curious if you would spend a brief sojourn on Mars. You land your ship near the rover.
When you reach the rover, you discover that it's already in the process of rebooting! It's just waiting for someone to enter a [BIOS](https://en.wikipedia.org/wiki/BIOS) password. The Elf responsible for the rover takes a picture of the password (your puzzle input) and sends it to you via the Digital Sending Network.
-Read the [full puzzle](https://adventofcode.com/2019/day/8).
\ No newline at end of file
+Unfortunately, images sent via the Digital Sending Network aren't encoded with any normal encoding; instead, they're encoded in a special Space Image Format. None of the Elves seem to remember why this is the case. They send you the instructions to decode it.
+
+Images are sent as a series of digits that each represent the color of a single pixel. The digits fill each row of the image left-to-right, then move downward to the next row, filling rows top-to-bottom until every pixel of the image is filled.
+
+Each image actually consists of a series of identically-sized *layers* that are filled in this way. So, the first digit corresponds to the top-left pixel of the first layer, the second digit corresponds to the pixel to the right of that on the same layer, and so on until the last digit, which corresponds to the bottom-right pixel of the last layer.
+
+For example, given an image `3` pixels wide and `2` pixels tall, the image data `123456789012` corresponds to the following image layers:
+
+```
+Layer 1: 123
+ 456
+
+Layer 2: 789
+ 012
+```
+
+The image you received is *`25` pixels wide and `6` pixels tall*.
+
+To make sure the image wasn't corrupted during transmission, the Elves would like you to find the layer that contains the *fewest `0` digits*. On that layer, what is *the number of `1` digits multiplied by the number of `2` digits?*
+
+
+## --- Part Two ---
+Now you're ready to decode the image. The image is rendered by stacking the layers and aligning the pixels with the same positions in each layer. The digits indicate the color of the corresponding pixel: `0` is black, `1` is white, and `2` is transparent.
+
+The layers are rendered with the first layer in front and the last layer in back. So, if a given position has a transparent pixel in the first and second layers, a black pixel in the third layer, and a white pixel in the fourth layer, the final image would have a *black* pixel at that position.
+
+For example, given an image `2` pixels wide and `2` pixels tall, the image data `0222112222120000` corresponds to the following image layers:
+
+```
+Layer 1: *0*2
+ 22
+
+Layer 2: 1*1*
+ 22
+
+Layer 3: 22
+ *1*2
+
+Layer 4: 00
+ 0*0*
+```
+
+Then, the full image can be found by determining the top visible pixel in each position:
+
+
+ - The top-left pixel is *black* because the top layer is `0`.
+ - The top-right pixel is *white* because the top layer is `2` (transparent), but the second layer is `1`.
+ - The bottom-left pixel is *white* because the top two layers are `2`, but the third layer is `1`.
+ - The bottom-right pixel is *black* because the only visible pixel in that position is `0` (from layer 4).
+
+So, the final image looks like this:
+
+```
+01
+10
+```
+
+*What message is produced after decoding your image?*
+
+
diff --git a/2019/Day08/input.in b/2019/Day08/input.in
index 546534d70..dd31a271a 100644
Binary files a/2019/Day08/input.in and b/2019/Day08/input.in differ
diff --git a/2019/Day09/README.md b/2019/Day09/README.md
index e063ad056..b72209a49 100644
--- a/2019/Day09/README.md
+++ b/2019/Day09/README.md
@@ -1,6 +1,53 @@
+original source: [https://adventofcode.com/2019/day/9](https://adventofcode.com/2019/day/9)
## --- Day 9: Sensor Boost ---
You've just said goodbye to the rebooted rover and left Mars when you receive a faint distress signal coming from the asteroid belt. It must be the Ceres monitoring station!
In order to lock on to the signal, you'll need to boost your sensors. The Elves send up the latest *BOOST* program - Basic Operation Of System Test.
-Read the [full puzzle](https://adventofcode.com/2019/day/9).
\ No newline at end of file
+While BOOST (your puzzle input) is capable of boosting your sensors, for tenuous safety reasons, it refuses to do so until the computer it runs on passes some checks to demonstrate it is a *complete Intcode computer*.
+
+[Your existing Intcode computer](5) is missing one key feature: it needs support for parameters in *relative mode*.
+
+Parameters in mode `2`, *relative mode*, behave very similarly to parameters in *position mode*: the parameter is interpreted as a position. Like position mode, parameters in relative mode can be read from or written to.
+
+The important difference is that relative mode parameters don't count from address `0`. Instead, they count from a value called the *relative base*. The *relative base* starts at `0`.
+
+The address a relative mode parameter refers to is itself *plus* the current *relative base*. When the relative base is `0`, relative mode parameters and position mode parameters with the same value refer to the same address.
+
+For example, given a relative base of `50`, a relative mode parameter of `-7` refers to memory address `50 + -7 = *43*`.
+
+The relative base is modified with the *relative base offset* instruction:
+
+
+ - Opcode `9` *adjusts the relative base* by the value of its only parameter. The relative base increases (or decreases, if the value is negative) by the value of the parameter.
+
+For example, if the relative base is `2000`, then after the instruction `109,19`, the relative base would be `2019`. If the next instruction were `204,-34`, then the value at address `1985` would be output.
+
+Your Intcode computer will also need a few other capabilities:
+
+
+ - The computer's available memory should be much larger than the initial program. Memory beyond the initial program starts with the value `0` and can be read or written like any other memory. (It is invalid to try to access memory at a negative address, though.)
+ - The computer should have support for large numbers. Some instructions near the beginning of the BOOST program will verify this capability.
+
+Here are some example programs that use these features:
+
+
+ - `109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99` takes no input and produces a [copy of itself](https://en.wikipedia.org/wiki/Quine_(computing)) as output.
+ - `1102,34915192,34915192,7,4,7,99,0` should output a 16-digit number.
+ - `104,1125899906842624,99` should output the large number in the middle.
+
+The BOOST program will ask for a single input; run it in test mode by providing it the value `1`. It will perform a series of checks on each opcode, output any opcodes (and the associated parameter modes) that seem to be functioning incorrectly, and finally output a BOOST keycode.
+
+Once your Intcode computer is fully functional, the BOOST program should report no malfunctioning opcodes when run in test mode; it should only output a single value, the BOOST keycode. *What BOOST keycode does it produce?*
+
+
+## --- Part Two ---
+*You now have a complete Intcode computer.*
+
+Finally, you can lock on to the Ceres distress signal! You just need to boost your sensors using the BOOST program.
+
+The program runs in sensor boost mode by providing the input instruction the value `2`. Once run, it will boost the sensors automatically, but it might take a few seconds to complete the operation on slower hardware. In sensor boost mode, the program will output a single value: *the coordinates of the distress signal*.
+
+Run the BOOST program in sensor boost mode. *What are the coordinates of the distress signal?*
+
+
diff --git a/2019/Day09/input.in b/2019/Day09/input.in
index 53b584655..233a9794a 100644
Binary files a/2019/Day09/input.in and b/2019/Day09/input.in differ
diff --git a/2019/Day10/README.md b/2019/Day10/README.md
index 049647f0e..0df798568 100644
--- a/2019/Day10/README.md
+++ b/2019/Day10/README.md
@@ -1,6 +1,199 @@
+original source: [https://adventofcode.com/2019/day/10](https://adventofcode.com/2019/day/10)
## --- Day 10: Monitoring Station ---
You fly into the asteroid belt and reach the Ceres monitoring station. The Elves here have an emergency: they're having trouble tracking all of the asteroids and can't be sure they're safe.
The Elves would like to build a new monitoring station in a nearby area of space; they hand you a map of all of the asteroids in that region (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2019/day/10).
\ No newline at end of file
+The map indicates whether each position is empty (`.`) or contains an asteroid (`#`). The asteroids are much smaller than they appear on the map, and every asteroid is exactly in the center of its marked position. The asteroids can be described with `X,Y` coordinates where `X` is the distance from the left edge and `Y` is the distance from the top edge (so the top-left corner is `0,0` and the position immediately to its right is `1,0`).
+
+Your job is to figure out which asteroid would be the best place to build a *new monitoring station*. A monitoring station can *detect* any asteroid to which it has *direct line of sight* - that is, there cannot be another asteroid *exactly* between them. This line of sight can be at any angle, not just lines aligned to the grid or diagonally. The *best* location is the asteroid that can *detect* the largest number of other asteroids.
+
+For example, consider the following map:
+
+```
+.#..#
+.....
+#####
+....#
+...*#*#
+```
+
+The best location for a new monitoring station on this map is the highlighted asteroid at `3,4` because it can detect `8` asteroids, more than any other location. (The only asteroid it cannot detect is the one at `1,0`; its view of this asteroid is blocked by the asteroid at `2,2`.) All other asteroids are worse locations; they can detect `7` or fewer other asteroids. Here is the number of other asteroids a monitoring station on each asteroid could detect:
+
+```
+.7..7
+.....
+67775
+....7
+...87
+```
+
+Here is an asteroid (`#`) and some examples of the ways its line of sight might be blocked. If there were another asteroid at the location of a capital letter, the locations marked with the corresponding lowercase letter would be blocked and could not be detected:
+
+```
+#.........
+...A......
+...B..a...
+.EDCG....a
+..F.c.b...
+.....c....
+..efd.c.gb
+.......c..
+....f...c.
+...e..d..c
+```
+
+Here are some larger examples:
+
+
+ - Best is `5,8` with `33` other asteroids detected:
+
+```
+......#.#.
+#..#.#....
+..#######.
+.#.#.###..
+.#..#.....
+..#....#.#
+#..#....#.
+.##.#..###
+##...*#*..#.
+.#....####
+```
+
+ - Best is `1,2` with `35` other asteroids detected:
+
+```
+#.#...#.#.
+.###....#.
+.*#*....#...
+##.#.#.#.#
+....#.#.#.
+.##..###.#
+..#...##..
+..##....##
+......#...
+.####.###.
+```
+
+ - Best is `6,3` with `41` other asteroids detected:
+
+```
+.#..#..###
+####.###.#
+....###.#.
+..###.*#*#.#
+##.##.#.#.
+....###..#
+..#.#..#.#
+#..#.#.###
+.##...##.#
+.....#.#..
+```
+
+ - Best is `11,13` with `210` other asteroids detected:
+
+```
+.#..##.###...#######
+##.############..##.
+.#.######.########.#
+.###.#######.####.#.
+#####.##.#.##.###.##
+..#####..#.#########
+####################
+#.####....###.#.#.##
+##.#################
+#####.##.###..####..
+..######..##.#######
+####.##.####...##..#
+.#####..#.######.###
+##...#.####*#*#####...
+#.##########.#######
+.####.#.###.###.#.##
+....##.##.###..#####
+.#.#.###########.###
+#.#.#.#####.####.###
+###.##.####.##.#..##
+```
+
+
+Find the best location for a new monitoring station. *How many other asteroids can be detected from that location?*
+
+
+## --- Part Two ---
+Once you give them the coordinates, the Elves quickly deploy an Instant Monitoring Station to the location and discover the worst: there are simply too many asteroids.
+
+The only solution is *complete vaporization by giant laser*.
+
+Fortunately, in addition to an asteroid scanner, the new monitoring station also comes equipped with a giant rotating laser perfect for vaporizing asteroids. The laser starts by pointing *up* and always rotates *clockwise*, vaporizing any asteroid it hits.
+
+If multiple asteroids are *exactly* in line with the station, the laser only has enough power to vaporize *one* of them before continuing its rotation. In other words, the same asteroids that can be *detected* can be vaporized, but if vaporizing one asteroid makes another one detectable, the newly-detected asteroid won't be vaporized until the laser has returned to the same position by rotating a full 360 degrees.
+
+For example, consider the following map, where the asteroid with the new monitoring station (and laser) is marked `X`:
+
+```
+.#....#####...#..
+##...##.#####..##
+##...#...#.#####.
+..#.....X...###..
+..#.#.....#....##
+```
+
+The first nine asteroids to get vaporized, in order, would be:
+
+```
+.#....###*2**4*...#..
+##...##.*1**3*#*6**7*..*9*#
+##...#...*5*.*8*####.
+..#.....X...###..
+..#.#.....#....##
+```
+
+Note that some asteroids (the ones behind the asteroids marked `1`, `5`, and `7`) won't have a chance to be vaporized until the next full rotation. The laser continues rotating; the next nine to be vaporized are:
+
+```
+.#....###.....#..
+##...##...#.....#
+##...#......*1**2**3**4*.
+..#.....X...*5*##..
+..#.*9*.....*8*....*7**6*
+```
+
+The next nine to be vaporized are then:
+
+```
+.*8*....###.....#..
+*5**6*...*9*#...#.....#
+*3**4*...*7*...........
+..*2*.....X....##..
+..*1*..............
+```
+
+Finally, the laser completes its first full rotation (`1` through `3`), a second rotation (`4` through `8`), and vaporizes the last asteroid (`9`) partway through its third rotation:
+
+```
+......*2**3**4*.....*6*..
+......*1*...*5*.....*7*
+.................
+........X....*8**9*..
+.................
+```
+
+In the large example above (the one with the best monitoring station location at `11,13`):
+
+
+ - The 1st asteroid to be vaporized is at `11,12`.
+ - The 2nd asteroid to be vaporized is at `12,1`.
+ - The 3rd asteroid to be vaporized is at `12,2`.
+ - The 10th asteroid to be vaporized is at `12,8`.
+ - The 20th asteroid to be vaporized is at `16,0`.
+ - The 50th asteroid to be vaporized is at `16,9`.
+ - The 100th asteroid to be vaporized is at `10,16`.
+ - The 199th asteroid to be vaporized is at `9,6`.
+ - *The 200th asteroid to be vaporized is at `8,2`.*
+ - The 201st asteroid to be vaporized is at `10,9`.
+ - The 299th and final asteroid to be vaporized is at `11,1`.
+
+The Elves are placing bets on which will be the *200th* asteroid to be vaporized. Win the bet by determining which asteroid that will be; *what do you get if you multiply its X coordinate by `100` and then add its Y coordinate?* (For example, `8,2` becomes *`802`*.)
+
+
diff --git a/2019/Day10/input.in b/2019/Day10/input.in
index 546434ef7..defc14888 100644
Binary files a/2019/Day10/input.in and b/2019/Day10/input.in differ
diff --git a/2019/Day11/README.md b/2019/Day11/README.md
index b9a2b021d..c7b8d3346 100644
--- a/2019/Day11/README.md
+++ b/2019/Day11/README.md
@@ -1,6 +1,85 @@
+original source: [https://adventofcode.com/2019/day/11](https://adventofcode.com/2019/day/11)
## --- Day 11: Space Police ---
On the way to Jupiter, you're [pulled over](https://www.youtube.com/watch?v=KwY28rpyKDE) by the *Space Police*.
"Attention, unmarked spacecraft! You are in violation of Space Law! All spacecraft must have a clearly visible *registration identifier*! You have 24 hours to comply or be sent to [Space Jail](https://www.youtube.com/watch?v=BVn1oQL9sWg&t=5)!"
-Read the [full puzzle](https://adventofcode.com/2019/day/11).
\ No newline at end of file
+Not wanting to be sent to Space Jail, you radio back to the Elves on Earth for help. Although it takes almost three hours for their reply signal to reach you, they send instructions for how to power up the *emergency hull painting robot* and even provide a small [Intcode program](9) (your puzzle input) that will cause it to paint your ship appropriately.
+
+There's just one problem: you don't have an emergency hull painting robot.
+
+You'll need to build a new emergency hull painting robot. The robot needs to be able to move around on the grid of square panels on the side of your ship, detect the color of its current panel, and paint its current panel *black* or *white*. (All of the panels are currently *black*.)
+
+The Intcode program will serve as the brain of the robot. The program uses input instructions to access the robot's camera: provide `0` if the robot is over a *black* panel or `1` if the robot is over a *white* panel. Then, the program will output two values:
+
+
+ - First, it will output a value indicating the *color to paint the panel* the robot is over: `0` means to paint the panel *black*, and `1` means to paint the panel *white*.
+ - Second, it will output a value indicating the *direction the robot should turn*: `0` means it should turn *left 90 degrees*, and `1` means it should turn *right 90 degrees*.
+
+After the robot turns, it should always move *forward exactly one panel*. The robot starts facing *up*.
+
+The robot will continue running for a while like this and halt when it is finished drawing. Do not restart the Intcode computer inside the robot during this process.
+
+For example, suppose the robot is about to start running. Drawing black panels as `.`, white panels as `#`, and the robot pointing the direction it is facing (`< ^ > v`), the initial state and region near the robot looks like this:
+
+```
+.....
+.....
+..^..
+.....
+.....
+```
+
+The panel under the robot (not visible here because a `^` is shown instead) is also black, and so any input instructions at this point should be provided `0`. Suppose the robot eventually outputs `1` (paint white) and then `0` (turn left). After taking these actions and moving forward one panel, the region now looks like this:
+
+```
+.....
+.....
+.<#..
+.....
+.....
+```
+
+Input instructions should still be provided `0`. Next, the robot might output `0` (paint black) and then `0` (turn left):
+
+```
+.....
+.....
+..#..
+.v...
+.....
+```
+
+After more outputs (`1,0`, `1,0`):
+
+```
+.....
+.....
+..^..
+.##..
+.....
+```
+
+The robot is now back where it started, but because it is now on a white panel, input instructions should be provided `1`. After several more outputs (`0,1`, `1,0`, `1,0`), the area looks like this:
+
+```
+.....
+..<#.
+...#.
+.##..
+.....
+```
+
+Before you deploy the robot, you should probably have an estimate of the area it will cover: specifically, you need to know the *number of panels it paints at least once*, regardless of color. In the example above, the robot painted *`6` panels* at least once. (It painted its starting panel twice, but that panel is [still only counted once](https://www.youtube.com/watch?v=KjsSvjA5TuE); it also never painted the panel it ended on.)
+
+Build a new emergency hull painting robot and run the Intcode program on it. *How many panels does it paint at least once?*
+
+
+## --- Part Two ---
+You're not sure what it's trying to paint, but it's definitely not a *registration identifier*. The Space Police are getting impatient.
+
+Checking your external ship cameras again, you notice a white panel marked "emergency hull painting robot starting panel". The rest of the panels are *still black*, but it looks like the robot was expecting to *start on a white panel*, not a black one.
+
+Based on the Space Law Space Brochure that the Space Police attached to one of your windows, a valid registration identifier is always *eight capital letters*. After starting the robot on a single *white panel* instead, *what registration identifier does it paint* on your hull?
+
+
diff --git a/2019/Day11/input.in b/2019/Day11/input.in
index bffe73d76..19cd3bde3 100644
Binary files a/2019/Day11/input.in and b/2019/Day11/input.in differ
diff --git a/2019/Day12/README.md b/2019/Day12/README.md
index 28ab5b8a6..8298f7f32 100644
--- a/2019/Day12/README.md
+++ b/2019/Day12/README.md
@@ -1,6 +1,242 @@
+original source: [https://adventofcode.com/2019/day/12](https://adventofcode.com/2019/day/12)
## --- Day 12: The N-Body Problem ---
The space near Jupiter is not a very safe place; you need to be careful of a [big distracting red spot](https://en.wikipedia.org/wiki/Great_Red_Spot), extreme [radiation](https://en.wikipedia.org/wiki/Magnetosphere_of_Jupiter), and a [whole lot of moons](https://en.wikipedia.org/wiki/Moons_of_Jupiter#List) swirling around. You decide to start by tracking the four largest moons: *Io*, *Europa*, *Ganymede*, and *Callisto*.
After a brief scan, you calculate the *position of each moon* (your puzzle input). You just need to *simulate their motion* so you can avoid them.
-Read the [full puzzle](https://adventofcode.com/2019/day/12).
\ No newline at end of file
+Each moon has a 3-dimensional position (`x`, `y`, and `z`) and a 3-dimensional velocity. The position of each moon is given in your scan; the `x`, `y`, and `z` velocity of each moon starts at `0`.
+
+Simulate the motion of the moons in *time steps*. Within each time step, first update the velocity of every moon by applying *gravity*. Then, once all moons' velocities have been updated, update the position of every moon by applying *velocity*. Time progresses by one step once all of the positions are updated.
+
+To apply *gravity*, consider every *pair* of moons. On each axis (`x`, `y`, and `z`), the velocity of each moon changes by *exactly +1 or -1* to pull the moons together. For example, if Ganymede has an `x` position of `3`, and Callisto has a `x` position of `5`, then Ganymede's `x` velocity *changes by +1* (because `5 > 3`) and Callisto's `x` velocity *changes by -1* (because `3 < 5`). However, if the positions on a given axis are the same, the velocity on that axis *does not change* for that pair of moons.
+
+Once all gravity has been applied, apply *velocity*: simply add the velocity of each moon to its own position. For example, if Europa has a position of `x=1, y=2, z=3` and a velocity of `x=-2, y=0,z=3`, then its new position would be `x=-1, y=2, z=6`. This process does not modify the velocity of any moon.
+
+For example, suppose your scan reveals the following positions:
+
+```
+1
), south (2
), west (3
), and east (4
). Any other command is invalid. The movements differ in direction, but not in distance: in a long enough east-west hallway, a series of commands like 4,4,4,4,3,3,3,3
would leave the repair droid back where it started.
+
+The repair droid can reply with any of the following status codes:
+
+
+ - 0
: The repair droid hit a wall. Its position has not changed.
+ - 1
: The repair droid has moved one step in the requested direction.
+ - 2
: The repair droid has moved one step in the requested direction; its new position is the location of the oxygen system.
+
+You don't know anything about the area around the repair droid, but you can figure it out by watching the status codes.
+
+For example, we can draw the area using D
for the droid, #
for walls, .
for locations the droid can traverse, and empty space for unexplored locations. Then, the initial state looks like this:
+
+
+
+
+ D
+
+
+
+
+
+To make the droid go north, send it 1
. If it replies with 0
, you know that location is a wall and that the droid didn't move:
+
+
+
+ #
+ D
+
+
+
+
+
+To move east, send 4
; a reply of 1
means the movement was successful:
+
+
+
+ #
+ .D
+
+
+
+
+
+Then, perhaps attempts to move north (1
), south (2
), and east (4
) are all met with replies of 0
:
+
+
+
+ ##
+ .D#
+ #
+
+
+
+
+Now, you know the repair droid is in a dead end. Backtrack with 3
(which you already know will get a reply of 1
because you already know that location is open):
+
+
+
+ ##
+ D.#
+ #
+
+
+
+
+Then, perhaps west (3
) gets a reply of 0
, south (2
) gets a reply of 1
, south again (2
) gets a reply of 0
, and then west (3
) gets a reply of 2
:
+
+
+
+ ##
+ #..#
+ D.#
+ #
+
+
+
+Now, because of the reply of 2
, you know you've found the oxygen system! In this example, it was only 2
moves away from the repair droid's starting position.
+
+What is the fewest number of movement commands required to move the repair droid from its starting position to the location of the oxygen system?
+
+
+## --- Part Two ---
+You quickly repair the oxygen system; oxygen gradually fills the area.
+
+Oxygen starts in the location containing the repaired oxygen system. It takes one minute for oxygen to spread to all open locations that are adjacent to a location that already contains oxygen. Diagonal locations are not adjacent.
+
+In the example above, suppose you've used the droid to explore the area fully and have the following map (where locations that currently contain oxygen are marked O
):
+
+
+ ##
+#..##
+#.#..#
+#.O.#
+ ###
+
+
+
+Initially, the only location which contains oxygen is the location of the repaired oxygen system. However, after one minute, the oxygen spreads to all open (.
) locations that are adjacent to a location containing oxygen:
+
+
+ ##
+#..##
+#.#..#
+#OOO#
+ ###
+
+
+
+After a total of two minutes, the map looks like this:
+
+
+ ##
+#..##
+#O#O.#
+#OOO#
+ ###
+
+
+
+After a total of three minutes:
+
+
+ ##
+#O.##
+#O#OO#
+#OOO#
+ ###
+
+
+
+And finally, the whole region is full of oxygen after a total of four minutes:
+
+
+ ##
+#OO##
+#O#OO#
+#OOO#
+ ###
+
+
+
+So, in this example, all locations contain oxygen after 4
minutes.
+
+Use the repair droid to get a complete map of the area. How many minutes will it take to fill with oxygen?
+
+
diff --git a/2019/Day15/input.in b/2019/Day15/input.in
index 62aa67426..3a7a90f94 100644
Binary files a/2019/Day15/input.in and b/2019/Day15/input.in differ
diff --git a/2019/Day16/README.md b/2019/Day16/README.md
index 719505721..696a371f8 100644
--- a/2019/Day16/README.md
+++ b/2019/Day16/README.md
@@ -1,6 +1,93 @@
+original source: [https://adventofcode.com/2019/day/16](https://adventofcode.com/2019/day/16)
## --- Day 16: Flawed Frequency Transmission ---
You're 3/4ths of the way through the [gas giants](https://en.wikipedia.org/wiki/Gas_giant). Not only do roundtrip signals to Earth take five hours, but the signal quality is quite bad as well. You can clean up the signal with the Flawed Frequency Transmission algorithm, or *FFT*.
As input, FFT takes a list of numbers. In the signal you received (your puzzle input), each number is a single digit: data like `15243` represents the sequence `1`, `5`, `2`, `4`, `3`.
-Read the [full puzzle](https://adventofcode.com/2019/day/16).
\ No newline at end of file
+FFT operates in repeated *phases*. In each phase, a new list is constructed with the same length as the input list. This new list is also used as the input for the next phase.
+
+Each element in the new list is built by multiplying every value in the input list by a value in a repeating *pattern* and then adding up the results. So, if the input list were `9, 8, 7, 6, 5` and the pattern for a given element were `1, 2, 3`, the result would be `9*1 + 8*2 + 7*3 + 6*1 + 5*2` (with each input element on the left and each value in the repeating pattern on the right of each multiplication). Then, only the ones digit is kept: `38` becomes `8`, `-17` becomes `7`, and so on.
+
+While each element in the output array uses all of the same input array elements, the actual repeating pattern to use depends on *which output element* is being calculated. The base pattern is `0, 1, 0, -1`. Then, repeat each value in the pattern a number of times equal to the *position in the output list* being considered. Repeat once for the first element, twice for the second element, three times for the third element, and so on. So, if the third element of the output list is being calculated, repeating the values would produce: `0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, -1`.
+
+When applying the pattern, skip the very first value exactly once. (In other words, offset the whole pattern left by one.) So, for the second element of the output list, the actual pattern used would be: `0, 1, 1, 0, 0, -1, -1, 0, 0, 1, 1, 0, 0, -1, -1, ...`.
+
+After using this process to calculate each element of the output list, the phase is complete, and the output list of this phase is used as the new input list for the next phase, if any.
+
+Given the input signal `12345678`, below are four phases of FFT. Within each phase, each output digit is calculated on a single line with the result at the far right; each multiplication operation shows the input digit on the left and the pattern value on the right:
+
+```
+Input signal: 12345678
+
+1*1 + 2*0 + 3*-1 + 4*0 + 5*1 + 6*0 + 7*-1 + 8*0 = 4
+1*0 + 2*1 + 3*1 + 4*0 + 5*0 + 6*-1 + 7*-1 + 8*0 = 8
+1*0 + 2*0 + 3*1 + 4*1 + 5*1 + 6*0 + 7*0 + 8*0 = 2
+1*0 + 2*0 + 3*0 + 4*1 + 5*1 + 6*1 + 7*1 + 8*0 = 2
+1*0 + 2*0 + 3*0 + 4*0 + 5*1 + 6*1 + 7*1 + 8*1 = 6
+1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*1 + 7*1 + 8*1 = 1
+1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*0 + 7*1 + 8*1 = 5
+1*0 + 2*0 + 3*0 + 4*0 + 5*0 + 6*0 + 7*0 + 8*1 = 8
+
+After 1 phase: 48226158
+
+4*1 + 8*0 + 2*-1 + 2*0 + 6*1 + 1*0 + 5*-1 + 8*0 = 3
+4*0 + 8*1 + 2*1 + 2*0 + 6*0 + 1*-1 + 5*-1 + 8*0 = 4
+4*0 + 8*0 + 2*1 + 2*1 + 6*1 + 1*0 + 5*0 + 8*0 = 0
+4*0 + 8*0 + 2*0 + 2*1 + 6*1 + 1*1 + 5*1 + 8*0 = 4
+4*0 + 8*0 + 2*0 + 2*0 + 6*1 + 1*1 + 5*1 + 8*1 = 0
+4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*1 + 5*1 + 8*1 = 4
+4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*0 + 5*1 + 8*1 = 3
+4*0 + 8*0 + 2*0 + 2*0 + 6*0 + 1*0 + 5*0 + 8*1 = 8
+
+After 2 phases: 34040438
+
+3*1 + 4*0 + 0*-1 + 4*0 + 0*1 + 4*0 + 3*-1 + 8*0 = 0
+3*0 + 4*1 + 0*1 + 4*0 + 0*0 + 4*-1 + 3*-1 + 8*0 = 3
+3*0 + 4*0 + 0*1 + 4*1 + 0*1 + 4*0 + 3*0 + 8*0 = 4
+3*0 + 4*0 + 0*0 + 4*1 + 0*1 + 4*1 + 3*1 + 8*0 = 1
+3*0 + 4*0 + 0*0 + 4*0 + 0*1 + 4*1 + 3*1 + 8*1 = 5
+3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*1 + 3*1 + 8*1 = 5
+3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*1 + 8*1 = 1
+3*0 + 4*0 + 0*0 + 4*0 + 0*0 + 4*0 + 3*0 + 8*1 = 8
+
+After 3 phases: 03415518
+
+0*1 + 3*0 + 4*-1 + 1*0 + 5*1 + 5*0 + 1*-1 + 8*0 = 0
+0*0 + 3*1 + 4*1 + 1*0 + 5*0 + 5*-1 + 1*-1 + 8*0 = 1
+0*0 + 3*0 + 4*1 + 1*1 + 5*1 + 5*0 + 1*0 + 8*0 = 0
+0*0 + 3*0 + 4*0 + 1*1 + 5*1 + 5*1 + 1*1 + 8*0 = 2
+0*0 + 3*0 + 4*0 + 1*0 + 5*1 + 5*1 + 1*1 + 8*1 = 9
+0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*1 + 1*1 + 8*1 = 4
+0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*1 + 8*1 = 9
+0*0 + 3*0 + 4*0 + 1*0 + 5*0 + 5*0 + 1*0 + 8*1 = 8
+
+After 4 phases: 01029498
+```
+
+Here are the first eight digits of the final output list after 100 phases for some larger inputs:
+
+
+ - `80871224585914546619083218645595` becomes `24176176`.
+ - `19617804207202209144916044189917` becomes `73745418`.
+ - `69317163492948606335995924319873` becomes `52432133`.
+
+After *100* phases of FFT, *what are the first eight digits in the final output list?*
+
+
+## --- Part Two ---
+Now that your FFT is working, you can decode the *real signal*.
+
+The real signal is your puzzle input *repeated 10000 times*. Treat this new signal as a single input list. Patterns are still calculated as before, and 100 phases of FFT are still applied.
+
+The *first seven digits* of your initial input signal also represent the *message offset*. The message offset is the location of the eight-digit message in the final output list. Specifically, the message offset indicates *the number of digits to skip* before reading the eight-digit message. For example, if the first seven digits of your initial input signal were `1234567`, the eight-digit message would be the eight digits after skipping 1,234,567 digits of the final output list. Or, if the message offset were `7` and your final output list were `98765432109876543210`, the eight-digit message would be `21098765`. (Of course, your real message offset will be a seven-digit number, not a one-digit number like `7`.)
+
+Here is the eight-digit message in the final output list after 100 phases. The message offset given in each input has been highlighted. (Note that the inputs given below are repeated 10000 times to find the actual starting input lists.)
+
+
+ - `*0303673*2577212944063491565474664` becomes `84462026`.
+ - `*0293510*9699940807407585447034323` becomes `78725270`.
+ - `*0308177*0884921959731165446850517` becomes `53553731`.
+
+After repeating your input signal 10000 times and running 100 phases of FFT, *what is the eight-digit message embedded in the final output list?*
+
+
diff --git a/2019/Day16/input.in b/2019/Day16/input.in
index 745b563e4..68cecfd2d 100644
Binary files a/2019/Day16/input.in and b/2019/Day16/input.in differ
diff --git a/2019/Day17/README.md b/2019/Day17/README.md
index 4bd898a5d..1077776c4 100644
--- a/2019/Day17/README.md
+++ b/2019/Day17/README.md
@@ -1,6 +1,135 @@
+original source: [https://adventofcode.com/2019/day/17](https://adventofcode.com/2019/day/17)
## --- Day 17: Set and Forget ---
An early warning system detects an incoming [solar flare](https://en.wikipedia.org/wiki/Solar_flare) and automatically activates the ship's electromagnetic shield. Unfortunately, this has cut off the Wi-Fi for many small robots that, unaware of the impending danger, are now trapped on exterior scaffolding on the unsafe side of the shield. To rescue them, you'll have to act quickly!
The only tools at your disposal are some wired cameras and a small vacuum robot currently asleep at its charging station. The video quality is poor, but the vacuum robot has a needlessly bright LED that makes it easy to spot no matter where it is.
-Read the [full puzzle](https://adventofcode.com/2019/day/17).
\ No newline at end of file
+An [Intcode](9) program, the *Aft Scaffolding Control and Information Interface* (ASCII, your puzzle input), provides access to the cameras and the vacuum robot. Currently, because the vacuum robot is asleep, you can only access the cameras.
+
+Running the ASCII program on your Intcode computer will provide the current view of the scaffolds. This is output, purely coincidentally, as [ASCII code](https://simple.wikipedia.org/wiki/ASCII): `35` means `#`, `46` means `.`, `10` starts a [new line](https://en.wikipedia.org/wiki/Newline#In_programming_languages) of output below the current one, and so on. (Within a line, characters are drawn left-to-right.)
+
+In the camera output, `#` represents a scaffold and `.` represents open space. The vacuum robot is visible as `^`, `v`, `<`, or `>` depending on whether it is facing up, down, left, or right respectively. When drawn like this, the vacuum robot is *always on a scaffold*; if the vacuum robot ever walks off of a scaffold and begins *tumbling through space uncontrollably*, it will instead be visible as `X`.
+
+In general, the scaffold forms a path, but it sometimes loops back onto itself. For example, suppose you can see the following view from the cameras:
+
+```
+..#..........
+..#..........
+#######...###
+#.#...#...#.#
+#############
+..#...#...#..
+..#####...^..
+```
+
+Here, the vacuum robot, `^` is facing up and sitting at one end of the scaffold near the bottom-right of the image. The scaffold continues up, loops across itself several times, and ends at the top-left of the image.
+
+The first step is to calibrate the cameras by getting the *alignment parameters* of some well-defined points. Locate all *scaffold intersections*; for each, its alignment parameter is the distance between its left edge and the left edge of the view multiplied by the distance between its top edge and the top edge of the view. Here, the intersections from the above image are marked `O`:
+
+```
+..#..........
+..#..........
+##O####...###
+#.#...#...#.#
+##O###O###O##
+..#...#...#..
+..#####...^..
+```
+
+For these intersections:
+
+
+ - The top-left intersection is `2` units from the left of the image and `2` units from the top of the image, so its alignment parameter is `2 * 2 = *4*`.
+ - The bottom-left intersection is `2` units from the left and `4` units from the top, so its alignment parameter is `2 * 4 = *8*`.
+ - The bottom-middle intersection is `6` from the left and `4` from the top, so its alignment parameter is `*24*`.
+ - The bottom-right intersection's alignment parameter is `*40*`.
+
+To calibrate the cameras, you need the *sum of the alignment parameters*. In the above example, this is `*76*`.
+
+Run your ASCII program. *What is the sum of the alignment parameters* for the scaffold intersections?
+
+
+## --- Part Two ---
+Now for the tricky part: notifying all the other robots about the solar flare. The vacuum robot can do this automatically if it gets into range of a robot. However, you can't see the other robots on the camera, so you need to be thorough instead: you need to make the vacuum robot *visit every part of the scaffold at least once*.
+
+The vacuum robot normally wanders randomly, but there isn't time for that today. Instead, you can *override its movement logic* with new rules.
+
+Force the vacuum robot to wake up by changing the value in your ASCII program at address `0` from `1` to `*2*`. When you do this, you will be automatically prompted for the new movement rules that the vacuum robot should use. The ASCII program will use input instructions to receive them, but they need to be provided as ASCII code; end each line of logic with a single newline, ASCII code `10`.
+
+First, you will be prompted for the *main movement routine*. The main routine may only call the *movement functions*: `A`, `B`, or `C`. Supply the movement functions to use as ASCII text, separating them with commas (`,`, ASCII code `44`), and ending the list with a newline (ASCII code `10`). For example, to call `A` twice, then alternate between `B` and `C` three times, provide the string `A,A,B,C,B,C,B,C` and then a newline.
+
+Then, you will be prompted for each *movement function*. Movement functions may use `L` to *turn left*, `R` to *turn right*, or a number to *move forward* that many units. Movement functions may not call other movement functions. Again, separate the actions with commas and end the list with a newline. For example, to move forward `10` units, turn left, move forward `8` units, turn right, and finally move forward `6` units, provide the string `10,L,8,R,6` and then a newline.
+
+Finally, you will be asked whether you want to see a *continuous video feed*; provide either `y` or `n` and a newline. Enabling the continuous video feed can help you see what's going on, but it also requires a significant amount of processing power, and may even cause your Intcode computer to overheat.
+
+Due to the limited amount of memory in the vacuum robot, the ASCII definitions of the main routine and the movement functions may each contain *at most 20 characters*, not counting the newline.
+
+For example, consider the following camera feed:
+
+```
+#######...#####
+#.....#...#...#
+#.....#...#...#
+......#...#...#
+......#...###.#
+......#.....#.#
+^########...#.#
+......#.#...#.#
+......#########
+........#...#..
+....#########..
+....#...#......
+....#...#......
+....#...#......
+....#####......
+```
+
+In order for the vacuum robot to *visit every part of the scaffold at least once*, one path it could take is:
+
+```
+R,8,R,8,R,4,R,4,R,8,L,6,L,2,R,4,R,4,R,8,R,8,R,8,L,6,L,2```
+
+Without the memory limit, you could just supply this whole string to function `A` and have the main routine call `A` once. However, you'll need to split it into smaller parts.
+
+One approach is:
+
+
+ - *Main routine: `A,B,C,B,A,C`*
+(ASCII input: `65`, `44`, `66`, `44`, `67`, `44`, `66`, `44`, `65`, `44`, `67`, `10`)
+ - *Function `A`: `R,8,R,8`*
+(ASCII input: `82`, `44`, `56`, `44`, `82`, `44`, `56`, `10`)
+ - *Function `B`: `R,4,R,4,R,8`*
+(ASCII input: `82`, `44`, `52`, `44`, `82`, `44`, `52`, `44`, `82`, `44`, `56`, `10`)
+ - *Function `C`: `L,6,L,2`*
+(ASCII input: `76`, `44`, `54`, `44`, `76`, `44`, `50`, `10`)
+
+Visually, this would break the desired path into the following parts:
+
+```
+A, B, C, B, A, C
+R,8,R,8, R,4,R,4,R,8, L,6,L,2, R,4,R,4,R,8, R,8,R,8, L,6,L,2
+
+CCCCCCA...BBBBB
+C.....A...B...B
+C.....A...B...B
+......A...B...B
+......A...CCC.B
+......A.....C.B
+^AAAAAAAA...C.B
+......A.A...C.B
+......AAAAAA#AB
+........A...C..
+....BBBB#BBBB..
+....B...A......
+....B...A......
+....B...A......
+....BBBBA......
+```
+
+Of course, the scaffolding outside your ship is much more complex.
+
+As the vacuum robot finds other robots and notifies them of the impending solar flare, it also can't help but leave them squeaky clean, collecting any space dust it finds. Once it finishes the programmed set of movements, assuming it hasn't drifted off into space, the cleaning robot will return to its docking station and report the amount of space dust it collected as a large, non-ASCII value in a single output instruction.
+
+After visiting every part of the scaffold at least once, *how much dust does the vacuum robot report it has collected?*
+
+
diff --git a/2019/Day17/input.in b/2019/Day17/input.in
index b98176f73..a2fbf0dce 100644
Binary files a/2019/Day17/input.in and b/2019/Day17/input.in differ
diff --git a/2019/Day18/README.md b/2019/Day18/README.md
index 21878042c..d28897b42 100644
--- a/2019/Day18/README.md
+++ b/2019/Day18/README.md
@@ -1,6 +1,294 @@
+original source: [https://adventofcode.com/2019/day/18](https://adventofcode.com/2019/day/18)
## --- Day 18: Many-Worlds Interpretation ---
As you approach Neptune, a planetary security system detects you and activates a giant [tractor beam](https://en.wikipedia.org/wiki/Tractor_beam) on [Triton](https://en.wikipedia.org/wiki/Triton_(moon))! You have no choice but to land.
A scan of the local area reveals only one interesting feature: a massive underground vault. You generate a map of the tunnels (your puzzle input). The tunnels are too narrow to move diagonally.
-Read the [full puzzle](https://adventofcode.com/2019/day/18).
\ No newline at end of file
+Only one *entrance* (marked `@`) is present among the *open passages* (marked `.`) and *stone walls* (`#`), but you also detect an assortment of *keys* (shown as lowercase letters) and *doors* (shown as uppercase letters). Keys of a given letter open the door of the same letter: `a` opens `A`, `b` opens `B`, and so on. You aren't sure which key you need to disable the tractor beam, so you'll need to *collect all of them*.
+
+For example, suppose you have the following map:
+
+```
+#########
+#b.A.@.a#
+#########
+```
+
+Starting from the entrance (`@`), you can only access a large door (`A`) and a key (`a`). Moving toward the door doesn't help you, but you can move `2` steps to collect the key, unlocking `A` in the process:
+
+```
+#########
+#b.....@#
+#########
+```
+
+Then, you can move `6` steps to collect the only other key, `b`:
+
+```
+#########
+#@......#
+#########
+```
+
+So, collecting every key took a total of `*8*` steps.
+
+Here is a larger example:
+
+```
+########################
+#f.D.E.e.C.b.A.@.a.B.c.#
+######################.#
+#d.....................#
+########################
+```
+
+The only reasonable move is to take key `a` and unlock door `A`:
+
+```
+########################
+#f.D.E.e.C.b.....@.B.c.#
+######################.#
+#d.....................#
+########################
+```
+
+Then, do the same with key `b`:
+
+```
+########################
+#f.D.E.e.C.@.........c.#
+######################.#
+#d.....................#
+########################
+```
+
+...and the same with key `c`:
+
+```
+########################
+#f.D.E.e.............@.#
+######################.#
+#d.....................#
+########################
+```
+
+Now, you have a choice between keys `d` and `e`. While key `e` is closer, collecting it now would be slower in the long run than collecting key `d` first, so that's the best choice:
+
+```
+########################
+#f...E.e...............#
+######################.#
+#@.....................#
+########################
+```
+
+Finally, collect key `e` to unlock door `E`, then collect key `f`, taking a grand total of `*86*` steps.
+
+Here are a few more examples:
+
+
+ - ```
+########################
+#...............b.C.D.f#
+#.######################
+#.....@.a.B.c.d.A.e.F.g#
+########################
+```
+
+Shortest path is `132` steps: `b`, `a`, `c`, `d`, `f`, `e`, `g`
+
+ - ```
+#################
+#i.G..c...e..H.p#
+########.########
+#j.A..b...f..D.o#
+########@########
+#k.E..a...g..B.n#
+########.########
+#l.F..d...h..C.m#
+#################
+```
+
+Shortest paths are `136` steps;
+one is: `a`, `f`, `b`, `j`, `g`, `n`, `h`, `d`, `l`, `o`, `e`, `p`, `c`, `i`, `k`, `m`
+
+ - ```
+########################
+#@..............ac.GI.b#
+###d#e#f################
+###A#B#C################
+###g#h#i################
+########################
+```
+
+Shortest paths are `81` steps; one is: `a`, `c`, `f`, `i`, `d`, `g`, `b`, `e`, `h`
+
+
+*How many steps is the shortest path that collects all of the keys?*
+
+
+## --- Part Two ---
+You arrive at the vault only to discover that there is not one vault, but *four* - each with its own entrance.
+
+On your map, find the area in the middle that looks like this:
+
+```
+...
+.@.
+...
+```
+
+Update your map to instead use the correct data:
+
+```
+@#@
+###
+@#@
+```
+
+This change will split your map into four separate sections, each with its own entrance:
+
+```
+####### #######
+#a.#Cd# #a.#Cd#
+##...## ##*@#@*##
+##.@.## --> ##*###*##
+##...## ##*@#@*##
+#cB#Ab# #cB#Ab#
+####### #######
+```
+
+Because some of the keys are for doors in other vaults, it would take much too long to collect all of the keys by yourself. Instead, you deploy four remote-controlled robots. Each starts at one of the entrances (`@`).
+
+Your goal is still to *collect all of the keys in the fewest steps*, but now, each robot has its own position and can move independently. You can only remotely control a single robot at a time. Collecting a key instantly unlocks any corresponding doors, regardless of the vault in which the key or door is found.
+
+For example, in the map above, the top-left robot first collects key `a`, unlocking door `A` in the bottom-right vault:
+
+```
+#######
+#@.#Cd#
+##.#@##
+#######
+##@#@##
+#cB#.b#
+#######
+```
+
+Then, the bottom-right robot collects key `b`, unlocking door `B` in the bottom-left vault:
+
+```
+#######
+#@.#Cd#
+##.#@##
+#######
+##@#.##
+#c.#.@#
+#######
+```
+
+Then, the bottom-left robot collects key `c`:
+
+```
+#######
+#@.#.d#
+##.#@##
+#######
+##.#.##
+#@.#.@#
+#######
+```
+
+Finally, the top-right robot collects key `d`:
+
+```
+#######
+#@.#.@#
+##.#.##
+#######
+##.#.##
+#@.#.@#
+#######
+```
+
+In this example, it only took `*8*` steps to collect all of the keys.
+
+Sometimes, multiple robots might have keys available, or a robot might have to wait for multiple keys to be collected:
+
+```
+###############
+#d.ABC.#.....a#
+######@#@######
+###############
+######@#@######
+#b.....#.....c#
+###############
+```
+
+First, the top-right, bottom-left, and bottom-right robots take turns collecting keys `a`, `b`, and `c`, a total of `6 + 6 + 6 = 18` steps. Then, the top-left robot can access key `d`, spending another `6` steps; collecting all of the keys here takes a minimum of `*24*` steps.
+
+Here's a more complex example:
+
+```
+#############
+#DcBa.#.GhKl#
+#.###@#@#I###
+#e#d#####j#k#
+###C#@#@###J#
+#fEbA.#.FgHi#
+#############
+```
+
+
+ - Top-left robot collects key `a`.
+ - Bottom-left robot collects key `b`.
+ - Top-left robot collects key `c`.
+ - Bottom-left robot collects key `d`.
+ - Top-left robot collects key `e`.
+ - Bottom-left robot collects key `f`.
+ - Bottom-right robot collects key `g`.
+ - Top-right robot collects key `h`.
+ - Bottom-right robot collects key `i`.
+ - Top-right robot collects key `j`.
+ - Bottom-right robot collects key `k`.
+ - Top-right robot collects key `l`.
+
+In the above example, the fewest steps to collect all of the keys is `*32*`.
+
+Here's an example with more choices:
+
+```
+#############
+#g#f.D#..h#l#
+#F###e#E###.#
+#dCba@#@BcIJ#
+#############
+#nK.L@#@G...#
+#M###N#H###.#
+#o#m..#i#jk.#
+#############
+```
+
+One solution with the fewest steps is:
+
+
+ - Top-left robot collects key `e`.
+ - Top-right robot collects key `h`.
+ - Bottom-right robot collects key `i`.
+ - Top-left robot collects key `a`.
+ - Top-left robot collects key `b`.
+ - Top-right robot collects key `c`.
+ - Top-left robot collects key `d`.
+ - Top-left robot collects key `f`.
+ - Top-left robot collects key `g`.
+ - Bottom-right robot collects key `k`.
+ - Bottom-right robot collects key `j`.
+ - Top-right robot collects key `l`.
+ - Bottom-left robot collects key `n`.
+ - Bottom-left robot collects key `m`.
+ - Bottom-left robot collects key `o`.
+
+This example requires at least `*72*` steps to collect all keys.
+
+After updating your map and using the remote-controlled robots, *what is the fewest steps necessary to collect all of the keys?*
+
+
diff --git a/2019/Day18/input.in b/2019/Day18/input.in
index d736bce82..123b7c740 100644
Binary files a/2019/Day18/input.in and b/2019/Day18/input.in differ
diff --git a/2019/Day19/README.md b/2019/Day19/README.md
index a0a240e7a..113218a28 100644
--- a/2019/Day19/README.md
+++ b/2019/Day19/README.md
@@ -1,6 +1,82 @@
+original source: [https://adventofcode.com/2019/day/19](https://adventofcode.com/2019/day/19)
## --- Day 19: Tractor Beam ---
Unsure of the state of Santa's ship, you borrowed the tractor beam technology from Triton. Time to test it out.
When you're safely away from anything else, you activate the tractor beam, but nothing happens. It's hard to tell whether it's working if there's nothing to use it on. Fortunately, your ship's drone system can be configured to deploy a drone to specific coordinates and then check whether it's being pulled. There's even an [Intcode](9) program (your puzzle input) that gives you access to the drone system.
-Read the [full puzzle](https://adventofcode.com/2019/day/19).
\ No newline at end of file
+The program uses two input instructions to request the *X and Y position* to which the drone should be deployed. Negative numbers are invalid and will confuse the drone; all numbers should be *zero or positive*.
+
+Then, the program will output whether the drone is *stationary* (`0`) or *being pulled by something* (`1`). For example, the coordinate X=`0`, Y=`0` is directly in front of the tractor beam emitter, so the drone control program will always report `1` at that location.
+
+To better understand the tractor beam, it is important to *get a good picture* of the beam itself. For example, suppose you scan the 10x10 grid of points closest to the emitter:
+
+```
+ X
+ 0-> 9
+ 0#.........
+ |.#........
+ v..##......
+ ...###....
+ ....###...
+Y .....####.
+ ......####
+ ......####
+ .......###
+ 9........##
+```
+
+In this example, the *number of points affected by the tractor beam* in the 10x10 area closest to the emitter is `*27*`.
+
+However, you'll need to scan a larger area to *understand the shape* of the beam. *How many points are affected by the tractor beam in the 50x50 area closest to the emitter?* (For each of X and Y, this will be `0` through `49`.)
+
+
+## --- Part Two ---
+You aren't sure how large Santa's ship is. You aren't even sure if you'll need to use this thing on Santa's ship, but it doesn't hurt to be prepared. You figure Santa's ship might fit in a *100x100* square.
+
+The beam gets wider as it travels away from the emitter; you'll need to be a minimum distance away to fit a square of that size into the beam fully. (Don't rotate the square; it should be aligned to the same axes as the drone grid.)
+
+For example, suppose you have the following tractor beam readings:
+
+```
+#.......................................
+.#......................................
+..##....................................
+...###..................................
+....###.................................
+.....####...............................
+......#####.............................
+......######............................
+.......#######..........................
+........########........................
+.........#########......................
+..........#########.....................
+...........##########...................
+...........############.................
+............############................
+.............#############..............
+..............##############............
+...............###############..........
+................###############.........
+................#################.......
+.................########*O*OOOOOOOOO.....
+..................#######OOOOOOOOOO#....
+...................######OOOOOOOOOO###..
+....................#####OOOOOOOOOO#####
+.....................####OOOOOOOOOO#####
+.....................####OOOOOOOOOO#####
+......................###OOOOOOOOOO#####
+.......................##OOOOOOOOOO#####
+........................#OOOOOOOOOO#####
+.........................OOOOOOOOOO#####
+..........................##############
+..........................##############
+...........................#############
+............................############
+.............................###########
+```
+
+In this example, the *10x10* square closest to the emitter that fits entirely within the tractor beam has been marked `O`. Within it, the point closest to the emitter (the only highlighted `*O*`) is at X=`25`, Y=`20`.
+
+Find the *100x100* square closest to the emitter that fits entirely within the tractor beam; within that square, find the point closest to the emitter. *What value do you get if you take that point's X coordinate, multiply it by `10000`, then add the point's Y coordinate?* (In the example above, this would be `250020`.)
+
+
diff --git a/2019/Day19/input.in b/2019/Day19/input.in
index bca68256b..b50dd1d64 100644
Binary files a/2019/Day19/input.in and b/2019/Day19/input.in differ
diff --git a/2019/Day20/README.md b/2019/Day20/README.md
index 3fe880d51..7991b7245 100644
--- a/2019/Day20/README.md
+++ b/2019/Day20/README.md
@@ -1,6 +1,212 @@
+original source: [https://adventofcode.com/2019/day/20](https://adventofcode.com/2019/day/20)
## --- Day 20: Donut Maze ---
You notice a strange pattern on the surface of Pluto and land nearby to get a closer look. Upon closer inspection, you realize you've come across one of the famous space-warping mazes of the long-lost Pluto civilization!
Because there isn't much space on Pluto, the civilization that used to live here thrived by inventing a method for folding spacetime. Although the technology is no longer understood, mazes like this one provide a small glimpse into the daily life of an ancient Pluto citizen.
-Read the [full puzzle](https://adventofcode.com/2019/day/20).
\ No newline at end of file
+This maze is shaped like a [donut](https://en.wikipedia.org/wiki/Torus). Portals along the inner and outer edge of the donut can instantly teleport you from one side to the other. For example:
+
+```
+ A
+ A
+ #######.#########
+ #######.........#
+ #######.#######.#
+ #######.#######.#
+ #######.#######.#
+ ##### B ###.#
+BC...## C ###.#
+ ##.## ###.#
+ ##...DE F ###.#
+ ##### G ###.#
+ #########.#####.#
+DE..#######...###.#
+ #.#########.###.#
+FG..#########.....#
+ ###########.#####
+ Z
+ Z
+```
+
+This map of the maze shows solid walls (`#`) and open passages (`.`). Every maze on Pluto has a start (the open tile next to `AA`) and an end (the open tile next to `ZZ`). Mazes on Pluto also have portals; this maze has three pairs of portals: `BC`, `DE`, and `FG`. When on an open tile next to one of these labels, a single step can take you to the other tile with the same label. (You can only walk on `.` tiles; labels and empty space are not traversable.)
+
+One path through the maze doesn't require any portals. Starting at `AA`, you could go down 1, right 8, down 12, left 4, and down 1 to reach `ZZ`, a total of 26 steps.
+
+However, there is a shorter path: You could walk from `AA` to the inner `BC` portal (4 steps), warp to the outer `BC` portal (1 step), walk to the inner `DE` (6 steps), warp to the outer `DE` (1 step), walk to the outer `FG` (4 steps), warp to the inner `FG` (1 step), and finally walk to `ZZ` (6 steps). In total, this is only *23* steps.
+
+Here is a larger example:
+
+```
+ A
+ A
+ #################.#############
+ #.#...#...................#.#.#
+ #.#.#.###.###.###.#########.#.#
+ #.#.#.......#...#.....#.#.#...#
+ #.#########.###.#####.#.#.###.#
+ #.............#.#.....#.......#
+ ###.###########.###.#####.#.#.#
+ #.....# A C #.#.#.#
+ ####### S P #####.#
+ #.#...# #......VT
+ #.#.#.# #.#####
+ #...#.# YN....#.#
+ #.###.# #####.#
+DI....#.# #.....#
+ #####.# #.###.#
+ZZ......# QG....#..AS
+ ###.### #######
+JO..#.#.# #.....#
+ #.#.#.# ###.#.#
+ #...#..DI BU....#..LF
+ #####.# #.#####
+YN......# VT..#....QG
+ #.###.# #.###.#
+ #.#...# #.....#
+ ###.### J L J #.#.###
+ #.....# O F P #.#...#
+ #.###.#####.#.#####.#####.###.#
+ #...#.#.#...#.....#.....#.#...#
+ #.#####.###.###.#.#.#########.#
+ #...#.#.....#...#.#.#.#.....#.#
+ #.###.#####.###.###.#.#.#######
+ #.#.........#...#.............#
+ #########.###.###.#############
+ B J C
+ U P P
+```
+
+Here, `AA` has no direct path to `ZZ`, but it does connect to `AS` and `CP`. By passing through `AS`, `QG`, `BU`, and `JO`, you can reach `ZZ` in *58* steps.
+
+In your maze, *how many steps does it take to get from the open tile marked `AA` to the open tile marked `ZZ`?*
+
+
+## --- Part Two ---
+Strangely, the exit isn't open when you reach it. Then, you remember: the ancient Plutonians were famous for building *recursive spaces*.
+
+The marked connections in the maze aren't portals: they *physically connect* to a larger or smaller copy of the maze. Specifically, the labeled tiles around the inside edge actually connect to a smaller copy of the same maze, and the smaller copy's inner labeled tiles connect to yet a *smaller* copy, and so on.
+
+When you enter the maze, you are at the outermost level; when at the outermost level, only the outer labels `AA` and `ZZ` function (as the start and end, respectively); all other outer labeled tiles are effectively walls. At any other level, `AA` and `ZZ` count as walls, but the other outer labeled tiles bring you one level outward.
+
+Your goal is to find a path through the maze that brings you back to `ZZ` at the outermost level of the maze.
+
+In the first example above, the shortest path is now the loop around the right side. If the starting level is `0`, then taking the previously-shortest path would pass through `BC` (to level `1`), `DE` (to level `2`), and `FG` (back to level `1`). Because this is not the outermost level, `ZZ` is a wall, and the only option is to go back around to `BC`, which would only send you even deeper into the recursive maze.
+
+In the second example above, there is no path that brings you to `ZZ` at the outermost level.
+
+Here is a more interesting example:
+
+```
+ Z L X W C
+ Z P Q B K
+ ###########.#.#.#.#######.###############
+ #...#.......#.#.......#.#.......#.#.#...#
+ ###.#.#.#.#.#.#.#.###.#.#.#######.#.#.###
+ #.#...#.#.#...#.#.#...#...#...#.#.......#
+ #.###.#######.###.###.#.###.###.#.#######
+ #...#.......#.#...#...#.............#...#
+ #.#########.#######.#.#######.#######.###
+ #...#.# F R I Z #.#.#.#
+ #.###.# D E C H #.#.#.#
+ #.#...# #...#.#
+ #.###.# #.###.#
+ #.#....OA WB..#.#..ZH
+ #.###.# #.#.#.#
+CJ......# #.....#
+ ####### #######
+ #.#....CK #......IC
+ #.###.# #.###.#
+ #.....# #...#.#
+ ###.### #.#.#.#
+XF....#.# RF..#.#.#
+ #####.# #######
+ #......CJ NM..#...#
+ ###.#.# #.###.#
+RE....#.# #......RF
+ ###.### X X L #.#.#.#
+ #.....# F Q P #.#.#.#
+ ###.###########.###.#######.#########.###
+ #.....#...#.....#.......#...#.....#.#...#
+ #####.#.###.#######.#######.###.###.#.#.#
+ #.......#.......#.#.#.#.#...#...#...#.#.#
+ #####.###.#####.#.#.#.#.###.###.#.###.###
+ #.......#.....#.#...#...............#...#
+ #############.#.#.###.###################
+ A O F N
+ A A D M
+```
+
+One shortest path through the maze is the following:
+
+
+ - Walk from `AA` to `XF` (16 steps)
+ - Recurse into level 1 through `XF` (1 step)
+ - Walk from `XF` to `CK` (10 steps)
+ - Recurse into level 2 through `CK` (1 step)
+ - Walk from `CK` to `ZH` (14 steps)
+ - Recurse into level 3 through `ZH` (1 step)
+ - Walk from `ZH` to `WB` (10 steps)
+ - Recurse into level 4 through `WB` (1 step)
+ - Walk from `WB` to `IC` (10 steps)
+ - Recurse into level 5 through `IC` (1 step)
+ - Walk from `IC` to `RF` (10 steps)
+ - Recurse into level 6 through `RF` (1 step)
+ - Walk from `RF` to `NM` (8 steps)
+ - Recurse into level 7 through `NM` (1 step)
+ - Walk from `NM` to `LP` (12 steps)
+ - Recurse into level 8 through `LP` (1 step)
+ - Walk from `LP` to `FD` (24 steps)
+ - Recurse into level 9 through `FD` (1 step)
+ - Walk from `FD` to `XQ` (8 steps)
+ - Recurse into level 10 through `XQ` (1 step)
+ - Walk from `XQ` to `WB` (4 steps)
+ - Return to level 9 through `WB` (1 step)
+ - Walk from `WB` to `ZH` (10 steps)
+ - Return to level 8 through `ZH` (1 step)
+ - Walk from `ZH` to `CK` (14 steps)
+ - Return to level 7 through `CK` (1 step)
+ - Walk from `CK` to `XF` (10 steps)
+ - Return to level 6 through `XF` (1 step)
+ - Walk from `XF` to `OA` (14 steps)
+ - Return to level 5 through `OA` (1 step)
+ - Walk from `OA` to `CJ` (8 steps)
+ - Return to level 4 through `CJ` (1 step)
+ - Walk from `CJ` to `RE` (8 steps)
+ - Return to level 3 through `RE` (1 step)
+ - Walk from `RE` to `IC` (4 steps)
+ - Recurse into level 4 through `IC` (1 step)
+ - Walk from `IC` to `RF` (10 steps)
+ - Recurse into level 5 through `RF` (1 step)
+ - Walk from `RF` to `NM` (8 steps)
+ - Recurse into level 6 through `NM` (1 step)
+ - Walk from `NM` to `LP` (12 steps)
+ - Recurse into level 7 through `LP` (1 step)
+ - Walk from `LP` to `FD` (24 steps)
+ - Recurse into level 8 through `FD` (1 step)
+ - Walk from `FD` to `XQ` (8 steps)
+ - Recurse into level 9 through `XQ` (1 step)
+ - Walk from `XQ` to `WB` (4 steps)
+ - Return to level 8 through `WB` (1 step)
+ - Walk from `WB` to `ZH` (10 steps)
+ - Return to level 7 through `ZH` (1 step)
+ - Walk from `ZH` to `CK` (14 steps)
+ - Return to level 6 through `CK` (1 step)
+ - Walk from `CK` to `XF` (10 steps)
+ - Return to level 5 through `XF` (1 step)
+ - Walk from `XF` to `OA` (14 steps)
+ - Return to level 4 through `OA` (1 step)
+ - Walk from `OA` to `CJ` (8 steps)
+ - Return to level 3 through `CJ` (1 step)
+ - Walk from `CJ` to `RE` (8 steps)
+ - Return to level 2 through `RE` (1 step)
+ - Walk from `RE` to `XQ` (14 steps)
+ - Return to level 1 through `XQ` (1 step)
+ - Walk from `XQ` to `FD` (8 steps)
+ - Return to level 0 through `FD` (1 step)
+ - Walk from `FD` to `ZZ` (18 steps)
+
+This path takes a total of *396* steps to move from `AA` at the outermost layer to `ZZ` at the outermost layer.
+
+In your maze, when accounting for recursion, *how many steps does it take to get from the open tile marked `AA` to the open tile marked `ZZ`, both at the outermost layer?*
+
+
diff --git a/2019/Day20/input.in b/2019/Day20/input.in
index 3ad350028..40ce47f83 100644
Binary files a/2019/Day20/input.in and b/2019/Day20/input.in differ
diff --git a/2019/Day21/README.md b/2019/Day21/README.md
index 48998e112..a4cbe59a0 100644
--- a/2019/Day21/README.md
+++ b/2019/Day21/README.md
@@ -1,6 +1,112 @@
+original source: [https://adventofcode.com/2019/day/21](https://adventofcode.com/2019/day/21)
## --- Day 21: Springdroid Adventure ---
You lift off from Pluto and start flying in the direction of Santa.
While experimenting further with the tractor beam, you accidentally pull an asteroid directly into your ship! It deals significant damage to your hull and causes your ship to begin tumbling violently.
-Read the [full puzzle](https://adventofcode.com/2019/day/21).
\ No newline at end of file
+You can send a droid out to investigate, but the tumbling is causing enough [artificial gravity](https://en.wikipedia.org/wiki/Artificial_gravity) that one wrong step could send the droid through a hole in the hull and flying out into space.
+
+The clear choice for this mission is a droid that can *jump* over the holes in the hull - a *springdroid*.
+
+You can use an [Intcode](9) program (your puzzle input) running on an [ASCII-capable](17) computer to [program](https://en.wikipedia.org/wiki/Programmable_read-only_memory) the springdroid. However, springdroids don't run Intcode; instead, they run a simplified assembly language called *springscript*.
+
+While a springdroid is certainly capable of navigating the artificial gravity and giant holes, it has one downside: it can only remember at most *15* springscript instructions.
+
+The springdroid will move forward automatically, constantly thinking about *whether to jump*. The springscript program defines the logic for this decision.
+
+Springscript programs only use [Boolean values](https://en.wikipedia.org/wiki/Boolean_data_type), not numbers or strings. Two registers are available: `T`, the *temporary value* register, and `J`, the *jump* register. If the jump register is *true* at the end of the springscript program, the springdroid will try to jump. Both of these registers start with the value *false*.
+
+Springdroids have a sensor that can detect *whether there is ground* at various distances in the direction it is facing; these values are provided in *read-only registers*. Your springdroid can detect ground at four distances: one tile away (`A`), two tiles away (`B`), three tiles away (`C`), and four tiles away (`D`). If there is ground at the given distance, the register will be *true*; if there is a hole, the register will be *false*.
+
+There are only *three instructions* available in springscript:
+
+
+ - `AND X Y` sets `Y` to *true* if both `X` and `Y` are *true*; otherwise, it sets `Y` to *false*.
+ - `OR X Y` sets `Y` to *true* if at least one of `X` or `Y` is *true*; otherwise, it sets `Y` to *false*.
+ - `NOT X Y` sets `Y` to *true* if `X` is *false*; otherwise, it sets `Y` to *false*.
+
+In all three instructions, the second argument (`Y`) needs to be a *writable register* (either `T` or `J`). The first argument (`X`) can be *any register* (including `A`, `B`, `C`, or `D`).
+
+For example, the one-instruction program `NOT A J` means "if the tile immediately in front of me is not ground, jump".
+
+Or, here is a program that jumps if a three-tile-wide hole (with ground on the other side of the hole) is detected:
+
+```
+NOT A J
+NOT B T
+AND T J
+NOT C T
+AND T J
+AND D J
+```
+
+The Intcode program expects ASCII inputs and outputs. It will begin by displaying a prompt; then, input the desired instructions one per line. End each line with a newline (ASCII code `10`). *When you have finished entering your program*, provide the command `WALK` followed by a newline to instruct the springdroid to begin surveying the hull.
+
+If the springdroid *falls into space*, an ASCII rendering of the last moments of its life will be produced. In these, `@` is the springdroid, `#` is hull, and `.` is empty space. For example, suppose you program the springdroid like this:
+
+```
+NOT D J
+WALK
+```
+
+This one-instruction program sets `J` to *true* if and only if there is no ground four tiles away. In other words, it attempts to jump into any hole it finds:
+
+```
+.................
+.................
+*@*................
+#####.###########
+
+.................
+.................
+.*@*...............
+#####.###########
+
+.................
+..*@*..............
+.................
+#####.###########
+
+...*@*.............
+.................
+.................
+#####.###########
+
+.................
+....*@*............
+.................
+#####.###########
+
+.................
+.................
+.....*@*...........
+#####.###########
+
+.................
+.................
+.................
+#####*@*###########
+```
+
+However, if the springdroid successfully makes it across, it will use an output instruction to indicate the *amount of damage to the hull* as a single giant integer outside the normal ASCII range.
+
+Program the springdroid with logic that allows it to survey the hull without falling into space. *What amount of hull damage does it report?*
+
+
+## --- Part Two ---
+There are many areas the springdroid can't reach. You flip through the manual and discover a way to *increase its sensor range*.
+
+Instead of ending your springcode program with `WALK`, use `RUN`. Doing this will enable *extended sensor mode*, capable of sensing ground up to *nine tiles away*. This data is available in *five new read-only registers*:
+
+
+ - Register `E` indicates whether there is ground *five* tiles away.
+ - Register `F` indicates whether there is ground *six* tiles away.
+ - Register `G` indicates whether there is ground *seven* tiles away.
+ - Register `H` indicates whether there is ground *eight* tiles away.
+ - Register `I` indicates whether there is ground *nine* tiles away.
+
+All other functions remain the same.
+
+Successfully survey the rest of the hull by ending your program with `RUN`. *What amount of hull damage does the springdroid now report?*
+
+
diff --git a/2019/Day21/input.in b/2019/Day21/input.in
index e71d327cc..3ced3cd82 100644
Binary files a/2019/Day21/input.in and b/2019/Day21/input.in differ
diff --git a/2019/Day22/README.md b/2019/Day22/README.md
index f72411e68..bdad2cd74 100644
--- a/2019/Day22/README.md
+++ b/2019/Day22/README.md
@@ -1,6 +1,176 @@
+original source: [https://adventofcode.com/2019/day/22](https://adventofcode.com/2019/day/22)
## --- Day 22: Slam Shuffle ---
There isn't much to do while you wait for the droids to repair your ship. At least you're drifting in the right direction. You decide to practice a new [card shuffle](https://en.wikipedia.org/wiki/Shuffling) you've been working on.
Digging through the ship's storage, you find a deck of *space cards*! Just like any deck of space cards, there are 10007 cards in the deck numbered `0` through `10006`. The deck must be new - they're still in *factory order*, with `0` on the top, then `1`, then `2`, and so on, all the way through to `10006` on the bottom.
-Read the [full puzzle](https://adventofcode.com/2019/day/22).
\ No newline at end of file
+You've been practicing three different *techniques* that you use while shuffling. Suppose you have a deck of only 10 cards (numbered `0` through `9`):
+
+*To `deal into new stack`*, create a new stack of cards by dealing the top card of the deck onto the top of the new stack repeatedly until you run out of cards:
+
+```
+Top Bottom
+0 1 2 3 4 5 6 7 8 9 Your deck
+ New stack
+
+ 1 2 3 4 5 6 7 8 9 Your deck
+ 0 New stack
+
+ 2 3 4 5 6 7 8 9 Your deck
+ 1 0 New stack
+
+ 3 4 5 6 7 8 9 Your deck
+ 2 1 0 New stack
+
+Several steps later...
+
+ 9 Your deck
+ 8 7 6 5 4 3 2 1 0 New stack
+
+ Your deck
+9 8 7 6 5 4 3 2 1 0 New stack
+```
+
+Finally, pick up the new stack you've just created and use it as the deck for the next technique.
+
+*To `cut N` cards*, take the top `N` cards off the top of the deck and move them as a single unit to the bottom of the deck, retaining their order. For example, to `cut 3`:
+
+```
+Top Bottom
+0 1 2 3 4 5 6 7 8 9 Your deck
+
+ 3 4 5 6 7 8 9 Your deck
+0 1 2 Cut cards
+
+3 4 5 6 7 8 9 Your deck
+ 0 1 2 Cut cards
+
+3 4 5 6 7 8 9 0 1 2 Your deck
+```
+
+You've also been getting pretty good at a version of this technique where `N` is negative! In that case, cut (the absolute value of) `N` cards from the bottom of the deck onto the top. For example, to `cut -4`:
+
+```
+Top Bottom
+0 1 2 3 4 5 6 7 8 9 Your deck
+
+0 1 2 3 4 5 Your deck
+ 6 7 8 9 Cut cards
+
+ 0 1 2 3 4 5 Your deck
+6 7 8 9 Cut cards
+
+6 7 8 9 0 1 2 3 4 5 Your deck
+```
+
+*To `deal with increment N`*, start by clearing enough space on your table to lay out all of the cards individually in a long line. Deal the top card into the leftmost position. Then, move `N` positions to the right and deal the next card there. If you would move into a position past the end of the space on your table, wrap around and keep counting from the leftmost card again. Continue this process until you run out of cards.
+
+For example, to `deal with increment 3`:
+
+```
+
+0 1 2 3 4 5 6 7 8 9 Your deck
+. . . . . . . . . . Space on table
+^ Current position
+
+Deal the top card to the current position:
+
+ 1 2 3 4 5 6 7 8 9 Your deck
+0 . . . . . . . . . Space on table
+^ Current position
+
+Move the current position right 3:
+
+ 1 2 3 4 5 6 7 8 9 Your deck
+0 . . . . . . . . . Space on table
+ ^ Current position
+
+Deal the top card:
+
+ 2 3 4 5 6 7 8 9 Your deck
+0 . . 1 . . . . . . Space on table
+ ^ Current position
+
+Move right 3 and deal:
+
+ 3 4 5 6 7 8 9 Your deck
+0 . . 1 . . 2 . . . Space on table
+ ^ Current position
+
+Move right 3 and deal:
+
+ 4 5 6 7 8 9 Your deck
+0 . . 1 . . 2 . . 3 Space on table
+ ^ Current position
+
+Move right 3, wrapping around, and deal:
+
+ 5 6 7 8 9 Your deck
+0 . 4 1 . . 2 . . 3 Space on table
+ ^ Current position
+
+And so on:
+
+0 7 4 1 8 5 2 9 6 3 Space on table
+```
+
+Positions on the table which already contain cards are still counted; they're not skipped. Of course, this technique is carefully designed so it will never put two cards in the same position or leave a position empty.
+
+Finally, collect the cards on the table so that the leftmost card ends up at the top of your deck, the card to its right ends up just below the top card, and so on, until the rightmost card ends up at the bottom of the deck.
+
+The complete shuffle process (your puzzle input) consists of applying many of these techniques. Here are some examples that combine techniques; they all start with a *factory order* deck of 10 cards:
+
+```
+deal with increment 7
+deal into new stack
+deal into new stack
+Result: 0 3 6 9 2 5 8 1 4 7
+```
+
+```
+cut 6
+deal with increment 7
+deal into new stack
+Result: 3 0 7 4 1 8 5 2 9 6
+```
+
+```
+deal with increment 7
+deal with increment 9
+cut -2
+Result: 6 3 0 7 4 1 8 5 2 9
+```
+
+```
+deal into new stack
+cut -2
+deal with increment 7
+cut 8
+cut -4
+deal with increment 7
+cut 3
+deal with increment 9
+deal with increment 3
+cut -1
+Result: 9 2 5 8 1 4 7 0 3 6
+```
+
+Positions within the deck count from `0` at the top, then `1` for the card immediately below the top card, and so on to the bottom. (That is, cards start in the position matching their number.)
+
+After shuffling your *factory order* deck of 10007 cards, *what is the position of card `2019`?*
+
+
+## --- Part Two ---
+After a while, you realize your shuffling skill won't improve much more with merely a single deck of cards. You ask every 3D printer on the ship to make you some more cards while you check on the ship repairs. While reviewing the work the droids have finished so far, you think you see [Halley's Comet](https://en.wikipedia.org/wiki/Halley%27s_Comet) fly past!
+
+When you get back, you discover that the 3D printers have combined their power to create for you a single, giant, brand new, *factory order* deck of *`119315717514047` space cards*.
+
+Finally, a deck of cards worthy of shuffling!
+
+You decide to apply your complete shuffle process (your puzzle input) to the deck *`101741582076661` times in a row*.
+
+You'll need to be careful, though - one wrong move with this many cards and you might *overflow* your entire ship!
+
+After shuffling your new, giant, *factory order* deck that many times, *what number is on the card that ends up in position `2020`?*
+
+
diff --git a/2019/Day22/input.in b/2019/Day22/input.in
index 0eab6218e..0f3313602 100644
Binary files a/2019/Day22/input.in and b/2019/Day22/input.in differ
diff --git a/2019/Day23/README.md b/2019/Day23/README.md
index eeb65d376..e9b127fcb 100644
--- a/2019/Day23/README.md
+++ b/2019/Day23/README.md
@@ -1,6 +1,31 @@
+original source: [https://adventofcode.com/2019/day/23](https://adventofcode.com/2019/day/23)
## --- Day 23: Category Six ---
The droids have finished repairing as much of the ship as they can. Their report indicates that this was a *Category 6* disaster - not because it was that bad, but because it destroyed the stockpile of [Category 6](https://en.wikipedia.org/wiki/Category_6_cable) network cables as well as most of the ship's network infrastructure.
You'll need to *rebuild the network from scratch*.
-Read the [full puzzle](https://adventofcode.com/2019/day/23).
\ No newline at end of file
+The computers on the network are standard [Intcode](9) computers that communicate by sending *packets* to each other. There are `50` of them in total, each running a copy of the same *Network Interface Controller* (NIC) software (your puzzle input). The computers have *network addresses* `0` through `49`; when each computer boots up, it will request its network address via a single input instruction. Be sure to give each computer a unique network address.
+
+Once a computer has received its network address, it will begin doing work and communicating over the network by sending and receiving *packets*. All packets contain *two values* named `X` and `Y`. Packets sent to a computer are queued by the recipient and read in the order they are received.
+
+To *send* a packet to another computer, the NIC will use *three output instructions* that provide the *destination address* of the packet followed by its `X` and `Y` values. For example, three output instructions that provide the values `10`, `20`, `30` would send a packet with `X=20` and `Y=30` to the computer with address `10`.
+
+To *receive* a packet from another computer, the NIC will use an *input instruction*. If the incoming packet queue is *empty*, provide `-1`. Otherwise, provide the `X` value of the next packet; the computer will then use a second input instruction to receive the `Y` value for the same packet. Once both values of the packet are read in this way, the packet is removed from the queue.
+
+Note that these input and output instructions never [block](https://en.wikipedia.org/wiki/Blocking_(computing)). Specifically, output instructions do not wait for the sent packet to be received - the computer might send multiple packets before receiving any. Similarly, input instructions do not wait for a packet to arrive - if no packet is waiting, input instructions should receive `-1`.
+
+Boot up all `50` computers and attach them to your network. *What is the `Y` value of the first packet sent to address `255`?*
+
+
+## --- Part Two ---
+Packets sent to address `255` are handled by a device called a NAT (Not Always Transmitting). The NAT is responsible for managing power consumption of the network by blocking certain packets and watching for idle periods in the computers.
+
+If a packet would be sent to address `255`, the NAT receives it instead. The NAT remembers only the *last* packet it receives; that is, the data in each packet it receives overwrites the NAT's packet memory with the new packet's `X` and `Y` values.
+
+The NAT also monitors all computers on the network. If all computers have *empty incoming packet queues* and are *continuously trying to receive packets* without sending packets, the network is considered *idle*.
+
+Once the network is idle, the NAT sends *only the last packet it received* to address `0`; this will cause the computers on the network to resume activity. In this way, the NAT can throttle power consumption of the network when the ship needs power in other areas.
+
+Monitor packets released to the computer at address `0` by the NAT. *What is the first `Y` value delivered by the NAT to the computer at address `0` twice in a row?*
+
+
diff --git a/2019/Day23/input.in b/2019/Day23/input.in
index 088494653..4c1bd5493 100644
Binary files a/2019/Day23/input.in and b/2019/Day23/input.in differ
diff --git a/2019/Day24/README.md b/2019/Day24/README.md
index 0571ab9cb..198fd9e40 100644
--- a/2019/Day24/README.md
+++ b/2019/Day24/README.md
@@ -1,6 +1,243 @@
+original source: [https://adventofcode.com/2019/day/24](https://adventofcode.com/2019/day/24)
## --- Day 24: Planet of Discord ---
You land on [Eris](https://en.wikipedia.org/wiki/Eris_(dwarf_planet)), your last stop before reaching Santa. As soon as you do, your sensors start picking up strange life forms moving around: Eris is infested with [bugs](https://www.nationalgeographic.org/thisday/sep9/worlds-first-computer-bug/)! With an over 24-hour roundtrip for messages between you and Earth, you'll have to deal with this problem on your own.
Eris isn't a very large place; a scan of the entire area fits into a 5x5 grid (your puzzle input). The scan shows *bugs* (`#`) and *empty spaces* (`.`).
-Read the [full puzzle](https://adventofcode.com/2019/day/24).
\ No newline at end of file
+Each *minute*, The bugs live and die based on the number of bugs in the *four adjacent tiles*:
+
+
+ - A bug *dies* (becoming an empty space) unless there is *exactly one* bug adjacent to it.
+ - An empty space *becomes infested* with a bug if *exactly one or two* bugs are adjacent to it.
+
+Otherwise, a bug or empty space remains the same. (Tiles on the edges of the grid have fewer than four adjacent tiles; the missing tiles count as empty space.) This process happens in every location *simultaneously*; that is, within the same minute, the number of adjacent bugs is counted for every tile first, and then the tiles are updated.
+
+Here are the first few minutes of an example scenario:
+
+```
+Initial state:
+....#
+#..#.
+#..##
+..#..
+#....
+
+After 1 minute:
+#..#.
+####.
+###.#
+##.##
+.##..
+
+After 2 minutes:
+#####
+....#
+....#
+...#.
+#.###
+
+After 3 minutes:
+#....
+####.
+...##
+#.##.
+.##.#
+
+After 4 minutes:
+####.
+....#
+##..#
+.....
+##...
+```
+
+To understand the nature of the bugs, watch for the first time a layout of bugs and empty spaces *matches any previous layout*. In the example above, the first layout to appear twice is:
+
+```
+.....
+.....
+.....
+#....
+.#...
+```
+
+To calculate the *biodiversity rating* for this layout, consider each tile left-to-right in the top row, then left-to-right in the second row, and so on. Each of these tiles is worth biodiversity points equal to *increasing powers of two*: 1, 2, 4, 8, 16, 32, and so on. Add up the biodiversity points for tiles with bugs; in this example, the 16th tile (`32768` points) and 22nd tile (`2097152` points) have bugs, a total biodiversity rating of `*2129920*`.
+
+*What is the biodiversity rating for the first layout that appears twice?*
+
+
+## --- Part Two ---
+After careful analysis, one thing is certain: *you have no idea where all these bugs are coming from*.
+
+Then, you remember: Eris is an old [Plutonian](20) settlement! Clearly, the bugs are coming from recursively-folded space.
+
+This 5x5 grid is *only one* level in an *infinite* number of recursion levels. The tile in the middle of the grid is actually another 5x5 grid, the grid in your scan is contained as the middle tile of a larger 5x5 grid, and so on. Two levels of grids look like this:
+
+```
+ | | | |
+ | | | |
+ | | | |
+-----+-----+---------+-----+-----
+ | | | |
+ | | | |
+ | | | |
+-----+-----+---------+-----+-----
+ | | | | | | | |
+ | |-+-+-+-+-| |
+ | | | | | | | |
+ | |-+-+-+-+-| |
+ | | | |?| | | |
+ | |-+-+-+-+-| |
+ | | | | | | | |
+ | |-+-+-+-+-| |
+ | | | | | | | |
+-----+-----+---------+-----+-----
+ | | | |
+ | | | |
+ | | | |
+-----+-----+---------+-----+-----
+ | | | |
+ | | | |
+ | | | |
+```
+
+(To save space, some of the tiles are not drawn to scale.) Remember, this is only a small part of the infinitely recursive grid; there is a 5x5 grid that contains this diagram, and a 5x5 grid that contains that one, and so on. Also, the `?` in the diagram contains another 5x5 grid, which itself contains another 5x5 grid, and so on.
+
+The scan you took (your puzzle input) shows where the bugs are *on a single level* of this structure. The middle tile of your scan is empty to accommodate the recursive grids within it. Initially, no other levels contain bugs.
+
+Tiles still count as *adjacent* if they are directly *up, down, left, or right* of a given tile. Some tiles have adjacent tiles at a recursion level above or below its own level. For example:
+
+```
+ | | | |
+ 1 | 2 | 3 | 4 | 5
+ | | | |
+-----+-----+---------+-----+-----
+ | | | |
+ 6 | 7 | 8 | 9 | 10
+ | | | |
+-----+-----+---------+-----+-----
+ | |A|B|C|D|E| |
+ | |-+-+-+-+-| |
+ | |F|G|H|I|J| |
+ | |-+-+-+-+-| |
+ 11 | 12 |K|L|?|N|O| 14 | 15
+ | |-+-+-+-+-| |
+ | |P|Q|R|S|T| |
+ | |-+-+-+-+-| |
+ | |U|V|W|X|Y| |
+-----+-----+---------+-----+-----
+ | | | |
+ 16 | 17 | 18 | 19 | 20
+ | | | |
+-----+-----+---------+-----+-----
+ | | | |
+ 21 | 22 | 23 | 24 | 25
+ | | | |
+```
+
+
+ - Tile 19 has four adjacent tiles: 14, 18, 20, and 24.
+ - Tile G has four adjacent tiles: B, F, H, and L.
+ - Tile D has four adjacent tiles: 8, C, E, and I.
+ - Tile E has four adjacent tiles: 8, D, 14, and J.
+ - Tile 14 has *eight* adjacent tiles: 9, E, J, O, T, Y, 15, and 19.
+ - Tile N has *eight* adjacent tiles: I, O, S, and five tiles within the sub-grid marked `?`.
+
+The rules about bugs living and dying are the same as before.
+
+For example, consider the same initial state as above:
+
+```
+....#
+#..#.
+#.?##
+..#..
+#....
+```
+
+The center tile is drawn as `?` to indicate the next recursive grid. Call this level 0; the grid within this one is level 1, and the grid that contains this one is level -1. Then, after *ten* minutes, the grid at each level would look like this:
+
+```
+Depth -5:
+..#..
+.#.#.
+..?.#
+.#.#.
+..#..
+
+Depth -4:
+...#.
+...##
+..?..
+...##
+...#.
+
+Depth -3:
+#.#..
+.#...
+..?..
+.#...
+#.#..
+
+Depth -2:
+.#.##
+....#
+..?.#
+...##
+.###.
+
+Depth -1:
+#..##
+...##
+..?..
+...#.
+.####
+
+Depth 0:
+.#...
+.#.##
+.#?..
+.....
+.....
+
+Depth 1:
+.##..
+#..##
+..?.#
+##.##
+#####
+
+Depth 2:
+###..
+##.#.
+#.?..
+.#.##
+#.#..
+
+Depth 3:
+..###
+.....
+#.?..
+#....
+#...#
+
+Depth 4:
+.###.
+#..#.
+#.?..
+##.#.
+.....
+
+Depth 5:
+####.
+#..#.
+#.?#.
+####.
+.....
+```
+
+In this example, after 10 minutes, a total of `*99*` bugs are present.
+
+Starting with your scan, *how many bugs are present after 200 minutes?*
+
+
diff --git a/2019/Day24/input.in b/2019/Day24/input.in
index ce82b25d5..2207476f0 100644
Binary files a/2019/Day24/input.in and b/2019/Day24/input.in differ
diff --git a/2019/Day25/README.md b/2019/Day25/README.md
index 09c087c2b..964e202b5 100644
--- a/2019/Day25/README.md
+++ b/2019/Day25/README.md
@@ -1,6 +1,39 @@
+original source: [https://adventofcode.com/2019/day/25](https://adventofcode.com/2019/day/25)
## --- Day 25: Cryostasis ---
As you approach Santa's ship, your sensors report two important details:
First, that you might be too late: the internal temperature is `-40` degrees.
-Read the [full puzzle](https://adventofcode.com/2019/day/25).
\ No newline at end of file
+Second, that one faint life signature is somewhere on the ship.
+
+The airlock door is locked with a code; your best option is to send in a small droid to investigate the situation. You attach your ship to Santa's, break a small hole in the hull, and let the droid run in before you seal it up again. Before your ship starts freezing, you detach your ship and set it to automatically stay within range of Santa's ship.
+
+This droid can follow basic instructions and report on its surroundings; you can communicate with it through an [Intcode](9) program (your puzzle input) running on an [ASCII-capable](17) computer.
+
+As the droid moves through its environment, it will describe what it encounters. When it says `Command?`, you can give it a single instruction terminated with a newline (ASCII code `10`). Possible instructions are:
+
+
+ - *Movement* via `north`, `south`, `east`, or `west`.
+ - To *take* an item the droid sees in the environment, use the command `take 2020
and then multiply those two numbers together.
+
+For example, suppose your expense report contained the following:
+
+
+1721
+979
+366
+299
+675
+1456
+
+
+
+In this list, the two entries that sum to 2020
are 1721
and 299
. Multiplying them together produces 1721 * 299 = 514579
, so the correct answer is 514579
.
+
+Of course, your expense report is much larger. Find the two entries that sum to 2020
; what do you get if you multiply them together?
+
+
+## --- Part Two ---
+The Elves in accounting are thankful for your help; one of them even offers you a starfish coin they had left over from a past vacation. They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
+
+Using the above example again, the three entries that sum to 2020
are 979
, 366
, and 675
. Multiplying them together produces the answer, 241861950
.
+
+In your expense report, what is the product of the three entries that sum to 2020
?
+
+
diff --git a/2020/Day01/input.in b/2020/Day01/input.in
index 498aa0d3f..7b7f47a2f 100644
Binary files a/2020/Day01/input.in and b/2020/Day01/input.in differ
diff --git a/2020/Day02/README.md b/2020/Day02/README.md
index 0b731664f..fa0649861 100644
--- a/2020/Day02/README.md
+++ b/2020/Day02/README.md
@@ -1,6 +1,43 @@
+original source: [https://adventofcode.com/2020/day/2](https://adventofcode.com/2020/day/2)
## --- Day 2: Password Philosophy ---
Your flight departs in a few days from the coastal airport; the easiest way down to the coast from here is via [toboggan](https://en.wikipedia.org/wiki/Toboggan).
The shopkeeper at the North Pole Toboggan Rental Shop is having a bad day. "Something's wrong with our computers; we can't log in!" You ask if you can take a look.
-Read the [full puzzle](https://adventofcode.com/2020/day/2).
\ No newline at end of file
+Their password database seems to be a little corrupted: some of the passwords wouldn't have been allowed by the Official Toboggan Corporate Policy that was in effect when they were chosen.
+
+To try to debug the problem, they have created a list (your puzzle input) of passwords (according to the corrupted database) and the corporate policy when that password was set.
+
+For example, suppose you have the following list:
+
+
+1-3 a: abcde
+1-3 b: cdefg
+2-9 c: ccccccccc
+
+
+
+Each line gives the password policy and then the password. The password policy indicates the lowest and highest number of times a given letter must appear for the password to be valid. For example, 1-3 a
means that the password must contain a
at least 1
time and at most 3
times.
+
+In the above example, 2
passwords are valid. The middle password, cdefg
, is not; it contains no instances of b
, but needs at least 1
. The first and third passwords are valid: they contain one a
or nine c
, both within the limits of their respective policies.
+
+How many passwords are valid according to their policies?
+
+
+## --- Part Two ---
+While it appears you validated the passwords correctly, they don't seem to be what the Official Toboggan Corporate Authentication System is expecting.
+
+The shopkeeper suddenly realizes that he just accidentally explained the password policy rules from his old job at the sled rental place down the street! The Official Toboggan Corporate Policy actually works a little differently.
+
+Each policy actually describes two positions in the password, where 1
means the first character, 2
means the second character, and so on. (Be careful; Toboggan Corporate Policies have no concept of "index zero"!) Exactly one of these positions must contain the given letter. Other occurrences of the letter are irrelevant for the purposes of policy enforcement.
+
+Given the same example list from above:
+
+
+ - 1-3 a: abcde
is valid: position 1
contains a
and position 3
does not.
+ - 1-3 b: cdefg
is invalid: neither position 1
nor position 3
contains b
.
+ - 2-9 c: ccccccccc
is invalid: both position 2
and position 9
contain c
.
+
+How many passwords are valid according to the new interpretation of the policies?
+
+
diff --git a/2020/Day02/input.in b/2020/Day02/input.in
index b43c90dc0..bb32789e6 100644
Binary files a/2020/Day02/input.in and b/2020/Day02/input.in differ
diff --git a/2020/Day03/README.md b/2020/Day03/README.md
index 79e2a72a7..ffe9f4dbc 100644
--- a/2020/Day03/README.md
+++ b/2020/Day03/README.md
@@ -1,6 +1,83 @@
+original source: [https://adventofcode.com/2020/day/3](https://adventofcode.com/2020/day/3)
## --- Day 3: Toboggan Trajectory ---
With the toboggan login problems resolved, you set off toward the airport. While travel by toboggan might be easy, it's certainly not safe: there's very minimal steering and the area is covered in trees. You'll need to see which angles will take you near the fewest trees.
Due to the local geology, trees in this area only grow on exact integer coordinates in a grid. You make a map (your puzzle input) of the open squares (.
) and trees (#
) you can see. For example:
-Read the [full puzzle](https://adventofcode.com/2020/day/3).
\ No newline at end of file
+
+..##.......
+#...#...#..
+.#....#..#.
+..#.#...#.#
+.#...##..#.
+..#.##.....
+.#.#.#....#
+.#........#
+#.##...#...
+#...##....#
+.#..#...#.#
+
+
+
+These aren't the only trees, though; due to something you read about once involving arboreal genetics and biome stability, the same pattern repeats to the right many times:
+
+
+..##.........##.........##.........##.........##.........##....... --->
+#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
+.#....#..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
+..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
+.#...##..#..#...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
+..#.##.......#.##.......#.##.......#.##.......#.##.......#.##..... --->
+.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
+.#........#.#........#.#........#.#........#.#........#.#........#
+#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...#.##...#...
+#...##....##...##....##...##....##...##....##...##....##...##....#
+.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.#.#..#...#.# --->
+
+
+
+You start on the open square (.
) in the top-left corner and need to reach the bottom (below the bottom-most row on your map).
+
+The toboggan can only follow a few specific slopes (you opted for a cheaper model that prefers rational numbers); start by counting all the trees you would encounter for the slope right 3, down 1:
+
+From your starting position at the top-left, check the position that is right 3 and down 1. Then, check the position that is right 3 and down 1 from there, and so on until you go past the bottom of the map.
+
+The locations you'd check in the above example are marked here with O
where there was an open square and X
where there was a tree:
+
+
+..##.........##.........##.........##.........##.........##....... --->
+#..O#...#..#...#...#..#...#...#..#...#...#..#...#...#..#...#...#..
+.#....X..#..#....#..#..#....#..#..#....#..#..#....#..#..#....#..#.
+..#.#...#O#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#..#.#...#.#
+.#...##..#..X...##..#..#...##..#..#...##..#..#...##..#..#...##..#.
+..#.##.......#.X#.......#.##.......#.##.......#.##.......#.##..... --->
+.#.#.#....#.#.#.#.O..#.#.#.#....#.#.#.#....#.#.#.#....#.#.#.#....#
+.#........#.#........X.#........#.#........#.#........#.#........#
+#.##...#...#.##...#...#.X#...#...#.##...#...#.##...#...#.##...#...
+#...##....##...##....##...#X....##...##....##...##....##...##....#
+.#..#...#.#.#..#...#.#.#..#...X.#.#..#...#.#.#..#...#.#.#..#...#.# --->
+
+
+
+In this example, traversing the map using this slope would cause you to encounter 7
trees.
+
+Starting at the top-left corner of your map and following a slope of right 3 and down 1, how many trees would you encounter?
+
+
+## --- Part Two ---
+Time to check the rest of the slopes - you need to minimize the probability of a sudden arboreal stop, after all.
+
+Determine the number of trees you would encounter if, for each of the following slopes, you start at the top-left corner and traverse the map all the way to the bottom:
+
+
+ - Right 1, down 1.
+ - Right 3, down 1. (This is the slope you already checked.)
+ - Right 5, down 1.
+ - Right 7, down 1.
+ - Right 1, down 2.
+
+In the above example, these slopes would find 2
, 7
, 3
, 4
, and 2
tree(s) respectively; multiplied together, these produce the answer 336
.
+
+What do you get if you multiply together the number of trees encountered on each of the listed slopes?
+
+
diff --git a/2020/Day03/input.in b/2020/Day03/input.in
index 4eb1a39f2..6727b2a4d 100644
Binary files a/2020/Day03/input.in and b/2020/Day03/input.in differ
diff --git a/2020/Day04/README.md b/2020/Day04/README.md
index cd23630f4..4ebaeb54d 100644
--- a/2020/Day04/README.md
+++ b/2020/Day04/README.md
@@ -1,6 +1,135 @@
+original source: [https://adventofcode.com/2020/day/4](https://adventofcode.com/2020/day/4)
## --- Day 4: Passport Processing ---
You arrive at the airport only to realize that you grabbed your North Pole Credentials instead of your passport. While these documents are extremely similar, North Pole Credentials aren't issued by a country and therefore aren't actually valid documentation for travel in most of the world.
It seems like you're not the only one having problems, though; a very long line has formed for the automatic passport scanners, and the delay could upset your travel itinerary.
-Read the [full puzzle](https://adventofcode.com/2020/day/4).
\ No newline at end of file
+Due to some questionable network security, you realize you might be able to solve both of these problems at the same time.
+
+The automatic passport scanners are slow because they're having trouble detecting which passports have all required fields. The expected fields are as follows:
+
+
+ - byr
(Birth Year)
+ - iyr
(Issue Year)
+ - eyr
(Expiration Year)
+ - hgt
(Height)
+ - hcl
(Hair Color)
+ - ecl
(Eye Color)
+ - pid
(Passport ID)
+ - cid
(Country ID)
+
+Passport data is validated in batch files (your puzzle input). Each passport is represented as a sequence of key:value
pairs separated by spaces or newlines. Passports are separated by blank lines.
+
+Here is an example batch file containing four passports:
+
+
+ecl:gry pid:860033327 eyr:2020 hcl:#fffffd
+byr:1937 iyr:2017 cid:147 hgt:183cm
+
+iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884
+hcl:#cfa07d byr:1929
+
+hcl:#ae17e1 iyr:2013
+eyr:2024
+ecl:brn pid:760753108 byr:1931
+hgt:179cm
+
+hcl:#cfa07d eyr:2025 pid:166559648
+iyr:2011 ecl:brn hgt:59in
+
+
+
+The first passport is valid - all eight fields are present. The second passport is invalid - it is missing hgt
(the Height field).
+
+The third passport is interesting; the only missing field is cid
, so it looks like data from North Pole Credentials, not a passport at all! Surely, nobody would mind if you made the system temporarily ignore missing cid
fields. Treat this "passport" as valid.
+
+The fourth passport is missing two fields, cid
and byr
. Missing cid
is fine, but missing any other field is not, so this passport is invalid.
+
+According to the above rules, your improved system would report 2
valid passports.
+
+Count the number of valid passports - those that have all required fields. Treat cid
as optional. In your batch file, how many passports are valid?
+
+
+## --- Part Two ---
+The line is moving more quickly now, but you overhear airport security talking about how passports with invalid data are getting through. Better add some data validation, quick!
+
+You can continue to ignore the cid
field, but each other field has strict rules about what values are valid for automatic validation:
+
+
+ - byr
(Birth Year) - four digits; at least 1920
and at most 2002
.
+ - iyr
(Issue Year) - four digits; at least 2010
and at most 2020
.
+ - eyr
(Expiration Year) - four digits; at least 2020
and at most 2030
.
+ - hgt
(Height) - a number followed by either cm
or in
:
+
+ - If cm
, the number must be at least 150
and at most 193
.
+ - If in
, the number must be at least 59
and at most 76
.
+
+
+ - hcl
(Hair Color) - a #
followed by exactly six characters 0
-9
or a
-f
.
+ - ecl
(Eye Color) - exactly one of: amb
blu
brn
gry
grn
hzl
oth
.
+ - pid
(Passport ID) - a nine-digit number, including leading zeroes.
+ - cid
(Country ID) - ignored, missing or not.
+
+Your job is to count the passports where all required fields are both present and valid according to the above rules. Here are some example values:
+
+
+byr valid: 2002
+byr invalid: 2003
+
+hgt valid: 60in
+hgt valid: 190cm
+hgt invalid: 190in
+hgt invalid: 190
+
+hcl valid: #123abc
+hcl invalid: #123abz
+hcl invalid: 123abc
+
+ecl valid: brn
+ecl invalid: wat
+
+pid valid: 000000001
+pid invalid: 0123456789
+
+
+
+Here are some invalid passports:
+
+
+eyr:1972 cid:100
+hcl:#18171d ecl:amb hgt:170 pid:186cm iyr:2018 byr:1926
+
+iyr:2019
+hcl:#602927 eyr:1967 hgt:170cm
+ecl:grn pid:012533040 byr:1946
+
+hcl:dab227 iyr:2012
+ecl:brn hgt:182cm pid:021572410 eyr:2020 byr:1992 cid:277
+
+hgt:59cm ecl:zzz
+eyr:2038 hcl:74454a iyr:2023
+pid:3556412378 byr:2007
+
+
+
+Here are some valid passports:
+
+
+pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980
+hcl:#623a2f
+
+eyr:2029 ecl:blu cid:129 byr:1989
+iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm
+
+hcl:#888785
+hgt:164cm byr:2001 iyr:2015 cid:88
+pid:545766238 ecl:hzl
+eyr:2022
+
+iyr:2010 hgt:158cm hcl:#b6652a ecl:blu byr:1944 eyr:2021 pid:093154719
+
+
+
+Count the number of valid passports - those that have all required fields and valid values. Continue to treat cid
as optional. In your batch file, how many passports are valid?
+
+
diff --git a/2020/Day04/input.in b/2020/Day04/input.in
index f84e2c10e..fa39bc7b7 100644
Binary files a/2020/Day04/input.in and b/2020/Day04/input.in differ
diff --git a/2020/Day05/README.md b/2020/Day05/README.md
index 79b2dec02..398d967dd 100644
--- a/2020/Day05/README.md
+++ b/2020/Day05/README.md
@@ -1,6 +1,56 @@
+original source: [https://adventofcode.com/2020/day/5](https://adventofcode.com/2020/day/5)
## --- Day 5: Binary Boarding ---
You board your plane only to discover a new problem: you dropped your boarding pass! You aren't sure which seat is yours, and all of the flight attendants are busy with the flood of people that suddenly made it through passport control.
You write a quick program to use your phone's camera to scan all of the nearby boarding passes (your puzzle input); perhaps you can find your seat through process of elimination.
-Read the [full puzzle](https://adventofcode.com/2020/day/5).
\ No newline at end of file
+Instead of [zones or groups](https://www.youtube.com/watch?v=oAHbLRjF0vo), this airline uses binary space partitioning to seat people. A seat might be specified like FBFBBFFRLR
, where F
means "front", B
means "back", L
means "left", and R
means "right".
+
+The first 7 characters will either be F
or B
; these specify exactly one of the 128 rows on the plane (numbered 0
through 127
). Each letter tells you which half of a region the given seat is in. Start with the whole list of rows; the first letter indicates whether the seat is in the front (0
through 63
) or the back (64
through 127
). The next letter indicates which half of that region the seat is in, and so on until you're left with exactly one row.
+
+For example, consider just the first seven characters of FBFBBFFRLR
:
+
+
+ - Start by considering the whole range, rows 0
through 127
.
+ - F
means to take the lower half, keeping rows 0
through 63
.
+ - B
means to take the upper half, keeping rows 32
through 63
.
+ - F
means to take the lower half, keeping rows 32
through 47
.
+ - B
means to take the upper half, keeping rows 40
through 47
.
+ - B
keeps rows 44
through 47
.
+ - F
keeps rows 44
through 45
.
+ - The final F
keeps the lower of the two, row 44
.
+
+The last three characters will be either L
or R
; these specify exactly one of the 8 columns of seats on the plane (numbered 0
through 7
). The same process as above proceeds again, this time with only three steps. L
means to keep the lower half, while R
means to keep the upper half.
+
+For example, consider just the last 3 characters of FBFBBFFRLR
:
+
+
+ - Start by considering the whole range, columns 0
through 7
.
+ - R
means to take the upper half, keeping columns 4
through 7
.
+ - L
means to take the lower half, keeping columns 4
through 5
.
+ - The final R
keeps the upper of the two, column 5
.
+
+So, decoding FBFBBFFRLR
reveals that it is the seat at row 44
, column 5
.
+
+Every seat also has a unique seat ID: multiply the row by 8, then add the column. In this example, the seat has ID 44 * 8 + 5 = 357
.
+
+Here are some other boarding passes:
+
+
+ - BFFFBBFRRR
: row 70
, column 7
, seat ID 567
.
+ - FFFBBBFRRR
: row 14
, column 7
, seat ID 119
.
+ - BBFFBBFRLL
: row 102
, column 4
, seat ID 820
.
+
+As a sanity check, look through your list of boarding passes. What is the highest seat ID on a boarding pass?
+
+
+## --- Part Two ---
+Ding! The "fasten seat belt" signs have turned on. Time to find your seat.
+
+It's a completely full flight, so your seat should be the only missing boarding pass in your list. However, there's a catch: some of the seats at the very front and back of the plane don't exist on this aircraft, so they'll be missing from your list as well.
+
+Your seat wasn't at the very front or back, though; the seats with IDs +1 and -1 from yours will be in your list.
+
+What is the ID of your seat?
+
+
diff --git a/2020/Day05/input.in b/2020/Day05/input.in
index addba3135..17dfa0b17 100644
Binary files a/2020/Day05/input.in and b/2020/Day05/input.in differ
diff --git a/2020/Day06/README.md b/2020/Day06/README.md
index f1f605931..e2e62ead5 100644
--- a/2020/Day06/README.md
+++ b/2020/Day06/README.md
@@ -1,6 +1,92 @@
+original source: [https://adventofcode.com/2020/day/6](https://adventofcode.com/2020/day/6)
## --- Day 6: Custom Customs ---
As your flight approaches the regional airport where you'll switch to a much larger plane, [customs declaration forms](https://en.wikipedia.org/wiki/Customs_declaration) are distributed to the passengers.
The form asks a series of 26 yes-or-no questions marked a
through z
. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
-Read the [full puzzle](https://adventofcode.com/2020/day/6).
\ No newline at end of file
+However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
+
+
+abcx
+abcy
+abcz
+
+
+
+In this group, there are 6
questions to which anyone answered "yes": a
, b
, c
, x
, y
, and z
. (Duplicate answers to the same question don't count extra; each question counts at most once.)
+
+Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
+
+
+abc
+
+a
+b
+c
+
+ab
+ac
+
+a
+a
+a
+a
+
+b
+
+
+
+This list represents answers from five groups:
+
+
+ - The first group contains one person who answered "yes" to 3
questions: a
, b
, and c
.
+ - The second group contains three people; combined, they answered "yes" to 3
questions: a
, b
, and c
.
+ - The third group contains two people; combined, they answered "yes" to 3
questions: a
, b
, and c
.
+ - The fourth group contains four people; combined, they answered "yes" to only 1
question, a
.
+ - The last group contains one person who answered "yes" to only 1
question, b
.
+
+In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1
= 11
.
+
+For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?
+
+
+## --- Part Two ---
+As you finish the last group's customs declaration, you notice that you misread one word in the instructions:
+
+You don't need to identify the questions to which anyone answered "yes"; you need to identify the questions to which everyone answered "yes"!
+
+Using the same example as above:
+
+
+abc
+
+a
+b
+c
+
+ab
+ac
+
+a
+a
+a
+a
+
+b
+
+
+
+This list represents answers from five groups:
+
+
+ - In the first group, everyone (all 1 person) answered "yes" to 3
questions: a
, b
, and c
.
+ - In the second group, there is no question to which everyone answered "yes".
+ - In the third group, everyone answered yes to only 1
question, a
. Since some people did not answer "yes" to b
or c
, they don't count.
+ - In the fourth group, everyone answered yes to only 1
question, a
.
+ - In the fifth group, everyone (all 1 person) answered "yes" to 1
question, b
.
+
+In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1
= 6
.
+
+For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?
+
+
diff --git a/2020/Day06/input.in b/2020/Day06/input.in
index 62ced6e23..ecd89a095 100644
Binary files a/2020/Day06/input.in and b/2020/Day06/input.in differ
diff --git a/2020/Day07/README.md b/2020/Day07/README.md
index a3323abd5..6e3f1972d 100644
--- a/2020/Day07/README.md
+++ b/2020/Day07/README.md
@@ -1,6 +1,71 @@
+original source: [https://adventofcode.com/2020/day/7](https://adventofcode.com/2020/day/7)
## --- Day 7: Handy Haversacks ---
You land at the regional airport in time for your next flight. In fact, it looks like you'll even have time to grab some food: all flights are currently delayed due to issues in luggage processing.
Due to recent aviation regulations, many rules (your puzzle input) are being enforced about bags and their contents; bags must be color-coded and must contain specific quantities of other color-coded bags. Apparently, nobody responsible for these regulations considered how long they would take to enforce!
-Read the [full puzzle](https://adventofcode.com/2020/day/7).
\ No newline at end of file
+For example, consider the following rules:
+
+
+light red bags contain 1 bright white bag, 2 muted yellow bags.
+dark orange bags contain 3 bright white bags, 4 muted yellow bags.
+bright white bags contain 1 shiny gold bag.
+muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
+shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
+dark olive bags contain 3 faded blue bags, 4 dotted black bags.
+vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
+faded blue bags contain no other bags.
+dotted black bags contain no other bags.
+
+
+
+These rules specify the required contents for 9 bag types. In this example, every faded blue
bag is empty, every vibrant plum
bag contains 11 bags (5 faded blue
and 6 dotted black
), and so on.
+
+You have a shiny gold
bag. If you wanted to carry it in at least one other bag, how many different bag colors would be valid for the outermost bag? (In other words: how many colors can, eventually, contain at least one shiny gold
bag?)
+
+In the above rules, the following options would be available to you:
+
+
+ - A bright white
bag, which can hold your shiny gold
bag directly.
+ - A muted yellow
bag, which can hold your shiny gold
bag directly, plus some other bags.
+ - A dark orange
bag, which can hold bright white
and muted yellow
bags, either of which could then hold your shiny gold
bag.
+ - A light red
bag, which can hold bright white
and muted yellow
bags, either of which could then hold your shiny gold
bag.
+
+So, in this example, the number of bag colors that can eventually contain at least one shiny gold
bag is 4
.
+
+How many bag colors can eventually contain at least one shiny gold
bag? (The list of rules is quite long; make sure you get all of it.)
+
+
+## --- Part Two ---
+It's getting pretty expensive to fly these days - not because of ticket prices, but because of the ridiculous number of bags you need to buy!
+
+Consider again your shiny gold
bag and the rules from the above example:
+
+
+ - faded blue
bags contain 0
other bags.
+ - dotted black
bags contain 0
other bags.
+ - vibrant plum
bags contain 11
other bags: 5 faded blue
bags and 6 dotted black
bags.
+ - dark olive
bags contain 7
other bags: 3 faded blue
bags and 4 dotted black
bags.
+
+So, a single shiny gold
bag must contain 1 dark olive
bag (and the 7 bags within it) plus 2 vibrant plum
bags (and the 11 bags within each of those): 1 + 1*7 + 2 + 2*11
= 32
bags!
+
+Of course, the actual rules have a small chance of going several levels deeper than this example; be sure to count all of the bags, even if the nesting becomes topologically impractical!
+
+Here's another example:
+
+
+shiny gold bags contain 2 dark red bags.
+dark red bags contain 2 dark orange bags.
+dark orange bags contain 2 dark yellow bags.
+dark yellow bags contain 2 dark green bags.
+dark green bags contain 2 dark blue bags.
+dark blue bags contain 2 dark violet bags.
+dark violet bags contain no other bags.
+
+
+
+In this example, a single shiny gold
bag must contain 126
other bags.
+
+How many individual bags are required inside your single shiny gold
bag?
+
+
diff --git a/2020/Day07/input.in b/2020/Day07/input.in
index 992861ef5..c05cffd84 100644
Binary files a/2020/Day07/input.in and b/2020/Day07/input.in differ
diff --git a/2020/Day08/README.md b/2020/Day08/README.md
index d59bf37f6..1af283114 100644
--- a/2020/Day08/README.md
+++ b/2020/Day08/README.md
@@ -1,6 +1,98 @@
+original source: [https://adventofcode.com/2020/day/8](https://adventofcode.com/2020/day/8)
## --- Day 8: Handheld Halting ---
Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come with a little umbrella, you are interrupted by the kid sitting next to you.
Their [handheld game console](https://en.wikipedia.org/wiki/Handheld_game_console) won't turn on! They ask if you can take a look.
-Read the [full puzzle](https://adventofcode.com/2020/day/8).
\ No newline at end of file
+You narrow the problem down to a strange infinite loop in the boot code (your puzzle input) of the device. You should be able to fix it, but first you need to be able to run the code in isolation.
+
+The boot code is represented as a text file with one instruction per line of text. Each instruction consists of an operation (acc
, jmp
, or nop
) and an argument (a signed number like +4
or -20
).
+
+
+ - acc
increases or decreases a single global value called the accumulator by the value given in the argument. For example, acc +7
would increase the accumulator by 7. The accumulator starts at 0
. After an acc
instruction, the instruction immediately below it is executed next.
+ - jmp
jumps to a new instruction relative to itself. The next instruction to execute is found using the argument as an offset from the jmp
instruction; for example, jmp +2
would skip the next instruction, jmp +1
would continue to the instruction immediately below it, and jmp -20
would cause the instruction 20 lines above to be executed next.
+ - nop
stands for No OPeration - it does nothing. The instruction immediately below it is executed next.
+
+For example, consider the following program:
+
+
+nop +0
+acc +1
+jmp +4
+acc +3
+jmp -3
+acc -99
+acc +1
+jmp -4
+acc +6
+
+
+
+These instructions are visited in this order:
+
+
+nop +0 | 1
+acc +1 | 2, 8(!)
+jmp +4 | 3
+acc +3 | 6
+jmp -3 | 7
+acc -99 |
+acc +1 | 4
+jmp -4 | 5
+acc +6 |
+
+
+
+First, the nop +0
does nothing. Then, the accumulator is increased from 0 to 1 (acc +1
) and jmp +4
sets the next instruction to the other acc +1
near the bottom. After it increases the accumulator from 1 to 2, jmp -4
executes, setting the next instruction to the only acc +3
. It sets the accumulator to 5, and jmp -3
causes the program to continue back at the first acc +1
.
+
+This is an infinite loop: with this sequence of jumps, the program will run forever. The moment the program tries to run any instruction a second time, you know it will never terminate.
+
+Immediately before the program would run an instruction a second time, the value in the accumulator is 5
.
+
+Run your copy of the boot code. Immediately before any instruction is executed a second time, what value is in the accumulator?
+
+
+## --- Part Two ---
+After some careful analysis, you believe that exactly one instruction is corrupted.
+
+Somewhere in the program, either a jmp
is supposed to be a nop
, or a nop
is supposed to be a jmp
. (No acc
instructions were harmed in the corruption of this boot code.)
+
+The program is supposed to terminate by attempting to execute an instruction immediately after the last instruction in the file. By changing exactly one jmp
or nop
, you can repair the boot code and make it terminate correctly.
+
+For example, consider the same program from above:
+
+
+nop +0
+acc +1
+jmp +4
+acc +3
+jmp -3
+acc -99
+acc +1
+jmp -4
+acc +6
+
+
+
+If you change the first instruction from nop +0
to jmp +0
, it would create a single-instruction infinite loop, never leaving that instruction. If you change almost any of the jmp
instructions, the program will still eventually find another jmp
instruction and loop forever.
+
+However, if you change the second-to-last instruction (from jmp -4
to nop -4
), the program terminates! The instructions are visited in this order:
+
+
+nop +0 | 1
+acc +1 | 2
+jmp +4 | 3
+acc +3 |
+jmp -3 |
+acc -99 |
+acc +1 | 4
+nop -4 | 5
+acc +6 | 6
+
+
+
+After the last instruction (acc +6
), the program terminates by attempting to run the instruction below the last instruction in the file. With this change, after the program terminates, the accumulator contains the value 8
(acc +1
, acc +1
, acc +6
).
+
+Fix the program so that it terminates normally by changing exactly one jmp
(to nop
) or nop
(to jmp
). What is the value of the accumulator after the program terminates?
+
+
diff --git a/2020/Day08/input.in b/2020/Day08/input.in
index f89763dda..bdc7017ad 100644
Binary files a/2020/Day08/input.in and b/2020/Day08/input.in differ
diff --git a/2020/Day09/README.md b/2020/Day09/README.md
index 5a67e3bca..9ce2ad3f0 100644
--- a/2020/Day09/README.md
+++ b/2020/Day09/README.md
@@ -1,6 +1,92 @@
+original source: [https://adventofcode.com/2020/day/9](https://adventofcode.com/2020/day/9)
## --- Day 9: Encoding Error ---
With your neighbor happily enjoying their video game, you turn your attention to an open data port on the little screen in the seat in front of you.
Though the port is non-standard, you manage to connect it to your computer through the clever use of several paperclips. Upon connection, the port outputs a series of numbers (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2020/day/9).
\ No newline at end of file
+The data appears to be encrypted with the eXchange-Masking Addition System (XMAS) which, conveniently for you, is an old cypher with an important weakness.
+
+XMAS starts by transmitting a preamble of 25 numbers. After that, each number you receive should be the sum of any two of the 25 immediately previous numbers. The two numbers will have different values, and there might be more than one such pair.
+
+For example, suppose your preamble consists of the numbers 1
through 25
in a random order. To be valid, the next number must be the sum of two of those numbers:
+
+
+ - 26
would be a valid next number, as it could be 1
plus 25
(or many other pairs, like 2
and 24
).
+ - 49
would be a valid next number, as it is the sum of 24
and 25
.
+ - 100
would not be valid; no two of the previous 25 numbers sum to 100
.
+ - 50
would also not be valid; although 25
appears in the previous 25 numbers, the two numbers in the pair must be different.
+
+Suppose the 26th number is 45
, and the first number (no longer an option, as it is more than 25 numbers ago) was 20
. Now, for the next number to be valid, there needs to be some pair of numbers among 1
-19
, 21
-25
, or 45
that add up to it:
+
+
+ - 26
would still be a valid next number, as 1
and 25
are still within the previous 25 numbers.
+ - 65
would not be valid, as no two of the available numbers sum to it.
+ - 64
and 66
would both be valid, as they are the result of 19+45
and 21+45
respectively.
+
+Here is a larger example which only considers the previous 5 numbers (and has a preamble of length 5):
+
+
+35
+20
+15
+25
+47
+40
+62
+55
+65
+95
+102
+117
+150
+182
+127
+219
+299
+277
+309
+576
+
+
+
+In this example, after the 5-number preamble, almost every number is the sum of two of the previous 5 numbers; the only number that does not follow this rule is 127
.
+
+The first step of attacking the weakness in the XMAS data is to find the first number in the list (after the preamble) which is not the sum of two of the 25 numbers before it. What is the first number that does not have this property?
+
+
+## --- Part Two ---
+The final step in breaking the XMAS encryption relies on the invalid number you just found: you must find a contiguous set of at least two numbers in your list which sum to the invalid number from step 1.
+
+Again consider the above example:
+
+
+35
+20
+15
+25
+47
+40
+62
+55
+65
+95
+102
+117
+150
+182
+127
+219
+299
+277
+309
+576
+
+
+
+In this list, adding up all of the numbers from 15
through 40
produces the invalid number from step 1, 127
. (Of course, the contiguous set of numbers in your actual list might be much longer.)
+
+To find the encryption weakness, add together the smallest and largest number in this contiguous range; in this example, these are 15
and 47
, producing 62
.
+
+What is the encryption weakness in your XMAS-encrypted list of numbers?
+
+
diff --git a/2020/Day09/input.in b/2020/Day09/input.in
index 59a243f0a..5d625e51d 100644
Binary files a/2020/Day09/input.in and b/2020/Day09/input.in differ
diff --git a/2020/Day10/README.md b/2020/Day10/README.md
index 9d44928ce..79d9a3df1 100644
--- a/2020/Day10/README.md
+++ b/2020/Day10/README.md
@@ -1,6 +1,154 @@
+original source: [https://adventofcode.com/2020/day/10](https://adventofcode.com/2020/day/10)
## --- Day 10: Adapter Array ---
Patched into the aircraft's data port, you discover weather forecasts of a massive tropical storm. Before you can figure out whether it will impact your vacation plans, however, your device suddenly turns off!
Its battery is dead.
-Read the [full puzzle](https://adventofcode.com/2020/day/10).
\ No newline at end of file
+You'll need to plug it in. There's only one problem: the charging outlet near your seat produces the wrong number of jolts. Always prepared, you make a list of all of the joltage adapters in your bag.
+
+Each of your joltage adapters is rated for a specific output joltage (your puzzle input). Any given adapter can take an input 1
, 2
, or 3
jolts lower than its rating and still produce its rated output joltage.
+
+In addition, your device has a built-in joltage adapter rated for 3
jolts higher than the highest-rated adapter in your bag. (If your adapter list were 3
, 9
, and 6
, your device's built-in adapter would be rated for 12
jolts.)
+
+Treat the charging outlet near your seat as having an effective joltage rating of 0
.
+
+Since you have some time to kill, you might as well test all of your adapters. Wouldn't want to get to your resort and realize you can't even charge your device!
+
+If you use every adapter in your bag at once, what is the distribution of joltage differences between the charging outlet, the adapters, and your device?
+
+For example, suppose that in your bag, you have adapters with the following joltage ratings:
+
+
+16
+10
+15
+5
+1
+11
+7
+19
+6
+12
+4
+
+
+
+With these adapters, your device's built-in joltage adapter would be rated for 19 + 3 = 22
jolts, 3 higher than the highest-rated adapter.
+
+Because adapters can only connect to a source 1-3 jolts lower than its rating, in order to use every adapter, you'd need to choose them like this:
+
+
+ - The charging outlet has an effective rating of 0
jolts, so the only adapters that could connect to it directly would need to have a joltage rating of 1
, 2
, or 3
jolts. Of these, only one you have is an adapter rated 1
jolt (difference of 1
).
+ - From your 1
-jolt rated adapter, the only choice is your 4
-jolt rated adapter (difference of 3
).
+ - From the 4
-jolt rated adapter, the adapters rated 5
, 6
, or 7
are valid choices. However, in order to not skip any adapters, you have to pick the adapter rated 5
jolts (difference of 1
).
+ - Similarly, the next choices would need to be the adapter rated 6
and then the adapter rated 7
(with difference of 1
and 1
).
+ - The only adapter that works with the 7
-jolt rated adapter is the one rated 10
jolts (difference of 3
).
+ - From 10
, the choices are 11
or 12
; choose 11
(difference of 1
) and then 12
(difference of 1
).
+ - After 12
, only valid adapter has a rating of 15
(difference of 3
), then 16
(difference of 1
), then 19
(difference of 3
).
+ - Finally, your device's built-in adapter is always 3 higher than the highest adapter, so its rating is 22
jolts (always a difference of 3
).
+
+In this example, when using every adapter, there are 7
differences of 1 jolt and 5
differences of 3 jolts.
+
+Here is a larger example:
+
+
+28
+33
+18
+42
+31
+14
+46
+20
+48
+47
+24
+23
+49
+45
+19
+38
+39
+11
+1
+32
+25
+35
+8
+17
+7
+9
+4
+2
+34
+10
+3
+
+
+
+In this larger example, in a chain that uses all of the adapters, there are 22
differences of 1 jolt and 10
differences of 3 jolts.
+
+Find a chain that uses all of your adapters to connect the charging outlet to your device's built-in adapter and count the joltage differences between the charging outlet, the adapters, and your device. What is the number of 1-jolt differences multiplied by the number of 3-jolt differences?
+
+
+## --- Part Two ---
+To completely determine whether you have enough adapters, you'll need to figure out how many different ways they can be arranged. Every arrangement needs to connect the charging outlet to your device. The previous rules about when adapters can successfully connect still apply.
+
+The first example above (the one that starts with 16
, 10
, 15
) supports the following arrangements:
+
+
+(0), 1, 4, 5, 6, 7, 10, 11, 12, 15, 16, 19, (22)
+(0), 1, 4, 5, 6, 7, 10, 12, 15, 16, 19, (22)
+(0), 1, 4, 5, 7, 10, 11, 12, 15, 16, 19, (22)
+(0), 1, 4, 5, 7, 10, 12, 15, 16, 19, (22)
+(0), 1, 4, 6, 7, 10, 11, 12, 15, 16, 19, (22)
+(0), 1, 4, 6, 7, 10, 12, 15, 16, 19, (22)
+(0), 1, 4, 7, 10, 11, 12, 15, 16, 19, (22)
+(0), 1, 4, 7, 10, 12, 15, 16, 19, (22)
+
+
+
+(The charging outlet and your device's built-in adapter are shown in parentheses.) Given the adapters from the first example, the total number of arrangements that connect the charging outlet to your device is 8
.
+
+The second example above (the one that starts with 28
, 33
, 18
) has many arrangements. Here are a few:
+
+
+(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
+32, 33, 34, 35, 38, 39, 42, 45, 46, 47, 48, 49, (52)
+
+(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
+32, 33, 34, 35, 38, 39, 42, 45, 46, 47, 49, (52)
+
+(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
+32, 33, 34, 35, 38, 39, 42, 45, 46, 48, 49, (52)
+
+(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
+32, 33, 34, 35, 38, 39, 42, 45, 46, 49, (52)
+
+(0), 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 17, 18, 19, 20, 23, 24, 25, 28, 31,
+32, 33, 34, 35, 38, 39, 42, 45, 47, 48, 49, (52)
+
+(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
+46, 48, 49, (52)
+
+(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
+46, 49, (52)
+
+(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
+47, 48, 49, (52)
+
+(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
+47, 49, (52)
+
+(0), 3, 4, 7, 10, 11, 14, 17, 20, 23, 25, 28, 31, 34, 35, 38, 39, 42, 45,
+48, 49, (52)
+
+
+
+In total, this set of adapters can connect the charging outlet to your device in 19208
distinct arrangements.
+
+You glance back down at your bag and try to remember why you brought so many adapters; there must be more than a trillion valid ways to arrange them! Surely, there must be an efficient way to count the arrangements.
+
+What is the total number of distinct ways you can arrange the adapters to connect the charging outlet to your device?
+
+
diff --git a/2020/Day10/input.in b/2020/Day10/input.in
index 759c3b340..f7374a05d 100644
Binary files a/2020/Day10/input.in and b/2020/Day10/input.in differ
diff --git a/2020/Day11/README.md b/2020/Day11/README.md
index a63684e2a..80458b89a 100644
--- a/2020/Day11/README.md
+++ b/2020/Day11/README.md
@@ -1,6 +1,259 @@
+original source: [https://adventofcode.com/2020/day/11](https://adventofcode.com/2020/day/11)
## --- Day 11: Seating System ---
Your plane lands with plenty of time to spare. The final leg of your journey is a ferry that goes directly to the tropical island where you can finally start your vacation. As you reach the waiting area to board the ferry, you realize you're so early, nobody else has even arrived yet!
By modeling the process people use to choose (or abandon) their seat in the waiting area, you're pretty sure you can predict the best place to sit. You make a quick map of the seat layout (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2020/day/11).
\ No newline at end of file
+The seat layout fits neatly on a grid. Each position is either floor (.
), an empty seat (L
), or an occupied seat (#
). For example, the initial seat layout might look like this:
+
+
+L.LL.LL.LL
+LLLLLLL.LL
+L.L.L..L..
+LLLL.LL.LL
+L.LL.LL.LL
+L.LLLLL.LL
+..L.L.....
+LLLLLLLLLL
+L.LLLLLL.L
+L.LLLLL.LL
+
+
+
+Now, you just need to model the people who will be arriving shortly. Fortunately, people are entirely predictable and always follow a simple set of rules. All decisions are based on the number of occupied seats adjacent to a given seat (one of the eight positions immediately up, down, left, right, or diagonal from the seat). The following rules are applied to every seat simultaneously:
+
+
+ - If a seat is empty (L
) and there are no occupied seats adjacent to it, the seat becomes occupied.
+ - If a seat is occupied (#
) and four or more seats adjacent to it are also occupied, the seat becomes empty.
+ - Otherwise, the seat's state does not change.
+
+Floor (.
) never changes; seats don't move, and nobody sits on the floor.
+
+After one round of these rules, every seat in the example layout becomes occupied:
+
+
+#.##.##.##
+#######.##
+#.#.#..#..
+####.##.##
+#.##.##.##
+#.#####.##
+..#.#.....
+##########
+#.######.#
+#.#####.##
+
+
+
+After a second round, the seats with four or more occupied adjacent seats become empty again:
+
+
+#.LL.L#.##
+#LLLLLL.L#
+L.L.L..L..
+#LLL.LL.L#
+#.LL.LL.LL
+#.LLLL#.##
+..L.L.....
+#LLLLLLLL#
+#.LLLLLL.L
+#.#LLLL.##
+
+
+
+This process continues for three more rounds:
+
+
+#.##.L#.##
+#L###LL.L#
+L.#.#..#..
+#L##.##.L#
+#.##.LL.LL
+#.###L#.##
+..#.#.....
+#L######L#
+#.LL###L.L
+#.#L###.##
+
+
+
+
+#.#L.L#.##
+#LLL#LL.L#
+L.L.L..#..
+#LLL.##.L#
+#.LL.LL.LL
+#.LL#L#.##
+..L.L.....
+#L#LLLL#L#
+#.LLLLLL.L
+#.#L#L#.##
+
+
+
+
+#.#L.L#.##
+#LLL#LL.L#
+L.#.L..#..
+#L##.##.L#
+#.#L.LL.LL
+#.#L#L#.##
+..L.L.....
+#L#L##L#L#
+#.LLLLLL.L
+#.#L#L#.##
+
+
+
+At this point, something interesting happens: the chaos stabilizes and further applications of these rules cause no seats to change state! Once people stop moving around, you count 37
occupied seats.
+
+Simulate your seating area by applying the seating rules repeatedly until no seats change state. How many seats end up occupied?
+
+
+## --- Part Two ---
+As soon as people start to arrive, you realize your mistake. People don't just care about adjacent seats - they care about the first seat they can see in each of those eight directions!
+
+Now, instead of considering just the eight immediately adjacent seats, consider the first seat in each of those eight directions. For example, the empty seat below would see eight occupied seats:
+
+
+.......#.
+...#.....
+.#.......
+.........
+..#L....#
+....#....
+.........
+#........
+...#.....
+
+
+
+The leftmost empty seat below would only see one empty seat, but cannot see any of the occupied ones:
+
+
+.............
+.L.L.#.#.#.#.
+.............
+
+
+
+The empty seat below would see no occupied seats:
+
+
+.##.##.
+#.#.#.#
+##...##
+...L...
+##...##
+#.#.#.#
+.##.##.
+
+
+
+Also, people seem to be more tolerant than you expected: it now takes five or more visible occupied seats for an occupied seat to become empty (rather than four or more from the previous rules). The other rules still apply: empty seats that see no occupied seats become occupied, seats matching no rule don't change, and floor never changes.
+
+Given the same starting layout as above, these new rules cause the seating area to shift around as follows:
+
+
+L.LL.LL.LL
+LLLLLLL.LL
+L.L.L..L..
+LLLL.LL.LL
+L.LL.LL.LL
+L.LLLLL.LL
+..L.L.....
+LLLLLLLLLL
+L.LLLLLL.L
+L.LLLLL.LL
+
+
+
+
+#.##.##.##
+#######.##
+#.#.#..#..
+####.##.##
+#.##.##.##
+#.#####.##
+..#.#.....
+##########
+#.######.#
+#.#####.##
+
+
+
+
+#.LL.LL.L#
+#LLLLLL.LL
+L.L.L..L..
+LLLL.LL.LL
+L.LL.LL.LL
+L.LLLLL.LL
+..L.L.....
+LLLLLLLLL#
+#.LLLLLL.L
+#.LLLLL.L#
+
+
+
+
+#.L#.##.L#
+#L#####.LL
+L.#.#..#..
+##L#.##.##
+#.##.#L.##
+#.#####.#L
+..#.#.....
+LLL####LL#
+#.L#####.L
+#.L####.L#
+
+
+
+
+#.L#.L#.L#
+#LLLLLL.LL
+L.L.L..#..
+##LL.LL.L#
+L.LL.LL.L#
+#.LLLLL.LL
+..L.L.....
+LLLLLLLLL#
+#.LLLLL#.L
+#.L#LL#.L#
+
+
+
+
+#.L#.L#.L#
+#LLLLLL.LL
+L.L.L..#..
+##L#.#L.L#
+L.L#.#L.L#
+#.L####.LL
+..#.#.....
+LLL###LLL#
+#.LLLLL#.L
+#.L#LL#.L#
+
+
+
+
+#.L#.L#.L#
+#LLLLLL.LL
+L.L.L..#..
+##L#.#L.L#
+L.L#.LL.L#
+#.LLLL#.LL
+..#.L.....
+LLL###LLL#
+#.LLLLL#.L
+#.L#LL#.L#
+
+
+
+Again, at this point, people stop shifting around and the seating area reaches equilibrium. Once this occurs, you count 26
occupied seats.
+
+Given the new visibility method and the rule change for occupied seats becoming empty, once equilibrium is reached, how many seats end up occupied?
+
+
diff --git a/2020/Day11/input.in b/2020/Day11/input.in
index e47a1f52c..7e491f467 100644
Binary files a/2020/Day11/input.in and b/2020/Day11/input.in differ
diff --git a/2020/Day12/README.md b/2020/Day12/README.md
index 5a856ba51..80377a84d 100644
--- a/2020/Day12/README.md
+++ b/2020/Day12/README.md
@@ -1,6 +1,74 @@
+original source: [https://adventofcode.com/2020/day/12](https://adventofcode.com/2020/day/12)
## --- Day 12: Rain Risk ---
Your ferry made decent progress toward the island, but the storm came in faster than anyone expected. The ferry needs to take evasive actions!
Unfortunately, the ship's navigation computer seems to be malfunctioning; rather than giving a route directly to safety, it produced extremely circuitous instructions. When the captain uses the [PA system](https://en.wikipedia.org/wiki/Public_address_system) to ask if anyone can help, you quickly volunteer.
-Read the [full puzzle](https://adventofcode.com/2020/day/12).
\ No newline at end of file
+The navigation instructions (your puzzle input) consists of a sequence of single-character actions paired with integer input values. After staring at them for a few minutes, you work out what they probably mean:
+
+
+ - Action N
means to move north by the given value.
+ - Action S
means to move south by the given value.
+ - Action E
means to move east by the given value.
+ - Action W
means to move west by the given value.
+ - Action L
means to turn left the given number of degrees.
+ - Action R
means to turn right the given number of degrees.
+ - Action F
means to move forward by the given value in the direction the ship is currently facing.
+
+The ship starts by facing east. Only the L
and R
actions change the direction the ship is facing. (That is, if the ship is facing east and the next instruction is N10
, the ship would move north 10 units, but would still move east if the following action were F
.)
+
+For example:
+
+
+F10
+N3
+F7
+R90
+F11
+
+
+
+These instructions would be handled as follows:
+
+
+ - F10
would move the ship 10 units east (because the ship starts by facing east) to east 10, north 0.
+ - N3
would move the ship 3 units north to east 10, north 3.
+ - F7
would move the ship another 7 units east (because the ship is still facing east) to east 17, north 3.
+ - R90
would cause the ship to turn right by 90 degrees and face south; it remains at east 17, north 3.
+ - F11
would move the ship 11 units south to east 17, south 8.
+
+At the end of these instructions, the ship's [Manhattan distance](https://en.wikipedia.org/wiki/Manhattan_distance) (sum of the absolute values of its east/west position and its north/south position) from its starting position is 17 + 8
= 25
.
+
+Figure out where the navigation instructions lead. What is the Manhattan distance between that location and the ship's starting position?
+
+
+## --- Part Two ---
+Before you can give the destination to the captain, you realize that the actual action meanings were printed on the back of the instructions the whole time.
+
+Almost all of the actions indicate how to move a waypoint which is relative to the ship's position:
+
+
+ - Action N
means to move the waypoint north by the given value.
+ - Action S
means to move the waypoint south by the given value.
+ - Action E
means to move the waypoint east by the given value.
+ - Action W
means to move the waypoint west by the given value.
+ - Action L
means to rotate the waypoint around the ship left (counter-clockwise) the given number of degrees.
+ - Action R
means to rotate the waypoint around the ship right (clockwise) the given number of degrees.
+ - Action F
means to move forward to the waypoint a number of times equal to the given value.
+
+The waypoint starts 10 units east and 1 unit north relative to the ship. The waypoint is relative to the ship; that is, if the ship moves, the waypoint moves with it.
+
+For example, using the same instructions as above:
+
+
+ - F10
moves the ship to the waypoint 10 times (a total of 100 units east and 10 units north), leaving the ship at east 100, north 10. The waypoint stays 10 units east and 1 unit north of the ship.
+ - N3
moves the waypoint 3 units north to 10 units east and 4 units north of the ship. The ship remains at east 100, north 10.
+ - F7
moves the ship to the waypoint 7 times (a total of 70 units east and 28 units north), leaving the ship at east 170, north 38. The waypoint stays 10 units east and 4 units north of the ship.
+ - R90
rotates the waypoint around the ship clockwise 90 degrees, moving it to 4 units east and 10 units south of the ship. The ship remains at east 170, north 38.
+ - F11
moves the ship to the waypoint 11 times (a total of 44 units east and 110 units south), leaving the ship at east 214, south 72. The waypoint stays 4 units east and 10 units south of the ship.
+
+After these operations, the ship's Manhattan distance from its starting position is 214 + 72
= 286
.
+
+Figure out where the navigation instructions actually lead. What is the Manhattan distance between that location and the ship's starting position?
+
+
diff --git a/2020/Day12/input.in b/2020/Day12/input.in
index 87a53ff58..e10642dfe 100644
Binary files a/2020/Day12/input.in and b/2020/Day12/input.in differ
diff --git a/2020/Day13/README.md b/2020/Day13/README.md
index 358e65ddb..34c0c72e4 100644
--- a/2020/Day13/README.md
+++ b/2020/Day13/README.md
@@ -1,6 +1,127 @@
+original source: [https://adventofcode.com/2020/day/13](https://adventofcode.com/2020/day/13)
## --- Day 13: Shuttle Search ---
Your ferry can make it safely to a nearby port, but it won't get much further. When you call to book another ship, you discover that no ships embark from that port to your vacation island. You'll need to get from the port to the nearest airport.
Fortunately, a shuttle bus service is available to bring you from the sea port to the airport! Each bus has an ID number that also indicates how often the bus leaves for the airport.
-Read the [full puzzle](https://adventofcode.com/2020/day/13).
\ No newline at end of file
+Bus schedules are defined based on a timestamp that measures the number of minutes since some fixed reference point in the past. At timestamp 0
, every bus simultaneously departed from the sea port. After that, each bus travels to the airport, then various other locations, and finally returns to the sea port to repeat its journey forever.
+
+The time this loop takes a particular bus is also its ID number: the bus with ID 5
departs from the sea port at timestamps 0
, 5
, 10
, 15
, and so on. The bus with ID 11
departs at 0
, 11
, 22
, 33
, and so on. If you are there when the bus departs, you can ride that bus to the airport!
+
+Your notes (your puzzle input) consist of two lines. The first line is your estimate of the earliest timestamp you could depart on a bus. The second line lists the bus IDs that are in service according to the shuttle company; entries that show x
must be out of service, so you decide to ignore them.
+
+To save time once you arrive, your goal is to figure out the earliest bus you can take to the airport. (There will be exactly one such bus.)
+
+For example, suppose you have the following notes:
+
+
+939
+7,13,x,x,59,x,31,19
+
+
+
+Here, the earliest timestamp you could depart is 939
, and the bus IDs in service are 7
, 13
, 59
, 31
, and 19
. Near timestamp 939
, these bus IDs depart at the times marked D
:
+
+
+time bus 7 bus 13 bus 59 bus 31 bus 19
+929 . . . . .
+930 . . . D .
+931 D . . . D
+932 . . . . .
+933 . . . . .
+934 . . . . .
+935 . . . . .
+936 . D . . .
+937 . . . . .
+938 D . . . .
+939 . . . . .
+940 . . . . .
+941 . . . . .
+942 . . . . .
+943 . . . . .
+944 . . D . .
+945 D . . . .
+946 . . . . .
+947 . . . . .
+948 . . . . .
+949 . D . . .
+
+
+
+The earliest bus you could take is bus ID 59
. It doesn't depart until timestamp 944
, so you would need to wait 944 - 939 = 5
minutes before it departs. Multiplying the bus ID by the number of minutes you'd need to wait gives 295
.
+
+What is the ID of the earliest bus you can take to the airport multiplied by the number of minutes you'll need to wait for that bus?
+
+
+## --- Part Two ---
+The shuttle company is running a contest: one gold coin for anyone that can find the earliest timestamp such that the first bus ID departs at that time and each subsequent listed bus ID departs at that subsequent minute. (The first line in your input is no longer relevant.)
+
+For example, suppose you have the same list of bus IDs as above:
+
+
+7,13,x,x,59,x,31,19
+
+
+An x
in the schedule means there are no constraints on what bus IDs must depart at that time.
+
+This means you are looking for the earliest timestamp (called t
) such that:
+
+
+ - Bus ID 7
departs at timestamp t
.
+ - Bus ID 13
departs one minute after timestamp t
.
+ - There are no requirements or restrictions on departures at two or three minutes after timestamp t
.
+ - Bus ID 59
departs four minutes after timestamp t
.
+ - There are no requirements or restrictions on departures at five minutes after timestamp t
.
+ - Bus ID 31
departs six minutes after timestamp t
.
+ - Bus ID 19
departs seven minutes after timestamp t
.
+
+The only bus departures that matter are the listed bus IDs at their specific offsets from t
. Those bus IDs can depart at other times, and other bus IDs can depart at those times. For example, in the list above, because bus ID 19
must depart seven minutes after the timestamp at which bus ID 7
departs, bus ID 7
will always also be departing with bus ID 19
at seven minutes after timestamp t
.
+
+In this example, the earliest timestamp at which this occurs is 1068781
:
+
+
+time bus 7 bus 13 bus 59 bus 31 bus 19
+1068773 . . . . .
+1068774 D . . . .
+1068775 . . . . .
+1068776 . . . . .
+1068777 . . . . .
+1068778 . . . . .
+1068779 . . . . .
+1068780 . . . . .
+1068781 D . . . .
+1068782 . D . . .
+1068783 . . . . .
+1068784 . . . . .
+1068785 . . D . .
+1068786 . . . . .
+1068787 . . . D .
+1068788 D . . . D
+1068789 . . . . .
+1068790 . . . . .
+1068791 . . . . .
+1068792 . . . . .
+1068793 . . . . .
+1068794 . . . . .
+1068795 D D . . .
+1068796 . . . . .
+1068797 . . . . .
+
+
+
+In the above example, bus ID 7
departs at timestamp 1068788
(seven minutes after t
). This is fine; the only requirement on that minute is that bus ID 19
departs then, and it does.
+
+Here are some other examples:
+
+
+ - The earliest timestamp that matches the list 17,x,13,19
is 3417
.
+ - 67,7,59,61
first occurs at timestamp 754018
.
+ - 67,x,7,59,61
first occurs at timestamp 779210
.
+ - 67,7,x,59,61
first occurs at timestamp 1261476
.
+ - 1789,37,47,1889
first occurs at timestamp 1202161486
.
+
+However, with so many bus IDs in your list, surely the actual earliest timestamp will be larger than 100000000000000
!
+
+What is the earliest timestamp such that all of the listed bus IDs depart at offsets matching their positions in the list?
+
+
diff --git a/2020/Day13/input.in b/2020/Day13/input.in
index d5be0d5c9..3d3e1d30e 100644
Binary files a/2020/Day13/input.in and b/2020/Day13/input.in differ
diff --git a/2020/Day14/README.md b/2020/Day14/README.md
index c5e356207..e8a16d304 100644
--- a/2020/Day14/README.md
+++ b/2020/Day14/README.md
@@ -1,6 +1,125 @@
+original source: [https://adventofcode.com/2020/day/14](https://adventofcode.com/2020/day/14)
## --- Day 14: Docking Data ---
As your ferry approaches the sea port, the captain asks for your help again. The computer system that runs this port isn't compatible with the docking program on the ferry, so the docking parameters aren't being correctly initialized in the docking program's memory.
After a brief inspection, you discover that the sea port's computer system uses a strange [bitmask](https://en.wikipedia.org/wiki/Mask_(computing)) system in its initialization program. Although you don't have the correct decoder chip handy, you can emulate it in software!
-Read the [full puzzle](https://adventofcode.com/2020/day/14).
\ No newline at end of file
+The initialization program (your puzzle input) can either update the bitmask or write a value to memory. Values and memory addresses are both 36-bit unsigned integers. For example, ignoring bitmasks for a moment, a line like mem[8] = 11
would write the value 11
to memory address 8
.
+
+The bitmask is always given as a string of 36 bits, written with the most significant bit (representing 2^35
) on the left and the least significant bit (2^0
, that is, the 1
s bit) on the right. The current bitmask is applied to values immediately before they are written to memory: a 0
or 1
overwrites the corresponding bit in the value, while an X
leaves the bit in the value unchanged.
+
+For example, consider the following program:
+
+
+mask = XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
+mem[8] = 11
+mem[7] = 101
+mem[8] = 0
+
+
+
+This program starts by specifying a bitmask (mask = ....
). The mask it specifies will overwrite two bits in every written value: the 2
s bit is overwritten with 0
, and the 64
s bit is overwritten with 1
.
+
+The program then attempts to write the value 11
to memory address 8
. By expanding everything out to individual bits, the mask is applied as follows:
+
+
+value: 000000000000000000000000000000001011 (decimal 11)
+mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
+result: 000000000000000000000000000001001001 (decimal 73)
+
+
+
+So, because of the mask, the value 73
is written to memory address 8
instead. Then, the program tries to write 101
to address 7
:
+
+
+value: 000000000000000000000000000001100101 (decimal 101)
+mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
+result: 000000000000000000000000000001100101 (decimal 101)
+
+
+
+This time, the mask has no effect, as the bits it overwrote were already the values the mask tried to set. Finally, the program tries to write 0
to address 8
:
+
+
+value: 000000000000000000000000000000000000 (decimal 0)
+mask: XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X
+result: 000000000000000000000000000001000000 (decimal 64)
+
+
+
+64
is written to address 8
instead, overwriting the value that was there previously.
+
+To initialize your ferry's docking program, you need the sum of all values left in memory after the initialization program completes. (The entire 36-bit address space begins initialized to the value 0
at every address.) In the above example, only two values in memory are not zero - 101
(at address 7
) and 64
(at address 8
) - producing a sum of 165
.
+
+Execute the initialization program. What is the sum of all values left in memory after it completes?
+
+
+## --- Part Two ---
+For some reason, the sea port's computer system still can't communicate with your ferry's docking program. It must be using version 2 of the decoder chip!
+
+A version 2 decoder chip doesn't modify the values being written at all. Instead, it acts as a [memory address decoder](https://www.youtube.com/watch?v=PvfhANgLrm4). Immediately before a value is written to memory, each bit in the bitmask modifies the corresponding bit of the destination memory address in the following way:
+
+
+ - If the bitmask bit is 0
, the corresponding memory address bit is unchanged.
+ - If the bitmask bit is 1
, the corresponding memory address bit is overwritten with 1
.
+ - If the bitmask bit is X
, the corresponding memory address bit is floating.
+
+A floating bit is not connected to anything and instead fluctuates unpredictably. In practice, this means the floating bits will take on all possible values, potentially causing many memory addresses to be written all at once!
+
+For example, consider the following program:
+
+
+mask = 000000000000000000000000000000X1001X
+mem[42] = 100
+mask = 00000000000000000000000000000000X0XX
+mem[26] = 1
+
+
+
+When this program goes to write to memory address 42
, it first applies the bitmask:
+
+
+address: 000000000000000000000000000000101010 (decimal 42)
+mask: 000000000000000000000000000000X1001X
+result: 000000000000000000000000000000X1101X
+
+
+
+After applying the mask, four bits are overwritten, three of which are different, and two of which are floating. Floating bits take on every possible combination of values; with two floating bits, four actual memory addresses are written:
+
+
+000000000000000000000000000000011010 (decimal 26)
+000000000000000000000000000000011011 (decimal 27)
+000000000000000000000000000000111010 (decimal 58)
+000000000000000000000000000000111011 (decimal 59)
+
+
+
+Next, the program is about to write to memory address 26
with a different bitmask:
+
+
+address: 000000000000000000000000000000011010 (decimal 26)
+mask: 00000000000000000000000000000000X0XX
+result: 00000000000000000000000000000001X0XX
+
+
+
+This results in an address with three floating bits, causing writes to eight memory addresses:
+
+
+000000000000000000000000000000010000 (decimal 16)
+000000000000000000000000000000010001 (decimal 17)
+000000000000000000000000000000010010 (decimal 18)
+000000000000000000000000000000010011 (decimal 19)
+000000000000000000000000000000011000 (decimal 24)
+000000000000000000000000000000011001 (decimal 25)
+000000000000000000000000000000011010 (decimal 26)
+000000000000000000000000000000011011 (decimal 27)
+
+
+
+The entire 36-bit address space still begins initialized to the value 0 at every address, and you still need the sum of all values left in memory at the end of the program. In this example, the sum is 208
.
+
+Execute the initialization program using an emulator for a version 2 decoder chip. What is the sum of all values left in memory after it completes?
+
+
diff --git a/2020/Day14/input.in b/2020/Day14/input.in
index 5ee6d12fb..e7977bf3e 100644
Binary files a/2020/Day14/input.in and b/2020/Day14/input.in differ
diff --git a/2020/Day15/README.md b/2020/Day15/README.md
index 5ac8db2cb..062bb178e 100644
--- a/2020/Day15/README.md
+++ b/2020/Day15/README.md
@@ -1,6 +1,60 @@
+original source: [https://adventofcode.com/2020/day/15](https://adventofcode.com/2020/day/15)
## --- Day 15: Rambunctious Recitation ---
You catch the airport shuttle and try to book a new flight to your vacation island. Due to the storm, all direct flights have been cancelled, but a route is available to get around the storm. You take it.
While you wait for your flight, you decide to check in with the Elves back at the North Pole. They're playing a memory game and are ever so excited to explain the rules!
-Read the [full puzzle](https://adventofcode.com/2020/day/15).
\ No newline at end of file
+In this game, the players take turns saying numbers. They begin by taking turns reading from a list of starting numbers (your puzzle input). Then, each turn consists of considering the most recently spoken number:
+
+
+ - If that was the first time the number has been spoken, the current player says 0
.
+ - Otherwise, the number had been spoken before; the current player announces how many turns apart the number is from when it was previously spoken.
+
+So, after the starting numbers, each turn results in that player speaking aloud either 0
(if the last number is new) or an age (if the last number is a repeat).
+
+For example, suppose the starting numbers are 0,3,6
:
+
+
+ - Turn 1: The 1
st number spoken is a starting number, 0
.
+ - Turn 2: The 2
nd number spoken is a starting number, 3
.
+ - Turn 3: The 3
rd number spoken is a starting number, 6
.
+ - Turn 4: Now, consider the last number spoken, 6
. Since that was the first time the number had been spoken, the 4
th number spoken is 0
.
+ - Turn 5: Next, again consider the last number spoken, 0
. Since it had been spoken before, the next number to speak is the difference between the turn number when it was last spoken (the previous turn, 4
) and the turn number of the time it was most recently spoken before then (turn 1
). Thus, the 5
th number spoken is 4 - 1
, 3
.
+ - Turn 6: The last number spoken, 3
had also been spoken before, most recently on turns 5
and 2
. So, the 6
th number spoken is 5 - 2
, 3
.
+ - Turn 7: Since 3
was just spoken twice in a row, and the last two turns are 1
turn apart, the 7
th number spoken is 1
.
+ - Turn 8: Since 1
is new, the 8
th number spoken is 0
.
+ - Turn 9: 0
was last spoken on turns 8
and 4
, so the 9
th number spoken is the difference between them, 4
.
+ - Turn 10: 4
is new, so the 10
th number spoken is 0
.
+
+(The game ends when the Elves get sick of playing or dinner is ready, whichever comes first.)
+
+Their question for you is: what will be the 2020
th number spoken? In the example above, the 2020
th number spoken will be 436
.
+
+Here are a few more examples:
+
+
+ - Given the starting numbers 1,3,2
, the 2020
th number spoken is 1
.
+ - Given the starting numbers 2,1,3
, the 2020
th number spoken is 10
.
+ - Given the starting numbers 1,2,3
, the 2020
th number spoken is 27
.
+ - Given the starting numbers 2,3,1
, the 2020
th number spoken is 78
.
+ - Given the starting numbers 3,2,1
, the 2020
th number spoken is 438
.
+ - Given the starting numbers 3,1,2
, the 2020
th number spoken is 1836
.
+
+Given your starting numbers, what will be the 2020
th number spoken?
+
+
+## --- Part Two ---
+Impressed, the Elves issue you a challenge: determine the 30000000
th number spoken. For example, given the same starting numbers as above:
+
+
+ - Given 0,3,6
, the 30000000
th number spoken is 175594
.
+ - Given 1,3,2
, the 30000000
th number spoken is 2578
.
+ - Given 2,1,3
, the 30000000
th number spoken is 3544142
.
+ - Given 1,2,3
, the 30000000
th number spoken is 261214
.
+ - Given 2,3,1
, the 30000000
th number spoken is 6895259
.
+ - Given 3,2,1
, the 30000000
th number spoken is 18
.
+ - Given 3,1,2
, the 30000000
th number spoken is 362
.
+
+Given your starting numbers, what will be the 30000000
th number spoken?
+
+
diff --git a/2020/Day15/input.in b/2020/Day15/input.in
index 1522fa3f9..6557303f7 100644
Binary files a/2020/Day15/input.in and b/2020/Day15/input.in differ
diff --git a/2020/Day16/README.md b/2020/Day16/README.md
index 60aa6b76e..2bf48c8d1 100644
--- a/2020/Day16/README.md
+++ b/2020/Day16/README.md
@@ -1,6 +1,76 @@
+original source: [https://adventofcode.com/2020/day/16](https://adventofcode.com/2020/day/16)
## --- Day 16: Ticket Translation ---
As you're walking to yet another connecting flight, you realize that one of the legs of your re-routed trip coming up is on a high-speed train. However, the train ticket you were given is in a language you don't understand. You should probably figure out what it says before you get to the train station after the next flight.
Unfortunately, you can't actually read the words on the ticket. You can, however, read the numbers, and so you figure out the fields these tickets must have and the valid ranges for values in those fields.
-Read the [full puzzle](https://adventofcode.com/2020/day/16).
\ No newline at end of file
+You collect the rules for ticket fields, the numbers on your ticket, and the numbers on other nearby tickets for the same train service (via the airport security cameras) together into a single document you can reference (your puzzle input).
+
+The rules for ticket fields specify a list of fields that exist somewhere on the ticket and the valid ranges of values for each field. For example, a rule like class: 1-3 or 5-7
means that one of the fields in every ticket is named class
and can be any value in the ranges 1-3
or 5-7
(inclusive, such that 3
and 5
are both valid in this field, but 4
is not).
+
+Each ticket is represented by a single line of comma-separated values. The values are the numbers on the ticket in the order they appear; every ticket has the same format. For example, consider this ticket:
+
+
+.--------------------------------------------------------.
+| ????: 101 ?????: 102 ??????????: 103 ???: 104 |
+| |
+| ??: 301 ??: 302 ???????: 303 ??????? |
+| ??: 401 ??: 402 ???? ????: 403 ????????? |
+'--------------------------------------------------------'
+
+
+
+Here, ?
represents text in a language you don't understand. This ticket might be represented as 101,102,103,104,301,302,303,401,402,403
; of course, the actual train tickets you're looking at are much more complicated. In any case, you've extracted just the numbers in such a way that the first number is always the same specific field, the second number is always a different specific field, and so on - you just don't know what each position actually means!
+
+Start by determining which tickets are completely invalid; these are tickets that contain values which aren't valid for any field. Ignore your ticket for now.
+
+For example, suppose you have the following notes:
+
+
+class: 1-3 or 5-7
+row: 6-11 or 33-44
+seat: 13-40 or 45-50
+
+your ticket:
+7,1,14
+
+nearby tickets:
+7,3,47
+40,4,50
+55,2,20
+38,6,12
+
+
+
+It doesn't matter which position corresponds to which field; you can identify invalid nearby tickets by considering only whether tickets contain values that are not valid for any field. In this example, the values on the first nearby ticket are all valid for at least one field. This is not true of the other three nearby tickets: the values 4
, 55
, and 12
are are not valid for any field. Adding together all of the invalid values produces your ticket scanning error rate: 4 + 55 + 12
= 71
.
+
+Consider the validity of the nearby tickets you scanned. What is your ticket scanning error rate?
+
+
+## --- Part Two ---
+Now that you've identified which tickets contain invalid values, discard those tickets entirely. Use the remaining valid tickets to determine which field is which.
+
+Using the valid ranges for each field, determine what order the fields appear on the tickets. The order is consistent between all tickets: if seat
is the third field, it is the third field on every ticket, including your ticket.
+
+For example, suppose you have the following notes:
+
+
+class: 0-1 or 4-19
+row: 0-5 or 8-19
+seat: 0-13 or 16-19
+
+your ticket:
+11,12,13
+
+nearby tickets:
+3,9,18
+15,1,5
+5,14,9
+
+
+
+Based on the nearby tickets in the above example, the first position must be row
, the second position must be class
, and the third position must be seat
; you can conclude that in your ticket, class
is 12
, row
is 11
, and seat
is 13
.
+
+Once you work out which field is which, look for the six fields on your ticket that start with the word departure
. What do you get if you multiply those six values together?
+
+
diff --git a/2020/Day16/input.in b/2020/Day16/input.in
index a63ca86a8..9f7314d01 100644
Binary files a/2020/Day16/input.in and b/2020/Day16/input.in differ
diff --git a/2020/Day17/README.md b/2020/Day17/README.md
index 77aab7398..f477ce111 100644
--- a/2020/Day17/README.md
+++ b/2020/Day17/README.md
@@ -1,6 +1,408 @@
+original source: [https://adventofcode.com/2020/day/17](https://adventofcode.com/2020/day/17)
## --- Day 17: Conway Cubes ---
As your flight slowly drifts through the sky, the Elves at the Mythical Information Bureau at the North Pole contact you. They'd like some help debugging a malfunctioning experimental energy source aboard one of their super-secret imaging satellites.
The experimental energy source is based on cutting-edge technology: a set of Conway Cubes contained in a pocket dimension! When you hear it's having problems, you can't help but agree to take a look.
-Read the [full puzzle](https://adventofcode.com/2020/day/17).
\ No newline at end of file
+The pocket dimension contains an infinite 3-dimensional grid. At every integer 3-dimensional coordinate (x,y,z
), there exists a single cube which is either active or inactive.
+
+In the initial state of the pocket dimension, almost all cubes start inactive. The only exception to this is a small flat region of cubes (your puzzle input); the cubes in this region start in the specified active (#
) or inactive (.
) state.
+
+The energy source then proceeds to boot up by executing six cycles.
+
+Each cube only ever considers its neighbors: any of the 26 other cubes where any of their coordinates differ by at most 1
. For example, given the cube at x=1,y=2,z=3
, its neighbors include the cube at x=2,y=2,z=2
, the cube at x=0,y=2,z=3
, and so on.
+
+During a cycle, all cubes simultaneously change their state according to the following rules:
+
+
+ - If a cube is active and exactly 2
or 3
of its neighbors are also active, the cube remains active. Otherwise, the cube becomes inactive.
+ - If a cube is inactive but exactly 3
of its neighbors are active, the cube becomes active. Otherwise, the cube remains inactive.
+
+The engineers responsible for this experimental energy source would like you to simulate the pocket dimension and determine what the configuration of cubes should be at the end of the six-cycle boot process.
+
+For example, consider the following initial state:
+
+
+.#.
+..#
+###
+
+
+
+Even though the pocket dimension is 3-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1 region of the 3-dimensional space.)
+
+Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z
coordinate (and the frame of view follows the active cells in each cycle):
+
+
+Before any cycles:
+
+z=0
+.#.
+..#
+###
+
+
+After 1 cycle:
+
+z=-1
+#..
+..#
+.#.
+
+z=0
+#.#
+.##
+.#.
+
+z=1
+#..
+..#
+.#.
+
+
+After 2 cycles:
+
+z=-2
+.....
+.....
+..#..
+.....
+.....
+
+z=-1
+..#..
+.#..#
+....#
+.#...
+.....
+
+z=0
+##...
+##...
+#....
+....#
+.###.
+
+z=1
+..#..
+.#..#
+....#
+.#...
+.....
+
+z=2
+.....
+.....
+..#..
+.....
+.....
+
+
+After 3 cycles:
+
+z=-2
+.......
+.......
+..##...
+..###..
+.......
+.......
+.......
+
+z=-1
+..#....
+...#...
+#......
+.....##
+.#...#.
+..#.#..
+...#...
+
+z=0
+...#...
+.......
+#......
+.......
+.....##
+.##.#..
+...#...
+
+z=1
+..#....
+...#...
+#......
+.....##
+.#...#.
+..#.#..
+...#...
+
+z=2
+.......
+.......
+..##...
+..###..
+.......
+.......
+.......
+
+
+
+After the full six-cycle boot process completes, 112
cubes are left in the active state.
+
+Starting with your given initial configuration, simulate six cycles. How many cubes are left in the active state after the sixth cycle?
+
+
+## --- Part Two ---
+For some reason, your simulated results don't match what the experimental energy source engineers expected. Apparently, the pocket dimension actually has four spatial dimensions, not three.
+
+The pocket dimension contains an infinite 4-dimensional grid. At every integer 4-dimensional coordinate (x,y,z,w
), there exists a single cube (really, a hypercube) which is still either active or inactive.
+
+Each cube only ever considers its neighbors: any of the 80 other cubes where any of their coordinates differ by at most 1
. For example, given the cube at x=1,y=2,z=3,w=4
, its neighbors include the cube at x=2,y=2,z=3,w=3
, the cube at x=0,y=2,z=3,w=4
, and so on.
+
+The initial state of the pocket dimension still consists of a small flat region of cubes. Furthermore, the same rules for cycle updating still apply: during each cycle, consider the number of active neighbors of each cube.
+
+For example, consider the same initial state as in the example above. Even though the pocket dimension is 4-dimensional, this initial state represents a small 2-dimensional slice of it. (In particular, this initial state defines a 3x3x1x1 region of the 4-dimensional space.)
+
+Simulating a few cycles from this initial state produces the following configurations, where the result of each cycle is shown layer-by-layer at each given z
and w
coordinate:
+
+
+Before any cycles:
+
+z=0, w=0
+.#.
+..#
+###
+
+
+After 1 cycle:
+
+z=-1, w=-1
+#..
+..#
+.#.
+
+z=0, w=-1
+#..
+..#
+.#.
+
+z=1, w=-1
+#..
+..#
+.#.
+
+z=-1, w=0
+#..
+..#
+.#.
+
+z=0, w=0
+#.#
+.##
+.#.
+
+z=1, w=0
+#..
+..#
+.#.
+
+z=-1, w=1
+#..
+..#
+.#.
+
+z=0, w=1
+#..
+..#
+.#.
+
+z=1, w=1
+#..
+..#
+.#.
+
+
+After 2 cycles:
+
+z=-2, w=-2
+.....
+.....
+..#..
+.....
+.....
+
+z=-1, w=-2
+.....
+.....
+.....
+.....
+.....
+
+z=0, w=-2
+###..
+##.##
+#...#
+.#..#
+.###.
+
+z=1, w=-2
+.....
+.....
+.....
+.....
+.....
+
+z=2, w=-2
+.....
+.....
+..#..
+.....
+.....
+
+z=-2, w=-1
+.....
+.....
+.....
+.....
+.....
+
+z=-1, w=-1
+.....
+.....
+.....
+.....
+.....
+
+z=0, w=-1
+.....
+.....
+.....
+.....
+.....
+
+z=1, w=-1
+.....
+.....
+.....
+.....
+.....
+
+z=2, w=-1
+.....
+.....
+.....
+.....
+.....
+
+z=-2, w=0
+###..
+##.##
+#...#
+.#..#
+.###.
+
+z=-1, w=0
+.....
+.....
+.....
+.....
+.....
+
+z=0, w=0
+.....
+.....
+.....
+.....
+.....
+
+z=1, w=0
+.....
+.....
+.....
+.....
+.....
+
+z=2, w=0
+###..
+##.##
+#...#
+.#..#
+.###.
+
+z=-2, w=1
+.....
+.....
+.....
+.....
+.....
+
+z=-1, w=1
+.....
+.....
+.....
+.....
+.....
+
+z=0, w=1
+.....
+.....
+.....
+.....
+.....
+
+z=1, w=1
+.....
+.....
+.....
+.....
+.....
+
+z=2, w=1
+.....
+.....
+.....
+.....
+.....
+
+z=-2, w=2
+.....
+.....
+..#..
+.....
+.....
+
+z=-1, w=2
+.....
+.....
+.....
+.....
+.....
+
+z=0, w=2
+###..
+##.##
+#...#
+.#..#
+.###.
+
+z=1, w=2
+.....
+.....
+.....
+.....
+.....
+
+z=2, w=2
+.....
+.....
+..#..
+.....
+.....
+
+
+
+After the full six-cycle boot process completes, 848
cubes are left in the active state.
+
+Starting with your given initial configuration, simulate six cycles in a 4-dimensional space. How many cubes are left in the active state after the sixth cycle?
+
+
diff --git a/2020/Day17/input.in b/2020/Day17/input.in
index 0ffd26405..d8b9ae9ff 100644
Binary files a/2020/Day17/input.in and b/2020/Day17/input.in differ
diff --git a/2020/Day18/README.md b/2020/Day18/README.md
index f6419792d..93c1fcc4e 100644
--- a/2020/Day18/README.md
+++ b/2020/Day18/README.md
@@ -1,6 +1,74 @@
+original source: [https://adventofcode.com/2020/day/18](https://adventofcode.com/2020/day/18)
## --- Day 18: Operation Order ---
As you look out the window and notice a heavily-forested continent slowly appear over the horizon, you are interrupted by the child sitting next to you. They're curious if you could help them with their math homework.
Unfortunately, it seems like this "math" [follows different rules](https://www.youtube.com/watch?v=3QtRK7Y2pPU&t=15) than you remember.
-Read the [full puzzle](https://adventofcode.com/2020/day/18).
\ No newline at end of file
+The homework (your puzzle input) consists of a series of expressions that consist of addition (+
), multiplication (*
), and parentheses ((...)
). Just like normal math, parentheses indicate that the expression inside must be evaluated before it can be used by the surrounding expression. Addition still finds the sum of the numbers on both sides of the operator, and multiplication still finds the product.
+
+However, the rules of operator precedence have changed. Rather than evaluating multiplication before addition, the operators have the same precedence, and are evaluated left-to-right regardless of the order in which they appear.
+
+For example, the steps to evaluate the expression 1 + 2 * 3 + 4 * 5 + 6
are as follows:
+
+
+1 + 2 * 3 + 4 * 5 + 6
+ 3 * 3 + 4 * 5 + 6
+ 9 + 4 * 5 + 6
+ 13 * 5 + 6
+ 65 + 6
+ 71
+
+
+
+Parentheses can override this order; for example, here is what happens if parentheses are added to form 1 + (2 * 3) + (4 * (5 + 6))
:
+
+
+1 + (2 * 3) + (4 * (5 + 6))
+1 + 6 + (4 * (5 + 6))
+ 7 + (4 * (5 + 6))
+ 7 + (4 * 11 )
+ 7 + 44
+ 51
+
+
+
+Here are a few more examples:
+
+
+ - 2 * 3 + (4 * 5)
becomes 26
.
+ - 5 + (8 * 3 + 9 + 3 * 4 * 3)
becomes 437
.
+ - 5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))
becomes 12240
.
+ - ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2
becomes 13632
.
+
+Before you can help with the homework, you need to understand it yourself. Evaluate the expression on each line of the homework; what is the sum of the resulting values?
+
+
+## --- Part Two ---
+You manage to answer the child's questions and they finish part 1 of their homework, but get stuck when they reach the next section: advanced math.
+
+Now, addition and multiplication have different precedence levels, but they're not the ones you're familiar with. Instead, addition is evaluated before multiplication.
+
+For example, the steps to evaluate the expression 1 + 2 * 3 + 4 * 5 + 6
are now as follows:
+
+
+1 + 2 * 3 + 4 * 5 + 6
+ 3 * 3 + 4 * 5 + 6
+ 3 * 7 * 5 + 6
+ 3 * 7 * 11
+ 21 * 11
+ 231
+
+
+
+Here are the other examples from above:
+
+
+ - 1 + (2 * 3) + (4 * (5 + 6))
still becomes 51
.
+ - 2 * 3 + (4 * 5)
becomes 46
.
+ - 5 + (8 * 3 + 9 + 3 * 4 * 3)
becomes 1445
.
+ - 5 * 9 * (7 * 3 * 3 + 9 * 3 + (8 + 6 * 4))
becomes 669060
.
+ - ((2 + 4 * 9) * (6 + 9 * 8 + 6) + 6) + 2 + 4 * 2
becomes 23340
.
+
+What do you get if you add up the results of evaluating the homework problems using these new rules?
+
+
diff --git a/2020/Day18/input.in b/2020/Day18/input.in
index 13bc4762b..3b04a70a4 100644
Binary files a/2020/Day18/input.in and b/2020/Day18/input.in differ
diff --git a/2020/Day19/README.md b/2020/Day19/README.md
index 84fc34e56..107943e97 100644
--- a/2020/Day19/README.md
+++ b/2020/Day19/README.md
@@ -1,6 +1,154 @@
+original source: [https://adventofcode.com/2020/day/19](https://adventofcode.com/2020/day/19)
## --- Day 19: Monster Messages ---
You land in an airport surrounded by dense forest. As you walk to your high-speed train, the Elves at the Mythical Information Bureau contact you again. They think their satellite has collected an image of a sea monster! Unfortunately, the connection to the satellite is having problems, and many of the messages sent back from the satellite have been corrupted.
They sent you a list of the rules valid messages should obey and a list of received messages they've collected so far (your puzzle input).
-Read the [full puzzle](https://adventofcode.com/2020/day/19).
\ No newline at end of file
+The rules for valid messages (the top part of your puzzle input) are numbered and build upon each other. For example:
+
+
+0: 1 2
+1: "a"
+2: 1 3 | 3 1
+3: "b"
+
+
+
+Some rules, like 3: "b"
, simply match a single character (in this case, b
).
+
+The remaining rules list the sub-rules that must be followed; for example, the rule 0: 1 2
means that to match rule 0
, the text being checked must match rule 1
, and the text after the part that matched rule 1
must then match rule 2
.
+
+Some of the rules have multiple lists of sub-rules separated by a pipe (|
). This means that at least one list of sub-rules must match. (The ones that match might be different each time the rule is encountered.) For example, the rule 2: 1 3 | 3 1
means that to match rule 2
, the text being checked must match rule 1
followed by rule 3
or it must match rule 3
followed by rule 1
.
+
+Fortunately, there are no loops in the rules, so the list of possible matches will be finite. Since rule 1
matches a
and rule 3
matches b
, rule 2
matches either ab
or ba
. Therefore, rule 0
matches aab
or aba
.
+
+Here's a more interesting example:
+
+
+0: 4 1 5
+1: 2 3 | 3 2
+2: 4 4 | 5 5
+3: 4 5 | 5 4
+4: "a"
+5: "b"
+
+
+
+Here, because rule 4
matches a
and rule 5
matches b
, rule 2
matches two letters that are the same (aa
or bb
), and rule 3
matches two letters that are different (ab
or ba
).
+
+Since rule 1
matches rules 2
and 3
once each in either order, it must match two pairs of letters, one pair with matching letters and one pair with different letters. This leaves eight possibilities: aaab
, aaba
, bbab
, bbba
, abaa
, abbb
, baaa
, or babb
.
+
+Rule 0
, therefore, matches a
(rule 4
), then any of the eight options from rule 1
, then b
(rule 5
): aaaabb
, aaabab
, abbabb
, abbbab
, aabaab
, aabbbb
, abaaab
, or ababbb
.
+
+The received messages (the bottom part of your puzzle input) need to be checked against the rules so you can determine which are valid and which are corrupted. Including the rules and the messages together, this might look like:
+
+
+0: 4 1 5
+1: 2 3 | 3 2
+2: 4 4 | 5 5
+3: 4 5 | 5 4
+4: "a"
+5: "b"
+
+ababbb
+bababa
+abbbab
+aaabbb
+aaaabbb
+
+
+
+Your goal is to determine the number of messages that completely match rule 0
. In the above example, ababbb
and abbbab
match, but bababa
, aaabbb
, and aaaabbb
do not, producing the answer 2
. The whole message must match all of rule 0
; there can't be extra unmatched characters in the message. (For example, aaaabbb
might appear to match rule 0
above, but it has an extra unmatched b
on the end.)
+
+How many messages completely match rule 0
?
+
+
+## --- Part Two ---
+As you look over the list of messages, you realize your matching rules aren't quite right. To fix them, completely replace rules 8: 42
and 11: 42 31
with the following:
+
+
+8: 42 | 42 8
+11: 42 31 | 42 11 31
+
+
+
+This small change has a big impact: now, the rules do contain loops, and the list of messages they could hypothetically match is infinite. You'll need to determine how these changes affect which messages are valid.
+
+Fortunately, many of the rules are unaffected by this change; it might help to start by looking at which rules always match the same set of values and how those rules (especially rules 42
and 31
) are used by the new versions of rules 8
and 11
.
+
+(Remember, you only need to handle the rules you have; building a solution that could handle any hypothetical combination of rules would be [significantly more difficult](https://en.wikipedia.org/wiki/Formal_grammar).)
+
+For example:
+
+
+42: 9 14 | 10 1
+9: 14 27 | 1 26
+10: 23 14 | 28 1
+1: "a"
+11: 42 31
+5: 1 14 | 15 1
+19: 14 1 | 14 14
+12: 24 14 | 19 1
+16: 15 1 | 14 14
+31: 14 17 | 1 13
+6: 14 14 | 1 14
+2: 1 24 | 14 4
+0: 8 11
+13: 14 3 | 1 12
+15: 1 | 14
+17: 14 2 | 1 7
+23: 25 1 | 22 14
+28: 16 1
+4: 1 1
+20: 14 14 | 1 15
+3: 5 14 | 16 1
+27: 1 6 | 14 18
+14: "b"
+21: 14 1 | 1 14
+25: 1 1 | 1 14
+22: 14 14
+8: 42
+26: 14 22 | 1 20
+18: 15 15
+7: 14 5 | 1 21
+24: 14 1
+
+abbbbbabbbaaaababbaabbbbabababbbabbbbbbabaaaa
+bbabbbbaabaabba
+babbbbaabbbbbabbbbbbaabaaabaaa
+aaabbbbbbaaaabaababaabababbabaaabbababababaaa
+bbbbbbbaaaabbbbaaabbabaaa
+bbbababbbbaaaaaaaabbababaaababaabab
+ababaaaaaabaaab
+ababaaaaabbbaba
+baabbaaaabbaaaababbaababb
+abbbbabbbbaaaababbbbbbaaaababb
+aaaaabbaabaaaaababaa
+aaaabbaaaabbaaa
+aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
+babaaabbbaaabaababbaabababaaab
+aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
+
+
+
+Without updating rules 8
and 11
, these rules only match three messages: bbabbbbaabaabba
, ababaaaaaabaaab
, and ababaaaaabbbaba
.
+
+However, after updating rules 8
and 11
, a total of 12
messages match:
+
+
+ - bbabbbbaabaabba
+ - babbbbaabbbbbabbbbbbaabaaabaaa
+ - aaabbbbbbaaaabaababaabababbabaaabbababababaaa
+ - bbbbbbbaaaabbbbaaabbabaaa
+ - bbbababbbbaaaaaaaabbababaaababaabab
+ - ababaaaaaabaaab
+ - ababaaaaabbbaba
+ - baabbaaaabbaaaababbaababb
+ - abbbbabbbbaaaababbbbbbaaaababb
+ - aaaaabbaabaaaaababaa
+ - aaaabbaabbaaaaaaabbbabbbaaabbaabaaa
+ - aabbbbbaabbbaaaaaabbbbbababaaaaabbaaabba
+
+After updating rules 8
and 11
, how many messages completely match rule 0
?
+
+
diff --git a/2020/Day19/input.in b/2020/Day19/input.in
index ee4e83cb5..c41dfe27c 100644
Binary files a/2020/Day19/input.in and b/2020/Day19/input.in differ
diff --git a/2020/Day20/README.md b/2020/Day20/README.md
index 61638dbef..cc61a4c1f 100644
--- a/2020/Day20/README.md
+++ b/2020/Day20/README.md
@@ -1,6 +1,288 @@
+original source: [https://adventofcode.com/2020/day/20](https://adventofcode.com/2020/day/20)
## --- Day 20: Jurassic Jigsaw ---
The high-speed train leaves the forest and quickly carries you south. You can even see a desert in the distance! Since you have some spare time, you might as well see if there was anything interesting in the image the Mythical Information Bureau satellite captured.
After decoding the satellite messages, you discover that the data actually contains many small images created by the satellite's camera array. The camera array consists of many cameras; rather than produce a single square image, they produce many smaller square image tiles that need to be reassembled back into a single image.
-Read the [full puzzle](https://adventofcode.com/2020/day/20).
\ No newline at end of file
+Each camera in the camera array returns a single monochrome image tile with a random unique ID number. The tiles (your puzzle input) arrived in a random order.
+
+Worse yet, the camera array appears to be malfunctioning: each image tile has been rotated and flipped to a random orientation. Your first task is to reassemble the original image by orienting the tiles so they fit together.
+
+To show how the tiles should be reassembled, each tile's image data includes a border that should line up exactly with its adjacent tiles. All tiles have this border, and the border lines up exactly when the tiles are both oriented correctly. Tiles at the edge of the image also have this border, but the outermost edges won't line up with any other tiles.
+
+For example, suppose you have the following nine tiles:
+
+
+Tile 2311:
+..##.#..#.
+##..#.....
+#...##..#.
+####.#...#
+##.##.###.
+##...#.###
+.#.#.#..##
+..#....#..
+###...#.#.
+..###..###
+
+Tile 1951:
+#.##...##.
+#.####...#
+.....#..##
+#...######
+.##.#....#
+.###.#####
+###.##.##.
+.###....#.
+..#.#..#.#
+#...##.#..
+
+Tile 1171:
+####...##.
+#..##.#..#
+##.#..#.#.
+.###.####.
+..###.####
+.##....##.
+.#...####.
+#.##.####.
+####..#...
+.....##...
+
+Tile 1427:
+###.##.#..
+.#..#.##..
+.#.##.#..#
+#.#.#.##.#
+....#...##
+...##..##.
+...#.#####
+.#.####.#.
+..#..###.#
+..##.#..#.
+
+Tile 1489:
+##.#.#....
+..##...#..
+.##..##...
+..#...#...
+#####...#.
+#..#.#.#.#
+...#.#.#..
+##.#...##.
+..##.##.##
+###.##.#..
+
+Tile 2473:
+#....####.
+#..#.##...
+#.##..#...
+######.#.#
+.#...#.#.#
+.#########
+.###.#..#.
+########.#
+##...##.#.
+..###.#.#.
+
+Tile 2971:
+..#.#....#
+#...###...
+#.#.###...
+##.##..#..
+.#####..##
+.#..####.#
+#..#.#..#.
+..####.###
+..#.#.###.
+...#.#.#.#
+
+Tile 2729:
+...#.#.#.#
+####.#....
+..#.#.....
+....#..#.#
+.##..##.#.
+.#.####...
+####.#.#..
+##.####...
+##..#.##..
+#.##...##.
+
+Tile 3079:
+#.#.#####.
+.#..######
+..#.......
+######....
+####.#..#.
+.#...#.##.
+#.#####.##
+..#.###...
+..#.......
+..#.###...
+
+
+
+By rotating, flipping, and rearranging them, you can find a square arrangement that causes all adjacent borders to line up:
+
+
+#...##.#.. ..###..### #.#.#####.
+..#.#..#.# ###...#.#. .#..######
+.###....#. ..#....#.. ..#.......
+###.##.##. .#.#.#..## ######....
+.###.##### ##...#.### ####.#..#.
+.##.#....# ##.##.###. .#...#.##.
+#...###### ####.#...# #.#####.##
+.....#..## #...##..#. ..#.###...
+#.####...# ##..#..... ..#.......
+#.##...##. ..##.#..#. ..#.###...
+
+#.##...##. ..##.#..#. ..#.###...
+##..#.##.. ..#..###.# ##.##....#
+##.####... .#.####.#. ..#.###..#
+####.#.#.. ...#.##### ###.#..###
+.#.####... ...##..##. .######.##
+.##..##.#. ....#...## #.#.#.#...
+....#..#.# #.#.#.##.# #.###.###.
+..#.#..... .#.##.#..# #.###.##..
+####.#.... .#..#.##.. .######...
+...#.#.#.# ###.##.#.. .##...####
+
+...#.#.#.# ###.##.#.. .##...####
+..#.#.###. ..##.##.## #..#.##..#
+..####.### ##.#...##. .#.#..#.##
+#..#.#..#. ...#.#.#.. .####.###.
+.#..####.# #..#.#.#.# ####.###..
+.#####..## #####...#. .##....##.
+##.##..#.. ..#...#... .####...#.
+#.#.###... .##..##... .####.##.#
+#...###... ..##...#.. ...#..####
+..#.#....# ##.#.#.... ...##.....
+
+
+
+For reference, the IDs of the above tiles are:
+
+
+1951 2311 3079
+2729 1427 2473
+2971 1489 1171
+
+
+
+To check that you've assembled the image correctly, multiply the IDs of the four corner tiles together. If you do this with the assembled tiles from the example above, you get 1951 * 3079 * 2971 * 1171
= 20899048083289
.
+
+Assemble the tiles into an image. What do you get if you multiply together the IDs of the four corner tiles?
+
+
+## --- Part Two ---
+Now, you're ready to check the image for sea monsters.
+
+The borders of each tile are not part of the actual image; start by removing them.
+
+In the example above, the tiles become:
+
+
+.#.#..#. ##...#.# #..#####
+###....# .#....#. .#......
+##.##.## #.#.#..# #####...
+###.#### #...#.## ###.#..#
+##.#.... #.##.### #...#.##
+...##### ###.#... .#####.#
+....#..# ...##..# .#.###..
+.####... #..#.... .#......
+
+#..#.##. .#..###. #.##....
+#.####.. #.####.# .#.###..
+###.#.#. ..#.#### ##.#..##
+#.####.. ..##..## ######.#
+##..##.# ...#...# .#.#.#..
+...#..#. .#.#.##. .###.###
+.#.#.... #.##.#.. .###.##.
+###.#... #..#.##. ######..
+
+.#.#.### .##.##.# ..#.##..
+.####.## #.#...## #.#..#.#
+..#.#..# ..#.#.#. ####.###
+#..####. ..#.#.#. ###.###.
+#####..# ####...# ##....##
+#.##..#. .#...#.. ####...#
+.#.###.. ##..##.. ####.##.
+...###.. .##...#. ..#..###
+
+
+
+Remove the gaps to form the actual image:
+
+
+.#.#..#.##...#.##..#####
+###....#.#....#..#......
+##.##.###.#.#..######...
+###.#####...#.#####.#..#
+##.#....#.##.####...#.##
+...########.#....#####.#
+....#..#...##..#.#.###..
+.####...#..#.....#......
+#..#.##..#..###.#.##....
+#.####..#.####.#.#.###..
+###.#.#...#.######.#..##
+#.####....##..########.#
+##..##.#...#...#.#.#.#..
+...#..#..#.#.##..###.###
+.#.#....#.##.#...###.##.
+###.#...#..#.##.######..
+.#.#.###.##.##.#..#.##..
+.####.###.#...###.#..#.#
+..#.#..#..#.#.#.####.###
+#..####...#.#.#.###.###.
+#####..#####...###....##
+#.##..#..#...#..####...#
+.#.###..##..##..####.##.
+...###...##...#...#..###
+
+
+
+Now, you're ready to search for sea monsters! Because your image is monochrome, a sea monster will look like this:
+
+
+ #
+# ## ## ###
+ # # # # # #
+
+
+
+When looking for this pattern in the image, the spaces can be anything; only the #
need to match. Also, you might need to rotate or flip your image before it's oriented correctly to find sea monsters. In the above image, after flipping and rotating it to the appropriate orientation, there are two sea monsters (marked with O
):
+
+
+.####...#####..#...###..
+#####..#..#.#.####..#.#.
+.#.#...#.###...#.##.O#..
+#.O.##.OO#.#.OO.##.OOO##
+..#O.#O#.O##O..O.#O##.##
+...#.#..##.##...#..#..##
+#.##.#..#.#..#..##.#.#..
+.###.##.....#...###.#...
+#.####.#.#....##.#..#.#.
+##...#..#....#..#...####
+..#.##...###..#.#####..#
+....#.##.#.#####....#...
+..##.##.###.....#.##..#.
+#...#...###..####....##.
+.#.##...#.##.#.#.###...#
+#.###.#..####...##..#...
+#.###...#.##...#.##O###.
+.O##.#OO.###OO##..OOO##.
+..O#.O..O..O.#O##O##.###
+#.#..##.########..#..##.
+#.#####..#.#...##..#....
+#....##..#.#########..##
+#...#.....#..##...###.##
+#..###....##.#...##.##.#
+
+
+
+Determine how rough the waters are in the sea monsters' habitat by counting the number of #
that are not part of a sea monster. In the above example, the habitat's water roughness is 273
.
+
+How many #
are not part of a sea monster?
+
+
diff --git a/2020/Day20/input.in b/2020/Day20/input.in
index 97e975f2f..6b475f8bd 100644
Binary files a/2020/Day20/input.in and b/2020/Day20/input.in differ
diff --git a/2020/Day21/README.md b/2020/Day21/README.md
index 5eda168ce..a8fac4c7d 100644
--- a/2020/Day21/README.md
+++ b/2020/Day21/README.md
@@ -1,6 +1,42 @@
+original source: [https://adventofcode.com/2020/day/21](https://adventofcode.com/2020/day/21)
## --- Day 21: Allergen Assessment ---
You reach the train's last stop and the closest you can get to your vacation island without getting wet. There aren't even any boats here, but nothing can stop you now: you build a raft. You just need a few days' worth of food for your journey.
You don't speak the local language, so you can't read any ingredients lists. However, sometimes, allergens are listed in a language you do understand. You should be able to use this information to determine which ingredient contains which allergen and work out which foods are safe to take with you on your trip.
-Read the [full puzzle](https://adventofcode.com/2020/day/21).
\ No newline at end of file
+You start by compiling a list of foods (your puzzle input), one food per line. Each line includes that food's ingredients list followed by some or all of the allergens the food contains.
+
+Each allergen is found in exactly one ingredient. Each ingredient contains zero or one allergen. Allergens aren't always marked; when they're listed (as in (contains nuts, shellfish)
after an ingredients list), the ingredient that contains each listed allergen will be somewhere in the corresponding ingredients list. However, even if an allergen isn't listed, the ingredient that contains that allergen could still be present: maybe they forgot to label it, or maybe it was labeled in a language you don't know.
+
+For example, consider the following list of foods:
+
+
+mxmxvkd kfcds sqjhc nhms (contains dairy, fish)
+trh fvjkl sbzzf mxmxvkd (contains dairy)
+sqjhc fvjkl (contains soy)
+sqjhc mxmxvkd sbzzf (contains fish)
+
+
+
+The first food in the list has four ingredients (written in a language you don't understand): mxmxvkd
, kfcds
, sqjhc
, and nhms
. While the food might contain other allergens, a few allergens the food definitely contains are listed afterward: dairy
and fish
.
+
+The first step is to determine which ingredients can't possibly contain any of the allergens in any food in your list. In the above example, none of the ingredients kfcds
, nhms
, sbzzf
, or trh
can contain an allergen. Counting the number of times any of these ingredients appear in any ingredients list produces 5
: they all appear once each except sbzzf
, which appears twice.
+
+Determine which ingredients cannot possibly contain any of the allergens in your list. How many times do any of those ingredients appear?
+
+
+## --- Part Two ---
+Now that you've isolated the inert ingredients, you should have enough information to figure out which ingredient contains which allergen.
+
+In the above example:
+
+
+ - mxmxvkd
contains dairy
.
+ - sqjhc
contains fish
.
+ - fvjkl
contains soy
.
+
+Arrange the ingredients alphabetically by their allergen and separate them by commas to produce your canonical dangerous ingredient list. (There should not be any spaces in your canonical dangerous ingredient list.) In the above example, this would be mxmxvkd,sqjhc,fvjkl
.
+
+Time to stock your raft with supplies. What is your canonical dangerous ingredient list?
+
+
diff --git a/2020/Day21/input.in b/2020/Day21/input.in
index 069732cb8..9301dc45a 100644
Binary files a/2020/Day21/input.in and b/2020/Day21/input.in differ
diff --git a/2020/Day22/README.md b/2020/Day22/README.md
index 07b3f0bf0..0744a25aa 100644
--- a/2020/Day22/README.md
+++ b/2020/Day22/README.md
@@ -1,6 +1,395 @@
+original source: [https://adventofcode.com/2020/day/22](https://adventofcode.com/2020/day/22)
## --- Day 22: Crab Combat ---
It only takes a few hours of sailing the ocean on a raft for boredom to sink in. Fortunately, you brought a small deck of [space cards](/2019/day/22)! You'd like to play a game of Combat, and there's even an opponent available: a small crab that climbed aboard your raft before you left.
Fortunately, it doesn't take long to teach the crab the rules.
-Read the [full puzzle](https://adventofcode.com/2020/day/22).
\ No newline at end of file
+Before the game starts, split the cards so each player has their own deck (your puzzle input). Then, the game consists of a series of rounds: both players draw their top card, and the player with the higher-valued card wins the round. The winner keeps both cards, placing them on the bottom of their own deck so that the winner's card is above the other card. If this causes a player to have all of the cards, they win, and the game ends.
+
+For example, consider the following starting decks:
+
+
+Player 1:
+9
+2
+6
+3
+1
+
+Player 2:
+5
+8
+4
+7
+10
+
+
+
+This arrangement means that player 1's deck contains 5 cards, with 9
on top and 1
on the bottom; player 2's deck also contains 5 cards, with 5
on top and 10
on the bottom.
+
+The first round begins with both players drawing the top card of their decks: 9
and 5
. Player 1 has the higher card, so both cards move to the bottom of player 1's deck such that 9
is above 5
. In total, it takes 29 rounds before a player has all of the cards:
+
+
+-- Round 1 --
+Player 1's deck: 9, 2, 6, 3, 1
+Player 2's deck: 5, 8, 4, 7, 10
+Player 1 plays: 9
+Player 2 plays: 5
+Player 1 wins the round!
+
+-- Round 2 --
+Player 1's deck: 2, 6, 3, 1, 9, 5
+Player 2's deck: 8, 4, 7, 10
+Player 1 plays: 2
+Player 2 plays: 8
+Player 2 wins the round!
+
+-- Round 3 --
+Player 1's deck: 6, 3, 1, 9, 5
+Player 2's deck: 4, 7, 10, 8, 2
+Player 1 plays: 6
+Player 2 plays: 4
+Player 1 wins the round!
+
+-- Round 4 --
+Player 1's deck: 3, 1, 9, 5, 6, 4
+Player 2's deck: 7, 10, 8, 2
+Player 1 plays: 3
+Player 2 plays: 7
+Player 2 wins the round!
+
+-- Round 5 --
+Player 1's deck: 1, 9, 5, 6, 4
+Player 2's deck: 10, 8, 2, 7, 3
+Player 1 plays: 1
+Player 2 plays: 10
+Player 2 wins the round!
+
+...several more rounds pass...
+
+-- Round 27 --
+Player 1's deck: 5, 4, 1
+Player 2's deck: 8, 9, 7, 3, 2, 10, 6
+Player 1 plays: 5
+Player 2 plays: 8
+Player 2 wins the round!
+
+-- Round 28 --
+Player 1's deck: 4, 1
+Player 2's deck: 9, 7, 3, 2, 10, 6, 8, 5
+Player 1 plays: 4
+Player 2 plays: 9
+Player 2 wins the round!
+
+-- Round 29 --
+Player 1's deck: 1
+Player 2's deck: 7, 3, 2, 10, 6, 8, 5, 9, 4
+Player 1 plays: 1
+Player 2 plays: 7
+Player 2 wins the round!
+
+
+== Post-game results ==
+Player 1's deck:
+Player 2's deck: 3, 2, 10, 6, 8, 5, 9, 4, 7, 1
+
+
+
+Once the game ends, you can calculate the winning player's score. The bottom card in their deck is worth the value of the card multiplied by 1, the second-from-the-bottom card is worth the value of the card multiplied by 2, and so on. With 10 cards, the top card is worth the value on the card multiplied by 10. In this example, the winning player's score is:
+
+
+ 3 * 10
++ 2 * 9
++ 10 * 8
++ 6 * 7
++ 8 * 6
++ 5 * 5
++ 9 * 4
++ 4 * 3
++ 7 * 2
++ 1 * 1
+= 306
+
+
+
+So, once the game ends, the winning player's score is 306
.
+
+Play the small crab in a game of Combat using the two decks you just dealt. What is the winning player's score?
+
+
+## --- Part Two ---
+You lost to the small crab! Fortunately, crabs aren't very good at recursion. To defend your honor as a Raft Captain, you challenge the small crab to a game of Recursive Combat.
+
+Recursive Combat still starts by splitting the cards into two decks (you offer to play with the same starting decks as before - it's only fair). Then, the game consists of a series of rounds with a few changes:
+
+
+ - Before either player deals a card, if there was a previous round in this game that had exactly the same cards in the same order in the same players' decks, the game instantly ends in a win for player 1. Previous rounds from other games are not considered. (This prevents infinite games of Recursive Combat, which everyone agrees is a bad idea.)
+ - Otherwise, this round's cards must be in a new configuration; the players begin the round by each drawing the top card of their deck as normal.
+ - If both players have at least as many cards remaining in their deck as the value of the card they just drew, the winner of the round is determined by playing a new game of Recursive Combat (see below).
+ - Otherwise, at least one player must not have enough cards left in their deck to recurse; the winner of the round is the player with the higher-value card.
+
+As in regular Combat, the winner of the round (even if they won the round by winning a sub-game) takes the two cards dealt at the beginning of the round and places them on the bottom of their own deck (again so that the winner's card is above the other card). Note that the winner's card might be the lower-valued of the two cards if they won the round due to winning a sub-game. If collecting cards by winning the round causes a player to have all of the cards, they win, and the game ends.
+
+Here is an example of a small game that would loop forever without the infinite game prevention rule:
+
+
+Player 1:
+43
+19
+
+Player 2:
+2
+29
+14
+
+
+
+During a round of Recursive Combat, if both players have at least as many cards in their own decks as the number on the card they just dealt, the winner of the round is determined by recursing into a sub-game of Recursive Combat. (For example, if player 1 draws the 3
card, and player 2 draws the 7
card, this would occur if player 1 has at least 3 cards left and player 2 has at least 7 cards left, not counting the 3
and 7
cards that were drawn.)
+
+To play a sub-game of Recursive Combat, each player creates a new deck by making a copy of the next cards in their deck (the quantity of cards copied is equal to the number on the card they drew to trigger the sub-game). During this sub-game, the game that triggered it is on hold and completely unaffected; no cards are removed from players' decks to form the sub-game. (For example, if player 1 drew the 3
card, their deck in the sub-game would be copies of the next three cards in their deck.)
+
+Here is a complete example of gameplay, where Game 1
is the primary game of Recursive Combat:
+
+
+=== Game 1 ===
+
+-- Round 1 (Game 1) --
+Player 1's deck: 9, 2, 6, 3, 1
+Player 2's deck: 5, 8, 4, 7, 10
+Player 1 plays: 9
+Player 2 plays: 5
+Player 1 wins round 1 of game 1!
+
+-- Round 2 (Game 1) --
+Player 1's deck: 2, 6, 3, 1, 9, 5
+Player 2's deck: 8, 4, 7, 10
+Player 1 plays: 2
+Player 2 plays: 8
+Player 2 wins round 2 of game 1!
+
+-- Round 3 (Game 1) --
+Player 1's deck: 6, 3, 1, 9, 5
+Player 2's deck: 4, 7, 10, 8, 2
+Player 1 plays: 6
+Player 2 plays: 4
+Player 1 wins round 3 of game 1!
+
+-- Round 4 (Game 1) --
+Player 1's deck: 3, 1, 9, 5, 6, 4
+Player 2's deck: 7, 10, 8, 2
+Player 1 plays: 3
+Player 2 plays: 7
+Player 2 wins round 4 of game 1!
+
+-- Round 5 (Game 1) --
+Player 1's deck: 1, 9, 5, 6, 4
+Player 2's deck: 10, 8, 2, 7, 3
+Player 1 plays: 1
+Player 2 plays: 10
+Player 2 wins round 5 of game 1!
+
+-- Round 6 (Game 1) --
+Player 1's deck: 9, 5, 6, 4
+Player 2's deck: 8, 2, 7, 3, 10, 1
+Player 1 plays: 9
+Player 2 plays: 8
+Player 1 wins round 6 of game 1!
+
+-- Round 7 (Game 1) --
+Player 1's deck: 5, 6, 4, 9, 8
+Player 2's deck: 2, 7, 3, 10, 1
+Player 1 plays: 5
+Player 2 plays: 2
+Player 1 wins round 7 of game 1!
+
+-- Round 8 (Game 1) --
+Player 1's deck: 6, 4, 9, 8, 5, 2
+Player 2's deck: 7, 3, 10, 1
+Player 1 plays: 6
+Player 2 plays: 7
+Player 2 wins round 8 of game 1!
+
+-- Round 9 (Game 1) --
+Player 1's deck: 4, 9, 8, 5, 2
+Player 2's deck: 3, 10, 1, 7, 6
+Player 1 plays: 4
+Player 2 plays: 3
+Playing a sub-game to determine the winner...
+
+=== Game 2 ===
+
+-- Round 1 (Game 2) --
+Player 1's deck: 9, 8, 5, 2
+Player 2's deck: 10, 1, 7
+Player 1 plays: 9
+Player 2 plays: 10
+Player 2 wins round 1 of game 2!
+
+-- Round 2 (Game 2) --
+Player 1's deck: 8, 5, 2
+Player 2's deck: 1, 7, 10, 9
+Player 1 plays: 8
+Player 2 plays: 1
+Player 1 wins round 2 of game 2!
+
+-- Round 3 (Game 2) --
+Player 1's deck: 5, 2, 8, 1
+Player 2's deck: 7, 10, 9
+Player 1 plays: 5
+Player 2 plays: 7
+Player 2 wins round 3 of game 2!
+
+-- Round 4 (Game 2) --
+Player 1's deck: 2, 8, 1
+Player 2's deck: 10, 9, 7, 5
+Player 1 plays: 2
+Player 2 plays: 10
+Player 2 wins round 4 of game 2!
+
+-- Round 5 (Game 2) --
+Player 1's deck: 8, 1
+Player 2's deck: 9, 7, 5, 10, 2
+Player 1 plays: 8
+Player 2 plays: 9
+Player 2 wins round 5 of game 2!
+
+-- Round 6 (Game 2) --
+Player 1's deck: 1
+Player 2's deck: 7, 5, 10, 2, 9, 8
+Player 1 plays: 1
+Player 2 plays: 7
+Player 2 wins round 6 of game 2!
+The winner of game 2 is player 2!
+
+...anyway, back to game 1.
+Player 2 wins round 9 of game 1!
+
+-- Round 10 (Game 1) --
+Player 1's deck: 9, 8, 5, 2
+Player 2's deck: 10, 1, 7, 6, 3, 4
+Player 1 plays: 9
+Player 2 plays: 10
+Player 2 wins round 10 of game 1!
+
+-- Round 11 (Game 1) --
+Player 1's deck: 8, 5, 2
+Player 2's deck: 1, 7, 6, 3, 4, 10, 9
+Player 1 plays: 8
+Player 2 plays: 1
+Player 1 wins round 11 of game 1!
+
+-- Round 12 (Game 1) --
+Player 1's deck: 5, 2, 8, 1
+Player 2's deck: 7, 6, 3, 4, 10, 9
+Player 1 plays: 5
+Player 2 plays: 7
+Player 2 wins round 12 of game 1!
+
+-- Round 13 (Game 1) --
+Player 1's deck: 2, 8, 1
+Player 2's deck: 6, 3, 4, 10, 9, 7, 5
+Player 1 plays: 2
+Player 2 plays: 6
+Playing a sub-game to determine the winner...
+
+=== Game 3 ===
+
+-- Round 1 (Game 3) --
+Player 1's deck: 8, 1
+Player 2's deck: 3, 4, 10, 9, 7, 5
+Player 1 plays: 8
+Player 2 plays: 3
+Player 1 wins round 1 of game 3!
+
+-- Round 2 (Game 3) --
+Player 1's deck: 1, 8, 3
+Player 2's deck: 4, 10, 9, 7, 5
+Player 1 plays: 1
+Player 2 plays: 4
+Playing a sub-game to determine the winner...
+
+=== Game 4 ===
+
+-- Round 1 (Game 4) --
+Player 1's deck: 8
+Player 2's deck: 10, 9, 7, 5
+Player 1 plays: 8
+Player 2 plays: 10
+Player 2 wins round 1 of game 4!
+The winner of game 4 is player 2!
+
+...anyway, back to game 3.
+Player 2 wins round 2 of game 3!
+
+-- Round 3 (Game 3) --
+Player 1's deck: 8, 3
+Player 2's deck: 10, 9, 7, 5, 4, 1
+Player 1 plays: 8
+Player 2 plays: 10
+Player 2 wins round 3 of game 3!
+
+-- Round 4 (Game 3) --
+Player 1's deck: 3
+Player 2's deck: 9, 7, 5, 4, 1, 10, 8
+Player 1 plays: 3
+Player 2 plays: 9
+Player 2 wins round 4 of game 3!
+The winner of game 3 is player 2!
+
+...anyway, back to game 1.
+Player 2 wins round 13 of game 1!
+
+-- Round 14 (Game 1) --
+Player 1's deck: 8, 1
+Player 2's deck: 3, 4, 10, 9, 7, 5, 6, 2
+Player 1 plays: 8
+Player 2 plays: 3
+Player 1 wins round 14 of game 1!
+
+-- Round 15 (Game 1) --
+Player 1's deck: 1, 8, 3
+Player 2's deck: 4, 10, 9, 7, 5, 6, 2
+Player 1 plays: 1
+Player 2 plays: 4
+Playing a sub-game to determine the winner...
+
+=== Game 5 ===
+
+-- Round 1 (Game 5) --
+Player 1's deck: 8
+Player 2's deck: 10, 9, 7, 5
+Player 1 plays: 8
+Player 2 plays: 10
+Player 2 wins round 1 of game 5!
+The winner of game 5 is player 2!
+
+...anyway, back to game 1.
+Player 2 wins round 15 of game 1!
+
+-- Round 16 (Game 1) --
+Player 1's deck: 8, 3
+Player 2's deck: 10, 9, 7, 5, 6, 2, 4, 1
+Player 1 plays: 8
+Player 2 plays: 10
+Player 2 wins round 16 of game 1!
+
+-- Round 17 (Game 1) --
+Player 1's deck: 3
+Player 2's deck: 9, 7, 5, 6, 2, 4, 1, 10, 8
+Player 1 plays: 3
+Player 2 plays: 9
+Player 2 wins round 17 of game 1!
+The winner of game 1 is player 2!
+
+
+== Post-game results ==
+Player 1's deck:
+Player 2's deck: 7, 5, 6, 2, 4, 1, 10, 8, 9, 3
+
+
+
+After the game, the winning player's score is calculated from the cards they have in their original deck using the same rules as regular Combat. In the above game, the winning player's score is 291
.
+
+Defend your honor as Raft Captain by playing the small crab in a game of Recursive Combat using the same two decks as before. What is the winning player's score?
+
+
diff --git a/2020/Day22/input.in b/2020/Day22/input.in
index 831915344..d57117dd9 100644
Binary files a/2020/Day22/input.in and b/2020/Day22/input.in differ
diff --git a/2020/Day23/README.md b/2020/Day23/README.md
index 7f505c698..a58c288b9 100644
--- a/2020/Day23/README.md
+++ b/2020/Day23/README.md
@@ -1,6 +1,95 @@
+original source: [https://adventofcode.com/2020/day/23](https://adventofcode.com/2020/day/23)
## --- Day 23: Crab Cups ---
The small crab challenges you to a game! The crab is going to mix up some cups, and you have to predict where they'll end up.
The cups will be arranged in a circle and labeled clockwise (your puzzle input). For example, if your labeling were 32415
, there would be five cups in the circle; going clockwise around the circle from the first cup, the cups would be labeled 3
, 2
, 4
, 1
, 5
, and then back to 3
again.
-Read the [full puzzle](https://adventofcode.com/2020/day/23).
\ No newline at end of file
+Before the crab starts, it will designate the first cup in your list as the current cup. The crab is then going to do 100 moves.
+
+Each move, the crab does the following actions:
+
+
+ - The crab picks up the three cups that are immediately clockwise of the current cup. They are removed from the circle; cup spacing is adjusted as necessary to maintain the circle.
+ - The crab selects a destination cup: the cup with a label equal to the current cup's label minus one. If this would select one of the cups that was just picked up, the crab will keep subtracting one until it finds a cup that wasn't just picked up. If at any point in this process the value goes below the lowest value on any cup's label, it wraps around to the highest value on any cup's label instead.
+ - The crab places the cups it just picked up so that they are immediately clockwise of the destination cup. They keep the same order as when they were picked up.
+ - The crab selects a new current cup: the cup which is immediately clockwise of the current cup.
+
+For example, suppose your cup labeling were 389125467
. If the crab were to do merely 10 moves, the following changes would occur:
+
+
+-- move 1 --
+cups: (3) 8 9 1 2 5 4 6 7
+pick up: 8, 9, 1
+destination: 2
+
+-- move 2 --
+cups: 3 (2) 8 9 1 5 4 6 7
+pick up: 8, 9, 1
+destination: 7
+
+-- move 3 --
+cups: 3 2 (5) 4 6 7 8 9 1
+pick up: 4, 6, 7
+destination: 3
+
+-- move 4 --
+cups: 7 2 5 (8) 9 1 3 4 6
+pick up: 9, 1, 3
+destination: 7
+
+-- move 5 --
+cups: 3 2 5 8 (4) 6 7 9 1
+pick up: 6, 7, 9
+destination: 3
+
+-- move 6 --
+cups: 9 2 5 8 4 (1) 3 6 7
+pick up: 3, 6, 7
+destination: 9
+
+-- move 7 --
+cups: 7 2 5 8 4 1 (9) 3 6
+pick up: 3, 6, 7
+destination: 8
+
+-- move 8 --
+cups: 8 3 6 7 4 1 9 (2) 5
+pick up: 5, 8, 3
+destination: 1
+
+-- move 9 --
+cups: 7 4 1 5 8 3 9 2 (6)
+pick up: 7, 4, 1
+destination: 5
+
+-- move 10 --
+cups: (5) 7 4 1 8 3 9 2 6
+pick up: 7, 4, 1
+destination: 3
+
+-- final --
+cups: 5 (8) 3 7 4 1 9 2 6
+
+
+
+In the above example, the cups' values are the labels as they appear moving clockwise around the circle; the current cup is marked with ( )
.
+
+After the crab is done, what order will the cups be in? Starting after the cup labeled 1
, collect the other cups' labels clockwise into a single string with no extra characters; each number except 1
should appear exactly once. In the above example, after 10 moves, the cups clockwise from 1
are labeled 9
, 2
, 6
, 5
, and so on, producing 92658374
. If the crab were to complete all 100 moves, the order after cup 1
would be 67384529
.
+
+Using your labeling, simulate 100 moves. What are the labels on the cups after cup 1
?
+
+
+## --- Part Two ---
+Due to what you can only assume is a mistranslation (you're not exactly fluent in Crab), you are quite surprised when the crab starts arranging many cups in a circle on your raft - one million (1000000
) in total.
+
+Your labeling is still correct for the first few cups; after that, the remaining cups are just numbered in an increasing fashion starting from the number after the highest number in your list and proceeding one by one until one million is reached. (For example, if your labeling were 54321
, the cups would be numbered 5
, 4
, 3
, 2
, 1
, and then start counting up from 6
until one million is reached.) In this way, every number from one through one million is used exactly once.
+
+After discovering where you made the mistake in translating Crab Numbers, you realize the small crab isn't going to do merely 100 moves; the crab is going to do ten million (10000000
) moves!
+
+The crab is going to hide your stars - one each - under the two cups that will end up immediately clockwise of cup 1
. You can have them if you predict what the labels on those cups will be when the crab is finished.
+
+In the above example (389125467
), this would be 934001
and then 159792
; multiplying these together produces 149245887792
.
+
+Determine which two cups will end up immediately clockwise of cup 1
. What do you get if you multiply their labels together?
+
+
diff --git a/2020/Day23/input.in b/2020/Day23/input.in
index 32bcef7d0..f925d7678 100644
Binary files a/2020/Day23/input.in and b/2020/Day23/input.in differ
diff --git a/2020/Day24/README.md b/2020/Day24/README.md
index 614c04ba5..c8efdcf9c 100644
--- a/2020/Day24/README.md
+++ b/2020/Day24/README.md
@@ -1,6 +1,89 @@
+original source: [https://adventofcode.com/2020/day/24](https://adventofcode.com/2020/day/24)
## --- Day 24: Lobby Layout ---
Your raft makes it to the tropical island; it turns out that the small crab was an excellent navigator. You make your way to the resort.
As you enter the lobby, you discover a small problem: the floor is being renovated. You can't even reach the check-in desk until they've finished installing the new tile floor.
-Read the [full puzzle](https://adventofcode.com/2020/day/24).
\ No newline at end of file
+The tiles are all hexagonal; they need to be arranged in a [hex grid](https://en.wikipedia.org/wiki/Hexagonal_tiling) with a very specific color pattern. Not in the mood to wait, you offer to help figure out the pattern.
+
+The tiles are all white on one side and black on the other. They start with the white side facing up. The lobby is large enough to fit whatever pattern might need to appear there.
+
+A member of the renovation crew gives you a list of the tiles that need to be flipped over (your puzzle input). Each line in the list identifies a single tile that needs to be flipped by giving a series of steps starting from a reference tile in the very center of the room. (Every line starts from the same reference tile.)
+
+Because the tiles are hexagonal, every tile has six neighbors: east, southeast, southwest, west, northwest, and northeast. These directions are given in your list, respectively, as e
, se
, sw
, w
, nw
, and ne
. A tile is identified by a series of these directions with no delimiters; for example, esenee
identifies the tile you land on if you start at the reference tile and then move one tile east, one tile southeast, one tile northeast, and one tile east.
+
+Each time a tile is identified, it flips from white to black or from black to white. Tiles might be flipped more than once. For example, a line like esew
flips a tile immediately adjacent to the reference tile, and a line like nwwswee
flips the reference tile itself.
+
+Here is a larger example:
+
+
+sesenwnenenewseeswwswswwnenewsewsw
+neeenesenwnwwswnenewnwwsewnenwseswesw
+seswneswswsenwwnwse
+nwnwneseeswswnenewneswwnewseswneseene
+swweswneswnenwsewnwneneseenw
+eesenwseswswnenwswnwnwsewwnwsene
+sewnenenenesenwsewnenwwwse
+wenwwweseeeweswwwnwwe
+wsweesenenewnwwnwsenewsenwwsesesenwne
+neeswseenwwswnwswswnw
+nenwswwsewswnenenewsenwsenwnesesenew
+enewnwewneswsewnwswenweswnenwsenwsw
+sweneswneswneneenwnewenewwneswswnese
+swwesenesewenwneswnwwneseswwne
+enesenwswwswneneswsenwnewswseenwsese
+wnwnesenesenenwwnenwsewesewsesesew
+nenewswnwewswnenesenwnesewesw
+eneswnwswnwsenenwnwnwwseeswneewsenese
+neswnwewnwnwseenwseesewsenwsweewe
+wseweeenwnesenwwwswnew
+
+
+
+In the above example, 10 tiles are flipped once (to black), and 5 more are flipped twice (to black, then back to white). After all of these instructions have been followed, a total of 10
tiles are black.
+
+Go through the renovation crew's list and determine which tiles they need to flip. After all of the instructions have been followed, how many tiles are left with the black side up?
+
+
+## --- Part Two ---
+The tile floor in the lobby is meant to be a living art exhibit. Every day, the tiles are all flipped according to the following rules:
+
+
+ - Any black tile with zero or more than 2 black tiles immediately adjacent to it is flipped to white.
+ - Any white tile with exactly 2 black tiles immediately adjacent to it is flipped to black.
+
+Here, tiles immediately adjacent means the six tiles directly touching the tile in question.
+
+The rules are applied simultaneously to every tile; put another way, it is first determined which tiles need to be flipped, then they are all flipped at the same time.
+
+In the above example, the number of black tiles that are facing up after the given number of days has passed is as follows:
+
+
+Day 1: 15
+Day 2: 12
+Day 3: 25
+Day 4: 14
+Day 5: 23
+Day 6: 28
+Day 7: 41
+Day 8: 37
+Day 9: 49
+Day 10: 37
+
+Day 20: 132
+Day 30: 259
+Day 40: 406
+Day 50: 566
+Day 60: 788
+Day 70: 1106
+Day 80: 1373
+Day 90: 1844
+Day 100: 2208
+
+
+
+After executing this process a total of 100 times, there would be 2208
black tiles facing up.
+
+How many tiles will be black after 100 days?
+
+
diff --git a/2020/Day24/input.in b/2020/Day24/input.in
index 69fd51927..a3c95793d 100644
Binary files a/2020/Day24/input.in and b/2020/Day24/input.in differ
diff --git a/2020/Day25/README.md b/2020/Day25/README.md
index 1ee9fb87d..ccf5d8e45 100644
--- a/2020/Day25/README.md
+++ b/2020/Day25/README.md
@@ -1,6 +1,58 @@
+original source: [https://adventofcode.com/2020/day/25](https://adventofcode.com/2020/day/25)
## --- Day 25: Combo Breaker ---
You finally reach the check-in desk. Unfortunately, their registration systems are currently offline, and they cannot check you in. Noticing the look on your face, they quickly add that tech support is already on the way! They even created all the room keys this morning; you can take yours now and give them your room deposit once the registration system comes back online.
The room key is a small [RFID](https://en.wikipedia.org/wiki/Radio-frequency_identification) card. Your room is on the 25th floor and the elevators are also temporarily out of service, so it takes what little energy you have left to even climb the stairs and navigate the halls. You finally reach the door to your room, swipe your card, and - beep - the light turns red.
-Read the [full puzzle](https://adventofcode.com/2020/day/25).
\ No newline at end of file
+Examining the card more closely, you discover a phone number for tech support.
+
+"Hello! How can we help you today?" You explain the situation.
+
+"Well, it sounds like the card isn't sending the right command to unlock the door. If you go back to the check-in desk, surely someone there can reset it for you." Still catching your breath, you describe the status of the elevator and the exact number of stairs you just had to climb.
+
+"I see! Well, your only other option would be to reverse-engineer the cryptographic handshake the card does with the door and then inject your own commands into the data stream, but that's definitely impossible." You thank them for their time.
+
+Unfortunately for the door, you know a thing or two about cryptographic handshakes.
+
+The handshake used by the card and the door involves an operation that transforms a subject number. To transform a subject number, start with the value 1
. Then, a number of times called the loop size, perform the following steps:
+
+
+ - Set the value to itself multiplied by the subject number.
+ - Set the value to the remainder after dividing the value by 20201227
.
+
+The card always uses a specific, secret loop size when it transforms a subject number. The door always uses a different, secret loop size.
+
+The cryptographic handshake works like this:
+
+
+ - The card transforms the subject number of 7
according to the card's secret loop size. The result is called the card's public key.
+ - The door transforms the subject number of 7
according to the door's secret loop size. The result is called the door's public key.
+ - The card and door use the wireless RFID signal to transmit the two public keys (your puzzle input) to the other device. Now, the card has the door's public key, and the door has the card's public key. Because you can eavesdrop on the signal, you have both public keys, but neither device's loop size.
+ - The card transforms the subject number of the door's public key according to the card's loop size. The result is the encryption key.
+ - The door transforms the subject number of the card's public key according to the door's loop size. The result is the same encryption key as the card calculated.
+
+If you can use the two public keys to determine each device's loop size, you will have enough information to calculate the secret encryption key that the card and door use to communicate; this would let you send the unlock
command directly to the door!
+
+For example, suppose you know that the card's public key is 5764801
. With a little trial and error, you can work out that the card's loop size must be 8
, because transforming the initial subject number of 7
with a loop size of 8
produces 5764801
.
+
+Then, suppose you know that the door's public key is 17807724
. By the same process, you can determine that the door's loop size is 11
, because transforming the initial subject number of 7
with a loop size of 11
produces 17807724
.
+
+At this point, you can use either device's loop size with the other device's public key to calculate the encryption key. Transforming the subject number of 17807724
(the door's public key) with a loop size of 8
(the card's loop size) produces the encryption key, 14897079
. (Transforming the subject number of 5764801
(the card's public key) with a loop size of 11
(the door's loop size) produces the same encryption key: 14897079
.)
+
+What encryption key is the handshake trying to establish?
+
+
+## --- Part Two ---
+The light turns green and the door unlocks. As you collapse onto the bed in your room, your pager goes off!
+
+"It's an emergency!" the Elf calling you explains. "The [soft serve](https://en.wikipedia.org/wiki/Soft_serve) machine in the cafeteria on sub-basement 7 just failed and you're the only one that knows how to fix it! We've already dispatched a reindeer to your location to pick you up."
+
+You hear the sound of hooves landing on your balcony.
+
+The reindeer carefully explores the contents of your room while you figure out how you're going to pay the 50 stars you owe the resort before you leave. Noticing that you look concerned, the reindeer wanders over to you; you see that it's carrying a small pouch.
+
+"Sorry for the trouble," a note in the pouch reads. Sitting at the bottom of the pouch is a gold coin with a little picture of a starfish on it.
+
+Looks like you only needed 49 stars after all.
+
+
diff --git a/2020/Day25/input.in b/2020/Day25/input.in
index 44406a1f4..d08846f1e 100644
Binary files a/2020/Day25/input.in and b/2020/Day25/input.in differ
diff --git a/2020/README.md b/2020/README.md
index 6e92a1b05..909ac8d77 100644
--- a/2020/README.md
+++ b/2020/README.md
@@ -1,4 +1,6 @@
+
# Advent of Code (2020)
Check out https://adventofcode.com/2020.