July 10, 2026

Solution for Codyssi 2025 - Challenging the Whirlpool

Link to the puzzle text

Part 1

In this puzzle, we have a instructions for a program made of three parts. The first part is the description of a 2d grid of integers numbers. The second part is a list of operations to perform. The third part is not required in this part of the puzzle.We should initialize the grid with the provided input and perform the operations one at a time. Possible operations are adding/subtracting/multiplying a number to all cells in a specific row/column or rotating a column/row. After each operation, we should make sure the result is in the range between 0 til 1073741824 by taking the modulo. Once done, we should return the row or column with the highest sum.

We start by reading in the values into a numpy array for easier handling. For performing the operations, we use regular expression to parse the lines into the operation name and the operands. While the numerical operations were straight forward, the rotating around a column or row needed the numpy function roll. Finally we take take row and column sums with the numpy function sum with different axis arguments and return the largest value out of them.

Part 2

In part 2, we use the third part of the input. These lines encode in which order the operations of the second part should be performed. There are three kinds of operations in this part: take selects the current operations, cycle moves the current operation to the end of the operation queue and act take the current operations and executes it, removing it from the queue. Again we should perform the operations in the second part and return the largest sum, but execute in the order encoded by the queue.

We read in the operations in a list and order them into an execution queue. Since the operations always act on the current element, we can ignore the take action. The other two either change the remaining instruction list or insert the first element of the instruction list into the execution queue. After the reordering, we supply the new instruction queue to the function performing the instructions from part 1 of the puzzle to get the result. 

Part 3

In part 3, we should loop over the third part of the input until the whole instruction list is reordered. Previously we used the action list only once, now we should repeat it until there is nothing left in the instruction list and everything is in the new execution queue.

We take the reordering function from part 2 of the puzzle, and repeat it several times. 

Link to my sol    utions

No comments:

Post a Comment