January 03, 2024

Solution for Advent of Code 2015 - Day 25: Let It Snow

Link to the puzzle text

Part 1

In this puzzle, a series of numbers is written on a diagonal pattern in a grid and we are asked to predict the number of a certain row and colum.

We are starting by calculating the number of iterations until we reach the target row/column. The pattern starts in the top left corner and writes diagonally from left to right. In each diagonal, the value of row + column - 1 stays constant and equals the current diagonal. Based on the diogonal number, we can calculate the area filled until now as completed diagonals*(completed diagonals + 1) / 2. We add the remaining numbers in this partially filled diagonal (this equals the column value) and get the number of iterations until now.

Finally we just run a loop this many times to get the answer.

completed_diagonal = row + column - 2
number_iterations = (completed_diagonal ** 2 + completed_diagonal) // 2
+ column

x = 20151125
for i in range(2, number_iterations+1):
x = (x * 252533) % 33554393 

Part 2

No part 2 for the last day, so were are done for 2015.

Link to my solutions

No comments:

Post a Comment