day 11
chronal charge
approach
the 300 × 300 grid of power levels is filled once from the serial number; the hundreds digit comes from (pl % 1000 - pl % 100) // 100. largest_of_size(k) sums every k × k square by brute force and returns the top-left corner and total of the best one.
the script then loops over sizes 2 to 99 and prints the best square for each size. part 1 is the size-3 line and part 2 is the best line overall, picked by eye. the search stops at size 99 rather than 300. the opening comment, "todo summed area!! no clue how though", names the faster approach it didn't get to.
the trick
sum every k × k window directly and compare sizes, assuming the best square is under 100 wide.
python
def largest_of_size(k):
values={}
for x in range(1,301-k):
for y in range(1,301-k):
s=0
for i in range(x,x+k):
for j in range(y,y+k):
s=s+grid[i][j]
values[(x,y)]=s