April 06, 2025

Solution for Advent of Code 2018 - Day 11: Chronal Charge

Link to the puzzle text

Part 1

In this puzzle we have instructions on how to build a 300x300 array of numbers. We should find the 3x3 square in it with the highest total sum.

After constructing the field, we build another array sum_table, where the coordinates (x,y) are the total sum from (1,1) to the point.(x,y).

This allows us to calculate the total sum of a square starting at (x,y) by 

    sum_table(x,y) + sum_table(x + 3, y + 3) - sum_table(x + 3, y) - sum_table(x, y + 3)

We can then loop through all starting coordinates and find the largest 3x3 square.

Part 2 

In part 2, there is no longer a size restriction on the square. We still have to find the square with the largest total sum, but it can no be between 1x1 and 300x300.

We could reuse the sum_table from before, but now it also loop through all possible sizes.

Link to my solutions

No comments:

Post a Comment