Advent of Code
Advent of Code 2024, Day 5 Part 2
I wanted to write about this day, since I thought of a nice way to solve this, which is the first time I’ve actually used this algorithm outside of class.
I’ll give a bit of a teaser: Topological Sort.
Problem
Go check out the real website, https://adventofcode.com/2024/day/5 for a full picture, but I’ll try to give as concise of a summary as possible.
Your Input
- You are given a set of rules, like
a|b
, meaning numbera
must come before numberb
- You are given a few arrays of numbers, and
- For Part 1, you must sum the middle number of all arrays that conform to the above set of rules.
- For Part 2, you must sort the invalid arrays and find the sum of their middle numbers.
Solution
Context You are only given the first problem until you solve the second one.