Advent of Code 2021
Solutions for 2021
Day 1 ⭐ ⭐
- How many numbers are bigger than the previous number?
- How many sums of three numbers are bigger than the previous three?
difffunction is very nicedifffunction has alagargument :)
Day 2 ⭐ ⭐
- Follow the forward, down, up instructions. Where do you end up?
- 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 ⭐ ⭐
- Find the ‘gamma’ and ‘epsilon’, calculating the most common bits in the columns.
- Finding the ‘oxygen’ and ‘carbon dioxide’ is a bit more difficult.
strtoiis the perfect function for this.- Determine each column sequentially, so, recursive function with colnum as input.
Day 4 ⭐ ⭐
- Which bingo card will win first?
- 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 ⭐ ⭐
- Calculate what is happening with some hydrothermal vents
- 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 ⭐ ⭐
- Find how many lanternfish there are after 80 days
- How many lanternfish are there after 256 days?
- Loop, apply the rules
- Again, loop again
Day 7 ⭐ ⭐
- The crabs needs to be aligned as efficiently as possible
- Efficiency is not linear, please still be efficient.
- Align with the median
- Align with the mean
- Math!
Day 8 ⭐ ⭐
- Check the digital displays, how often do 1,4,7,8 show up?
- 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 ⭐ ⭐
- Find the low points on the map
- 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 ⭐ ⭐
- Scrutinise some sequences of brackets and see which ones don’t close properly.
- 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 ⭐ ⭐
- Some octopi are flashing and interacting. How many flashes after 100 rounds?
- 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
- There is a system of small and large caves, how many paths are there?
Day 13 ⭐ ⭐
- Fold some dots in on itself, one time. How many dots?
- 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 ⭐
- Develop some polymers i.e. add some strings for letters.
- 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
- You can only move in two dimensions through the cave. What’s the best path?
- Decode the hexadecimal BITS in a long sequence of numbers.
Day 17 ⭐ ⭐
- Find the highest trajectory that lands in the box
- 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
- There are some weird bracket snailfish math numbers, what is their sum?
- You have some scanners finding some beacons. How many actually are there?
Day 20 ⭐
Day 22 ⭐
Day 23 ⭐