Advent of Code 2021

Solutions for 2021

Day 1 ⭐ ⭐

  1. How many numbers are bigger than the previous number?
  2. How many sums of three numbers are bigger than the previous three?
  • diff function is very nice
  • diff function has a lag argument :)

Day 2 ⭐ ⭐

  1. Follow the forward, down, up instructions. Where do you end up?
  2. Actually, the instructions are different. Where do you end up?
  • Use a tibble rather than a loop, and sum the columns, because it’s linear
  • Similar, but a couple of extra steps, because it’s cumulative

Day 3 ⭐ ⭐

  1. Find the ‘gamma’ and ‘epsilon’, calculating the most common bits in the columns.
  2. Finding the ‘oxygen’ and ‘carbon dioxide’ is a bit more difficult.
  • strtoi is the perfect function for this.
  • Determine each column sequentially, so, recursive function with colnum as input.

Day 4 ⭐ ⭐

  1. Which bingo card will win first?
  2. We should let the giant squid win, which card will win last?
  • Lots of preparation and calculation and checking functions for this
  • We have to go through all the numbers to see which one is last
  • I don’t think there’s any way around this, there’s no secret

Day 5 ⭐ ⭐

  1. Calculate what is happening with some hydrothermal vents
  2. Calculate what is happening with all the hydrothermal vents
  • Create a matrix and add 1 to all the plumes
  • Do the same thing with all the diagonals as well

Day 6 ⭐ ⭐

  1. Find how many lanternfish there are after 80 days
  2. How many lanternfish are there after 256 days?
  • Loop, apply the rules
  • Again, loop again

Day 7 ⭐ ⭐

  1. The crabs needs to be aligned as efficiently as possible
  2. Efficiency is not linear, please still be efficient.
  • Align with the median
  • Align with the mean
  • Math!

Day 8 ⭐ ⭐

  1. Check the digital displays, how often do 1,4,7,8 show up?
  2. What is the sum of all the output?
  • These are numbers with certain amounts of segments.
  • We have to figure out what those segments mean, through a series of functions

Day 9 ⭐ ⭐

  1. Find the low points on the map
  2. Find all the areas that are low
  • check to see if the current cell is the lowest of the surrounding cells
  • Start with the lowest points and then progressively add more points to the groups.
  • There could be an easier way to do this but I’m not sure how.
  • And with a chart as well!

Day 10 ⭐ ⭐

  1. Scrutinise some sequences of brackets and see which ones don’t close properly.
  2. Complete the improper strings of brackets
  • Function removes good brackets, until we make no more substitutions, and get the first closing bracket
  • Remove nice pairs, and then find what we need to close the brackets

Day 11 ⭐ ⭐

  1. Some octopi are flashing and interacting. How many flashes after 100 rounds?
  2. The interactions mean eventually they will all flash at once. When is that?
  • A function to handle the interactions, and a loop for 100
  • Check how many flashes there are, and keep those guys flashing

Day 12

  1. There is a system of small and large caves, how many paths are there?

Day 13 ⭐ ⭐

  1. Fold some dots in on itself, one time. How many dots?
  2. Keep folding, and you will be left with some letters
  • Don’t worry about drawing a grid, just reduce the numbers.
  • Keep reducing, and then make an array out of the dots.

Day 14

  1. Develop some polymers i.e. add some strings for letters.
  2. How many letters are there after a seemingly short but actually quite long (exponential) time?
  • Ten steps is not that long but turns out that 40 steps is very long

Day 15

  1. You can only move in two dimensions through the cave. What’s the best path?

Day 16

  1. Decode the hexadecimal BITS in a long sequence of numbers.

Day 17 ⭐ ⭐

  1. Find the highest trajectory that lands in the box
  2. How many trajectories land in the box?
  • This could probably be solved in a nicer way than what I did, but I got there
  • Three of the x velocities gave the same max height which is cool but also probably mathematical
  • Part one you were only shooting up but part two you can shoot down as well

Day 18

  1. There are some weird bracket snailfish math numbers, what is their sum?

Day 19

  1. You have some scanners finding some beacons. How many actually are there?

Day 20

Day 21

Day 22

Day 23

Day 24

Day 25