Reflowed problems and added solutions

This commit is contained in:
2018-03-15 11:24:23 -05:00
parent 986d17f104
commit 2a37946673
50 changed files with 2124 additions and 1464 deletions

View File

@@ -2,38 +2,55 @@ Advent of Code
--- Day 1: No Time for a Taxicab ---
Santa's sleigh uses a very high-precision clock to guide its movements, and the clock's oscillator is regulated by stars. Unfortunately, the stars have been stolen... by the Easter Bunny. To save Christmas, Santa needs you to
Santa's sleigh uses a very high-precision clock to guide its movements, and
the clock's oscillator is regulated by stars. Unfortunately, the stars have
been stolen... by the Easter Bunny. To save Christmas, Santa needs you to
retrieve all fifty stars by December 25th.
Collect stars by solving 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!
Collect stars by solving 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!
You're airdropped near Easter Bunny Headquarters in a city somewhere. "Near", unfortunately, is as close as you can get - the instructions on the Easter Bunny Recruiting Document the Elves intercepted start here, and nobody had time
to work them out further.
You're airdropped near Easter Bunny Headquarters in a city somewhere.
"Near", unfortunately, is as close as you can get - the instructions on the
Easter Bunny Recruiting Document the Elves intercepted start here, and
nobody had time to work them out further.
The Document indicates that you should start at the given coordinates (where you just landed) and face North. Then, follow the provided sequence: either turn left (L) or right (R) 90 degrees, then walk forward the given number of
The Document indicates that you should start at the given coordinates (where
you just landed) and face North. Then, follow the provided sequence: either
turn left (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, how far is the shortest path to the destination?
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, 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.
 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?
Your puzzle answer was ___.
Your puzzle answer was 243.
--- 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.
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.
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?
Your puzzle answer was ___.
Your puzzle answer was 142.
If you still want to see it, you can get your puzzle input.

View File

@@ -2,20 +2,24 @@ Advent of Code
--- 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.
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."
"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."
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.
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:
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
@@ -28,18 +32,25 @@ Advent of Code
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.
 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?
Your puzzle input is the instructions from the document you found at the
front desk. What is the bathroom code?
Your puzzle answer was ______.
Your puzzle answer was 98575.
--- Part Two ---
@@ -66,7 +77,7 @@ Advent of Code
Using the same instructions in your puzzle input, what is the correct bathroom code?
Your puzzle answer was _____.
Your puzzle answer was CD8D4.
Both parts of this puzzle are complete! They provide two gold stars: **

View File

@@ -2,32 +2,35 @@ Advent of Code
--- 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.
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?
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.
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 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?
Your puzzle answer was ___.
Your puzzle answer was 869.
The first half of this puzzle is complete! It provides one gold star: *
--- 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.
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:
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
@@ -36,10 +39,10 @@ Advent of Code
202 402 602
203 403 603
In your puzzle input, and instead reading by columns, how many of the listed triangles are
possible?
In your puzzle input, and instead reading by columns, how many of the listed
triangles are possible?
Although it hasn't changed, you can still get your puzzle input.
Your puzzle answer was 1544
References

View File

@@ -2,52 +2,59 @@ Advent of Code
--- 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.
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.
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.
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:
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.
 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?
Your puzzle answer was ___________.
Your puzzle answer was 245102.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
With all the decoy data out of the way, it's time to decrypt this list and get moving.
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, 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.
The room names are encrypted by a state-of-the-art shift 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.
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.
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?
Although it hasn't changed, you can still get your puzzle input.
Answer: _____________________ [ [Submit] ]
You can also [Shareon Twitter Google+ Reddit] this puzzle.
Your puzzle answer was 324.
References

View File

@@ -2,48 +2,72 @@ Advent of Code
--- 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 movies.
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
movies.
The eight-character password for the door is generated one character at a time by finding the MD5 hash of some Door ID (your puzzle input) and an increasing integer
index (starting with 0).
The eight-character password for the door is generated one character at a
time by finding the MD5 hash of some Door ID (your puzzle input) and an
increasing integer index (starting with 0).
A hash indicates the next character in the password if its hexadecimal representation starts with five zeroes. If it does, the sixth character in the hash is the next
character of the password.
A hash indicates the next character in the password if its 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.
 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.
In this example, after continuing this search a total of eight times, the password is 18f47a30.
 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?
Your puzzle answer was ________.
Your puzzle answer was 4543c154.
--- 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.
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.
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.
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.
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___.
 The first interesting hash is from abc3231929, which produces
0000015...; so, 5 goes in position 1: _5______.
You almost choke on your popcorn as the final character falls into place, producing the password 05ace8e3.
 In the previous method, 5017308 produced an interesting hash; however,
it is ignored, because it specifies an invalid position (8).
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.
 The second interesting hash is at index 5357525, which produces
000004e...; so, e goes in position 4: _5__e___.
Your puzzle answer was ________.
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.
Your puzzle answer was 1050cbbd.
Your puzzle input was ojvtpuvg.

View File

@@ -2,13 +2,16 @@ Advent of Code
--- 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 to get the message through.
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 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.
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.
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:
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
@@ -27,12 +30,14 @@ Advent of Code
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
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?
Given the recording in your puzzle input, what is the error-corrected
version of the message being sent?
Your puzzle answer was ________.
Your puzzle answer was cyxeoccr.
--- Part Two ---
@@ -47,7 +52,7 @@ Advent of Code
Given the recording in your puzzle input and this new decoding methodology, what is the original message that Santa is trying to send?
Your puzzle answer was ________.
Your puzzle answer was batwpask.
References

View File

@@ -2,44 +2,62 @@ Advent of Code
--- Day 7: Internet Protocol Version 7 ---
While snooping around the local network of EBHQ, you compile a list of IP addresses (they're IPv7, of course; IPv6 is much too limited).
You'd like to figure out which IPs support TLS (transport-layer snooping).
While snooping around the local network of EBHQ, you compile a list of IP
addresses (they're IPv7, of course; 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.
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.
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).
 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?
Your puzzle answer was _____.
Your puzzle answer was 118.
--- 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.
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).
 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).
 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?
Your puzzle answer was _______.
Your puzzle answer was 260.
References

View File

@@ -2,24 +2,33 @@ Advent of Code
--- Day 8: Two-Factor Authentication ---
You come across a door implementing what you can only assume is an implementation of two-factor authentication
after a long game of requirements telephone.
You come across a door implementing what you can only assume is an
implementation of two-factor authentication after a long game of
requirements telephone.
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, and you type that code on a keypad. Then, presumably, the door unlocks.
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, and you type
that code on a keypad. Then, presumably, the door unlocks.
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.
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:
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.
 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:
@@ -41,30 +50,31 @@ Advent of Code
###....
.#.....
 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:
 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.
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?
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?
Your puzzle answer was _____.
Your puzzle answer was 119.
--- 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.
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?
Your puzzle answer was _____________.
Your puzzle answer was ZFHFSFOGPO.
References

View File

@@ -2,55 +2,83 @@ Advent of Code
--- 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.
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.
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.
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.
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.
 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.
 A(2x2)BCD(2x2)EFG doubles the BC and EF, becoming ABCBCDEFEFG for a
decompressed length of 11.
Your puzzle answer was __________.
• (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.
Your puzzle answer was 110346.
--- 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.
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.
• (3x3)XYZ still becomes XYZXYZXYZ, as the decompressed section contains
no markers.
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.
 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?
Although it hasn't changed, you can still get your puzzle input.
Answer: _____________________ [ [Submit] ]
Your puzzle answer was 10774309173.
References

View File

@@ -2,20 +2,22 @@ Advent of Code
--- Day 10: Balance Bots ---
You come upon a factory in which many robots are zooming around handing small microchips to
each other.
You come upon a factory in which many robots are zooming around 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.
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.
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).
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.
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:
@@ -26,29 +28,34 @@ Advent of Code
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.
 Initially, bot 1 starts with a value-3 chip, and bot 2 starts with a
value-2 chip and a value-5 chip.
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.
 Because bot 2 has two microchips, it gives its lower one (2) to bot 1
and its higher one (5) to bot 0.
Based on your instructions, what is the number of the bot that is responsible for comparing
value-61 microchips with value-17 microchips?
 Then, bot 1 has two microchips; it puts the value-2 chip in output 1 and
gives the value-3 chip to bot 0.
Your puzzle answer was ______.
 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?
Your puzzle answer was 47.
--- Part Two ---
What do you get if you multiply together the values of one chip in each of outputs 0, 1, and
2?
What do you get if you multiply together the values of one chip in each of
outputs 0, 1, and 2?
Your puzzle answer was _______.
Your puzzle answer was 2666.
References

222
2016/day11/problem Normal file
View File

@@ -0,0 +1,222 @@
Advent of Code
--- 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 (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.
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?
Your puzzle answer was 31.
--- 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?
Your puzzle answer was 55.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, all that is left is for you to admire your advent calendar.
If you still want to see it, you can get your puzzle input.
References
Visible links
. http://adventofcode.com/
. http://adventofcode.com/2016/about
. http://adventofcode.com/2016/support
. http://adventofcode.com/2016/events
. http://adventofcode.com/2016/settings
. http://adventofcode.com/2016/auth/logout
. http://adventofcode.com/2016
. http://adventofcode.com/2016
. http://adventofcode.com/2016/leaderboard
. http://adventofcode.com/2016/stats
. http://adventofcode.com/2016/sponsors
. http://adventofcode.com/2016/sponsors
. https://en.wikipedia.org/wiki/Radioisotope_thermoelectric_generator
. http://adventofcode.com/2016
. http://adventofcode.com/2016/day/11/input

View File

@@ -2,31 +2,40 @@ Advent of Code
--- 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.
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, you manage to decrypt some of the files you extracted from
the servers downstairs.
While sitting on a nearby bench amidst some tiger lilies, you manage to
decrypt some of the files you extracted from the servers downstairs.
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.
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 you just assembled. You'll have to execute the code and get the password.
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 you just assembled. You'll have to
execute the code and get the password.
The assembunny code you've extracted operates on four registers (a, b, c, and d) that start at 0 and can hold any
integer. However, it seems to make use of only a few instructions:
The assembunny code you've extracted operates on four registers (a, b, c,
and d) that start at 0 and can hold any integer. However, it seems to make
use of only a few instructions:
 cpy x y copies x (either an integer or the value of a register) into
register y.
 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.
 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:
@@ -37,22 +46,26 @@ Advent of Code
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
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?
After executing the assembunny code in your puzzle input, what value is left
in register a?
Your puzzle answer was __________.
Your puzzle answer was 318077.
--- 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.
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?
If you instead initialize register c to be 1, what value is now left in
register a?
Your puzzle answer was ___________.
Your puzzle answer was 9227731.
References

View File

@@ -2,25 +2,33 @@ Advent of Code
--- 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.
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.
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.
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:
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 of that sum; count the number of bits that are 1.
 Find the binary representation of that sum; count the number of bits
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:
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 .#.####.##
@@ -31,7 +39,8 @@ Advent of Code
5 ..##....#.
6 #...##.###
Now, suppose you wanted to reach 7,4. The shortest route you could take is marked as O:
Now, suppose you wanted to reach 7,4. The shortest route you could take is
marked as O:
0123456789
0 .#.####.##
@@ -42,21 +51,23 @@ Advent of Code
5 ..##OOO.#.
6 #...##.###
Thus, reaching 7,4 would take a minimum of 11 steps (starting from your current location, 1,1).
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?
Your puzzle answer was _____.
Your puzzle answer was 86.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
How many locations (distinct x,y coordinates, including your starting location) can you reach in at most 50 steps?
How many locations (distinct x,y coordinates, including your starting
location) can you reach in at most 50 steps?
Your puzzle input is still 1364.
Answer: _____________________
Answer: 127
References

View File

@@ -2,45 +2,67 @@ Advent of Code
--- 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 that you generate 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.
In order to communicate securely with Santa while you're on this mission,
you've been using a one-time pad that you generate 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 of a pre-arranged salt (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.
To generate keys, you first get a stream of random data by taking the MD5 of
a pre-arranged salt (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.
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:
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.
 It contains three of the same character in a row, like 777. Only
consider the first such triplet in a hash.
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.
 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 64th key.
 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 64th
key.
So, using our example salt of abc, index 22728 produces the 64th key.
Given the actual salt in your puzzle input, what index produces your 64th one-time pad key?
Given the actual salt in your puzzle input, what index produces your 64th
one-time pad key?
Your puzzle input was cuanljph.
Your puzzle answer was ________.
Your puzzle answer was 23769.
--- Part Two ---
Of course, in order to make this process even more secure, you've also implemented key stretching.
Of course, in order to make this process even more secure, you've also
implemented key stretching.
Key stretching forces attackers to spend more time generating hashes. Unfortunately, it forces everyone else to spend more time, too.
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.
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:
@@ -50,18 +72,26 @@ Advent of Code
• ...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.
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 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 64th key (triple fff with matching fffff at index 22859.
 The first triple (222, at index 5) has no matching 22222 in the next
thousand hashes.
Given the actual salt in your puzzle input and using 2016 extra MD5 calls of key stretching, what index now produces your 64th one-time pad key?
 The second triple (eee, at index 10) hash a matching eeeee at index 89,
and so it is the first key.
Your puzzle answer was ________.
 Eventually, index 22551 produces the 64th 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 64th one-time pad key?
Your puzzle answer was 20606.
Your puzzle input was cuanljph.

View File

@@ -2,49 +2,76 @@ Advent of Code
--- 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 of spinning pieces.
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 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.
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.
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.
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 disk 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.
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 disk 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.
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.
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.
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.
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?
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?
Your puzzle answer was _________.
Your puzzle answer was 400589.
--- Part Two ---
After getting the first capsule (it contained a star! what great fortune!), the machine detects your success and begins to rearrange itself.
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.
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?
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?
Although it hasn't changed, you can still get your puzzle input.
Answer: _____________________
Answer: 3045959
References

View File

@@ -2,20 +2,27 @@ Advent of Code
--- 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.
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 suspiscious, 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.
For the data to not be suspiscious, 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.
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:
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 1s with 0.
 The resulting data is "a", then a single 0, then "b".
For example, after a single step of this process,
@@ -27,44 +34,62 @@ Advent of Code
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.
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.
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:
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 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:
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.
 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?
The first disk you have to fill has length 272. Using the initial state in
your puzzle input, what is the correct checksum?
Your puzzle answer _____________________.
Your puzzle answer 10011010010010010.
The first half of this puzzle is complete! It provides one gold star: *
@@ -75,7 +100,7 @@ Advent of Code
Your puzzle input is still 00111101111101000.
Answer: _____________________
Answer: 10101011110100011.
References

View File

@@ -2,9 +2,9 @@ Advent of Code
--- 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:
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:
#########
#S| | | #
@@ -18,52 +18,56 @@ Advent of Code
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 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).
The doors in your current room are either open or closed (and locked) based
on the hexadecimal 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.
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.
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
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 hijklD. This produces f2bc,
which indicates that you can go back up, left (but that's a wall), or right. Going right means
hashing hijklDR 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.
Next, having gone only one step (down, or D), you find the hash of hijklD.
This produces f2bc, which indicates that you can go back up, left (but
that's a wall), or right. Going right means hashing hijklDR 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 hijklDU to get 528e), only the right door is open; after
going DUR, all doors lock. (Fortunately, your actual passcode is not hijkl).
After going DU (and then hashing hijklDU 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:
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?
Given your vault's passcode, what is the shortest path (the actual path, not
just the length) to reach the vault?
Your puzzle answer was __________________.
Your puzzle answer was DRRDRLDURD.
--- 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).
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:
@@ -73,7 +77,7 @@ Advent of Code
What is the length of the longest path that reaches the vault?
Your puzzle answer was _______.
Your puzzle answer was 618.
References

View File

@@ -2,28 +2,32 @@ Advent of Code
--- 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, 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.
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, 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).
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).
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.)
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):
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:
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.
@@ -32,24 +36,30 @@ Advent of Code
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:
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, ^.
 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, ..
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:
 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:
..^^.
.^^^^
@@ -70,16 +80,16 @@ Advent of Code
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?
Starting with the map in your puzzle input, in a total of 40 rows (including
the starting row), how many safe tiles are there?
Your puzzle answer ________.
Your puzzle answer 1913.
--- Part Two ---
How many safe tiles are there in a total of 400000 rows?
Your puzzle answer was ________.
Your puzzle answer was 19993564.
References

View File

@@ -5,10 +5,10 @@ Advent of Code
The Elves contact you over a highly secure emergency channel. Back at the
North Pole, the Elves are busy misunderstanding White Elephant parties.
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.
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.
For example, with five Elves (numbered 1 to 5):
@@ -27,21 +27,21 @@ Advent of Code
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?
With the number of Elves given in your puzzle input, which Elf gets all the
presents?
Your puzzle input was 3014387.
Your puzzle answer was __________.
Your puzzle answer was 1834471.
--- 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.
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):
@@ -52,8 +52,8 @@ Advent of Code
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:
the one to the left. Elf 3 leaves the circle, and the rest of the Elves
move in:
1 1
5 2 --> 5 2
@@ -80,12 +80,12 @@ Advent of Code
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?
With the number of Elves given in your puzzle input, which Elf now gets all
the presents?
Your puzzle input was 3014387.
Your puzzle answer was __________.
Your puzzle answer was 1420064.
References

View File

@@ -2,30 +2,37 @@ Advent of Code
--- 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.
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.
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 notation, they are written as plain 32-bit integers, which can have any value from 0 through 4294967295, inclusive.
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 notation, they are
written as plain 32-bit integers, which can have any value from 0 through
4294967295, inclusive.
For example, suppose only the values 0 through 9 were valid, and that you retrieved the following blacklist:
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.
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?
Given the list of blocked IPs you retrieved from the firewall (your puzzle
input), what is the lowest-valued IP that is not blocked?
Your puzzle answer was _______________.
Your puzzle answer was 31053880.
--- Part Two ---
How many IPs are allowed by the blacklist?
Your puzzle answer was _______________.
Your puzzle answer was 117.
References

View File

@@ -2,51 +2,86 @@ Advent of Code
--- 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 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:
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:
 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.
 swap position X with position Y means that the letters at indexes X and
Y (counting from 0) should be swapped.
For example, suppose you start with abcde and perform the following operations:
 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 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.
 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?
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?
Your puzzle answer was ________.
Your puzzle answer was cbeghdaf.
--- Part Two ---
You scrambled the password correctly, but you discover that you can't actually modify the password file on the system. You'll need to
un-scramble one of the existing passwords by reversing the scrambling process.
You scrambled the password correctly, but you discover that you can't
actually modify the password file 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?
Your puzzle answer was ________.
Your puzzle answer was bacdefgh.
References

176
2016/day22/problem Normal file
View File

@@ -0,0 +1,176 @@
Advent of Code
--- 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:
 You can get the disk usage of all nodes (via df). 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?
Your puzzle answer was 955.
--- 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 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?
Your puzzle answer was 246.
Both parts of this puzzle are complete! They provide two gold stars: **
At this point, all that is left is for you to admire your advent calendar.
If you still want to see it, you can get your puzzle input.
References
Visible links
. http://adventofcode.com/
. http://adventofcode.com/2016/about
. http://adventofcode.com/2016/support
. http://adventofcode.com/2016/events
. http://adventofcode.com/2016/settings
. http://adventofcode.com/2016/auth/logout
. http://adventofcode.com/2016
. http://adventofcode.com/2016
. http://adventofcode.com/2016/leaderboard
. http://adventofcode.com/2016/stats
. http://adventofcode.com/2016/sponsors
. http://adventofcode.com/2016/sponsors
. https://en.wikipedia.org/wiki/Df_(Unix)#Example
. https://en.wikipedia.org/wiki/Terabyte
. http://adventofcode.com/2016
. http://adventofcode.com/2016/day/22/input

View File

@@ -2,34 +2,50 @@ Advent of Code
--- 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?
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.
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.
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! You pull apart the smashed keypad and extract the logic circuit, plug it into your computer,
and plug your computer into the safe.
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! 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 from the logic chip (your puzzle input).
Now, you just need to figure out what output the keypad would have sent to
the safe. You extract the assembunny code from the logic chip (your puzzle
input).
The code looks like it uses almost the same architecture and instruction set that the monorail computer used! You
should be able to use the same assembunny interpreter for this as you did there, but with one new instruction:
The code looks like it uses almost the same architecture and instruction set
that the monorail computer 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):
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.
 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.
 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:
@@ -42,34 +58,45 @@ Advent of Code
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 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.
 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.
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?
Your puzzle answer was ________.
Your puzzle answer was 10584.
--- Part Two ---
The safe doesn't open, but it does make several angry noises to express its frustration.
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.
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
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?
Your puzzle answer was ____________.
Your puzzle answer was 479007144.
References

View File

@@ -2,19 +2,23 @@ Advent of Code
--- 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.
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.
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 system. If you can direct it to each of those locations, you should be able to bypass
the security controls.
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 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.
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:
@@ -24,29 +28,33 @@ Advent of Code
#4.......3#
###########
To reach all of the points of interest as quickly as possible, you would have the robot take the following path:
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.
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?
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?
Your puzzle answer was ____.
Your puzzle answer was 490.
--- Part Two ---
Of course, if you leave the cleaning robot somewhere weird, someone is bound to notice.
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?
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?
Your puzzle answer was _____.
Your puzzle answer was 744.
References

View File

@@ -2,51 +2,61 @@ Advent of Code
--- Day 25: Clock Signal ---
You open the door and find yourself on the roof. The city sprawls away from you for miles and miles.
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.
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.
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.
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.
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.
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 - 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.
"No, no, a 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 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 code (your puzzle input); it looks mostly compatible
with code you worked on just recently.
You've extracted the antenna's clock signal generation assembunny code (your
puzzle input); it looks mostly compatible with code you worked on just
recently.
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.
 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.
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?
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?
Your puzzle answer was ____.
Your puzzle answer was 175.
--- 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.
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.
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.
If you like, you can [ [Retransmit the Signal] ] .