Advent of Code: Day 16 Solution

This year, I’m posting my solutions to the puzzles in the Advent of Code.

Click the link to view the puzzle and code, along with a link to the solution on Github.

And now, on with the solution:

Day 16, part 1

Simplified problem:

Starting with a string of 0 and 1 characters, process the input based on the following rules until the length of the string is greater than or equal to [value] (in this case, 272).

  • 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”.

Once the string is long enough, calculate a checksum based on the following rules:

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 is calculated using the first [value] characters of the string.

What is the checksum of the data?

Day 16, Part 2

What is the checksum of the data using a string of length [largervalue] (in this case, 35651584)?

Solution

You can find the full solution on Github

Leave a Reply

Your email address will not be published. Required fields are marked *