Advent of Code 2023 solution insights: # Day 10 # Part 1: # Find the path of the loop. The furthest point is length of the loop/2 # Part 2: # To decide if a point is inside or outside the loop, traverse along # a direction and check how many times it crosses the loop. If # it's odd, then it lies inside, else outside. # Day 12: # Part 1: Counting number of combinations. # Base cases: empty configuration, or empty counts # General case: Brake the configuration as you count for # possibilities (./? or #/? for the current character) # Part 2: Add memoization since the input is much larger # to avoid repeated computations # Day 14: # Part 1: # Simple moving of array elements to the end while keeping some fixed. # Part 2: # Is to perform the same movements multiple times and detect the repetition of patters. # once the period of repetition is detected, you can find out what it the pattern # would be at 1 billionth iteration. # Day 16 # Part 1: Simulate the path of light. Can be done using a # queue data structure. # Part 2: Try all the corners and check which one gives the best answer # Day 19 # In part 1: you need to go through the list first # and create a map of operations and what to # do if the operation failed. After that's done # you need to process the inputs and evaluate them # through the map. # In part 2: you only have to find the combinations # of the scores that would be accepted. Requires you # to go through the workflows and count the ranges # which are accepted. Brute force solution is not possible as # it will take too long (4000 ^ 4). # Day 20 # Part 1: It's a directed graph problem. the first step # is to create a graph representing the relationship between # the modules, once the graph is built process the pulses # with a queue. The tricky part is creating the data structure # that connects the modules. # Part 2: Find the modules which reach rx (assuming only one rx) # The trick here is to see the input data and find out that rx is # reachable by a conjuction module (&) which sends a low pulse # only when all it's inputs are high. So, you need to find the LCM # of the cycle lengths of the modules which is reachable by the conjuction # module which is reachable by rx. # Day 21 # Part 1: Standard DFS search, one thing to keep in mind is that # if there are even number of steps left the same position can be visited again. For # odd number of steps, that's not the case, so continue search. # Part 2: Looking at the input (square), you can see that the row and column of the starting position # is empty, and the last row/column is empty. This can be used to optimize the search. # The width of the input is also odd, which means that every alternative position cannot be # reached again. Also, the starting position is the middle of the grids. Find the number of steps for odd # points and the even points(where steps left is odd/even), the corners, top/bottom left and top/bottom right # and add them up. # Day 22 # Part 1: Form a relationship map between the bricks (which ones are supporing which, # create overlapping logic based on x, y of the bricks, and move the bricks to # the lowest point based on the overlap. Based on the relationship map, you can # figure out which bricks can be disintegrated safely # Part 2: Use the relationship map from part 1 to figure out number of bricks # that would be disintegrated for each brick. # Day 23 # Part 1: To find the longest path, some optimizations need to # be performed. First identify the paths where there are choices # te be made. By finding those points, you don't have to do # a search for every single point in the grid (edge contraction). Create a directed # graph from the start to all these points and store the distances. # then do a dfs from the start to the end keeping track of the max distance. # Part 2 : Part 2 relaxes some of the constraints with respect to the directions # that can be moved. The same approach as part 1 works with small modifications. # Day 24 # Part 1: Represent the path of the hail stones via a linear equation. With this # you can check if the paths are parallel, converge or diverge. # Part 2: Represent the paths for x, y, z via linear equations. To reduce time # taken to solve, solve for 1/3 of the hailstones. Take only the integer solutions. # Day 25 # Part 1: find the path for every pair of # node, the three most commonly used # nodes are the ones that keep the # graph together. Statistically chose the nodes # Once you remove the nodes connecting the graph, # remove them and find the number of connected # components of the independent graphs.