Day 1 - Trebuchet
- Get the number values from the string
- Concatenate the first and last to get the calibration value
- Sum all the calibration values
- Get the first numeric or written digit using regex
- Get the last numeric or written digit using regex and reversing
- Concatenate the first and last to get the calibration value
- Sum all the calibration values
Day 2 - Cube Conundrum
- Match the pattern
<quantity> <colour>
using regex - Loop through the game string and keep track of the largest values of each colour
- Count the number of possible games by checking the values of each colour don't exceed the maximum
- Match the game pattern - same as part 1
- Get the product of each game by multiplying the colour counts together
- Sum the products
Day 3 - Gear Ratios
- Pattern match to find numbers and symbols in a grid
- Identify the bounding box for each number
- Sum all the numbers where a symbol overlaps its bounding box
- Pattern match to find numbers and symbols in a grid
- Identify specifically the gear symbols
- If the gear overlaps a number's bounding box then keep track of it
- Filter out gears that only have 2 adjacent numbers
- Sum the products of each gear
Day 4 - Scratchcards
- Get all cards in a list of tuples
- Can work out the matches by getting the set intersection
- For each card add 2 ^ (number of matches - 1) to total points
- Answer is total points after all cards are processed
- Get all cards in a list of tuples
- Work out how many copies of each card there are
- Sum total number of cards after processing
Day 5 - If You Give A Seed A Fertilizer
- Build up the almanac with maps from seed -> soil -> ... -> location
- For each seed keep track of the lowest location value
- Answer is the lowest after all seeds have been processed
- Build up the almanac with maps
- Work out the input seed ranges using every 2 values (initial, range)
- Starting with 0 increase the location value until we find a match
- Reverse map from location -> seed and check if it intersects any input seed range
- Faster than processing all input seeds (~1.3 trillion inputs) but can take a couple of mins to finish
Day 6 - Wait For It
- Read in races by removing the prefixes and zipping the values together into a tuple
- Race wins calculated by checking all variations of time held
- Keep track of a count of wins for each race
- Calculate the product of the win count for each race
- Read in races by removing the prefixes and spaces (for the kerning error part) and zip the values together into a tuple
- Race wins calculated by checking all variations of time held
- Keep track of a count of wins
- Calculate the product of the win count for each race
- This takes about a minute to calculate this way
Day 7 - Camel Cards
- Use an enum for the HandType and class to store the hand data (cards + bid)
- Set up comparator functions to allow sort to work
- Sort in ascending order
- Sum the bid * placement for each card
- Add an optional wildcard parameter to the hand and HandType
- If the wildcard is set then reduce its individual value
- Calculate the best hand type by substituting in the wildcard
- Sort in ascending order
- Sum the bid * placement for each card
Day 8 - Haunted Wasteland
- Build the network graph using the input
- Traverse each node starting from AAA keeping track of the steps
- When the current node is ZZZ return the number of steps
- Build the network graph using the input
- Get all the starting nodes (nodes matching "??A")
- Traverse the graph using each start node and get the steps for each
- Calculate the LCM for the steps to get the number of steps to get all traversal to line up
- This solution relies on assumptions that the examples do not show so required reading the input itself to notice the pattern