Sean McLemon | Advent of Code

Home | Czech | Blog | GitHub | Advent Of Code | Notes

My Advent Of Code 2020 solutions. See also 2021, 2019, 2018, 2017 and 2016.

2020-12-25 - Combo Breaker

Day 25 input is two integers representing readings from an RFID handshake (mine is here). Part 1 involves using these digits, a known value (the "subject" - 7) and the description of an algorithm to find out an encryption key. There is no Part 2 :-)

Looking back on Advent of Code I really enjoyed many of the problems. I am glad I completed it on Christmas Day proper, there's a nice sense of satisfaction and accomplishment that comes with that. I don't want to write a whole bunch about this but I'll summarise a few things:

  1. It was really motivating to have a few colleagues working through the puzzles at the same time. Not in a competitive way, but in an encouraging way.
  2. I am beyond impressed at (my colleague) Rob's decision use F#, and as a result feel a bit humbled by my use of Python :-D
  3. A couple of maths ones really messed me up - I feel like I cut corners on them.
  4. Getting up at 6am every day to start (if not exactly finish) my problems was a great idea. Towards the end I didn't manage them before I had to go take my dog Alfie out (usually I gave it 1 hour and a half), but it was really good.
  5. The latter ~7 problems or so were much harder. I rarely take time off just before christmas, but if I have days off next year I'll use them up in the run-up to christmas to ease this a bit (and make xmas prep a bit less stressful at the same time).
  6. I'd like to continue doing little puzzles like this through the year, but at a much reduced pace - once a week or fortnight. I'll maybe revisit Project Euler or the puzzles given out by Interview Cake.

2020-12-24 - Lobby Layout

Day 24 input is a sequence of paths through a hexagonal grid (mine is here) representing the tile pattern of a floor (once the end of each path is reached the tile color is flipped). Part 1 involves interpreting these paths and determining how many end up being black. Part 2 involves playing this repeatedly with a few cellular-automata/game-of-life type rules that govern how the tiles change over time.

2020-12-23 - Crab Cups

Day 23 input is 9 digit string representing the arrangement of 9 cups in a circle, labelled 1-9 (mine is 364289715). Part 1 involves applying a given shuffle of these cups 100 times. Part 2 involves increasing the cups (to 1 million, each cup after the initial 9 is just labelled after the place in the initial configuration it is, so the 10th cup is 10, the 11th cup is 11, etc) and applying the shuffle 10 million times.

NOTE: My solution is horrendously inefficient and Part 2 does not complete in a reasonable time. To get my answer I ran it locally with pypy, tweaked a few bits and then ran it overnight. :-/ there is definitely a faster way to get this. Another one for the "revisit" queue.

2020-12-22 - Crab Combat

Day 22 input is a listing of the cards two players have (mine is here). Part 1 involves applying the rules of a game until one player has no more cards left. Part 2 playing the game with a small modification - it can recurse into many sub-games.

2020-12-21 - Allergen Assessment

Day 21 input is a sequence of ingredients in an unfamiliar language followed by a list of allergens (mine is here). Each allergen maps to a single ingredient. Part 1 involves finding the number of appearances of each ingredient which is not an allergen. Part 2 involves finding the allergen/ingredient mappings and producing a comma-separated string of ingredients sorted by the alphabetic order of their allergen.

2020-12-20 - Jurassic Jigsaw

Day 20 input is a sequence of "tiles" - grids composed of # and . characters (mine is here). The tiles can be combined to form a grid, where a tile can be beside another tile if its edges match up. They can be rotated or flipped (think of them like a jigsaw piece). Part 1 involves combining them to find the corner tiles. Part 2 involves producing an output image and looking for a certain "monster" pattern.

2020-12-19 - Monster Messages

Day 19 input is a sequence of rules followed by a sequence of messages strings (mine is here). The rules are like a parse tree and determine whether a message is valid or not. Part 1 involves finding the number of valid messages. Part 2 involves modifying rule 8 and 11 and then finding the number of valid messages again.

Note: I started off with a very neat little parser - but it was stupid and returned the first valid sequence. This was OK for part one, but with the loops it unfortunately returned too early. I then hacked on it for a bit, went out for a walk with alfie, hacked a bit more, made french toast for breakfast and then hacked until it worked. So it's awful but I'm not coming back to sort that. Life's too short :-)

2020-12-18 - Operation Order

Day 18 input is a sequence of calculations (mine is here) involving integers, + and * operators and parenthesised expressions. Part 1 involves finding the sum of these calculations, assuming they have a simple left-to-right order of evaluation. Part 2 involves the same except assuming + has higher precedence than *.

2020-12-17 - Conway Cubes

Day 17 input is a 2D plane showing active ("#") and inactive (".") cubes (mine is here) which is part of an infinite 3D grid. There are rules like Conway's "game of life" which determine how each of these cubes changes over time (becomes active/inactive). Part 1 involves running this over 6 iterations. Part 2 involves running this over 6 interations in four dimensions. I wish I had time to make a visualization of this, I think it could be cool.

2020-12-16 - Ticket Translation

Day 16 is about numbers present on flight tickets. In the input (mine is here) you're given a set of ticket fields and the valid numbers they can have, your own ticket (a bunch of comma-separated integers) and a list of nearby tickets (many lines of comma-separated integers). You don't know which fields correspond to which part of the ticket. Part 1 involves applying some validation to input to find tickets which don't satisfy ANY rules, and returning the sum of their values. Part 2 obviously involves trying to map the ticket fields to the index they have in the comma-separated list of ticket numbers, finding the ones relating to the "departure" fields in your own ticket and multiplying them together.

2020-12-15 - Rambunctious Recitation

Day 15 puzzle input is a comma-separated sequence of integers (mine is here) which represent the first few numbers spoken as part of an elf memory game. Part 1 involves playing the game until turn 2020 - and the last number spoken is the answer. Part 2 involves running the game for 30 million turns, and the last number spoken is the answer.

2020-12-14 - Docking Data

Day 14 puzzle input is a sequence of assembly-like instructions (mine is here) which can be either writes to memory locations or adjustments of a "mask" register. Part 1 involves interpreting the mask as modifying the values being written to memory (0 and 1 set the bits in those positions, X is ignored). Part 2 involves interpreting the mask as modifying the memory address being written, with "X"s being wildcards meaning both 0 and 1 (so one write instruction can result in multiple addresses being modified).

2020-12-13 - Shuttle Search

Day 13 puzzle input is a starting timestamp followed by a comma-separated list of integers representing a bus schedule (mine is here). Part 1 involves finding the first bus to arrive after the given timestamp. As soon as I saw this puzzle I knew Part 2 would be a pain in the arse, and it was. So we basically needed to find the first timestamp where the buses would arrive at a given order.

2020-12-12 - Rain Risk

Day 12 puzzle input is a sequence of instructions consisting of an action (N, S, E, W, L, R, F) and an integer quantity (mine is here) whose meanings should be self evident. Part 1 involves assuming you're starting at (0,0) and facing East and moving according to the rules, and finding manhattan distance to the starting position. Part 2 involves interpreting the actions slightly different (N, S, E, W move a "waypoint" around. R and L rotate the waypoint around the user, and F moves forward in multiples of the distance between you and the waypoint) then finding the manhattan distance to the starting position.

2020-12-11 - Seating System

Day 11 puzzle input is a grid (mine is here) representing a seating layout - where "L" indicates an empty seat, "#" indicates an occupied seat and "." indicating no seat whatsoever. There are some rules given as to when a seat changes from occupied to empty, and vice versa over a given time-step. Part 1 applying the rules to the grid until no changes occur and finding the number of occupied seats at that steady state. Part 2 involves doing the same with some small modifications to the rules.

WARNING: I produce an animated gif showing the seats getting filled and emptied over time, it turns out that this results in some quite vivid flashing imagery. If you have epilepsy or anything else that may be triggered by flashing, you may want to avoid checking this solution out.

2020-12-10 - Adapter Array

Day 10 is a sequence of integers (mine is here) which represent some output "joltage" of a given adapter, which it can successfully produce if it receives an input "joltage" of at most 3 less than the output. Part 1 involves sorting the joltage of each adapter, finding the differences between each, collecting the occurence of each difference and multiplying the number of those with difference 1 with those of difference 3. Part 2 involves finding the number of valid combinations of each adapter, such that we can be taken from the beginning joltage of 0 to the final output one.

2020-12-09 - Encoding Error

Day 9 is a sequence of integers (mine is here) which represent some data that has been encoded with some kind of cipher. Part 1 involves identifying a weakness in the cipher, by locating the first number in the sequence that isn't the sum of any digits in the previous 25. Part 2 involves finding a run of >1 consecutive numbers which sum to the number identified in Part 1, and adding the smallest and largest values in this sequence.

2020-12-08 - Handheld Halting

Day 8 is a simple assembly-code like program (mine is here) which can execute one of three operations (nop, acc and jmp). Part 1 involves interpreting the program and finding the value of the accumulator register at the point that it begins to enter an infinite loop. Part 2 involves "fixing" one of the instructions - swapping a nop to a jmp or vice versa - such that the program doesn't hit an infinite loop, but instead runs to the end of the program.

2020-12-07 - Handy Haversacks

Day 7 puzzle input is a list of descriptions of coloured bags and what colours of bags they can contain (mine is here). Part 1 involve s finding all the bag colours that may directly or indirectly contain a "shiny gold" bag. Part 2 involves finding the total number of bags that are inside a "shiny gold" bag.

2020-12-06 - Custom Customs

Day 6 puzzle input is a list of positive responses to customs declaration questions for groups of travellers, with each group separated by a blank line (mine is here). Part 1 involves counting the number of questions that anyone in the group answered "yes" to, collecting the sum of these for each group and summing them. Part 2 is similar but for where all members of a group answered in the affirmative.

2020-12-05 - Binary Boarding

Day 5 puzzle input is a list of 10-character strings (mine is here) representing a Boarding Pass, which can be processed to calculate a "seat id" through a calculation neatly described in the link but which I can't be bothered repeating here. Part 1 involves calculating the seat ids for all boarding passes and finding the largest one. Part 2 involves finding a gap in the sequence of seat ids which turns out to be "my" seat.

2020-12-04 - Passport Processing

Day 4 puzzle input is a set of data representing attributes of identification documents - possibly passports - with each document terminated by a blank line (mine is here). Part 1 involves parsing the input and returning the number of these documents which contain all of the required fields. Part 2 involves taking these parsed documents and applying some more detailed validation to each document's attributes and counting how many documents pass all validation.

2020-12-03 - Toboggan Trajectory

Day 3 puzzle input is a grid of "#" and "." characters representing a toboggan run dotted with trees, where "#" is a tree (mine is here). Part 1 involves traversing the toboggan run by advancing one row and three columns at a time, and counting how many trees you encounter (hit?). The pattern of trees repeats to the right forever. Part 2 involves traversing the toboggan run by a number of different row/column increments, and multiplying together the number of trees you encounter for each.

2020-12-02 - Password Philosophy

Day 2 puzzle input is a list of password policy and password pairs (mine is here). Part 1 involves returning the number of passwords valid according to the policy (where x-y c: pass means "between x and y occurrences of the character c are in password pass"). Part 2 is broadly similar, but with a with slightly different policy logic (x-y c: pass means "either pass[x-1]==c XOR pass[y-1]==c")

2020-12-01 - Report Repair

Day 1 puzzle input is a list of integers which represent expenses (mine is here). Part 1 involves finding a pair of these which sums to 2020 and returning the value of them multiplied together. Part 2 is the exact same but for triples instead of pairs.