May 26, 2026

Solution for Codyssi 2025 - Cyclops Chaos

Link to the puzzle text

Part 1

In this puzzle, we have a 2-d grid of numbers. Each cell consists of a number between 1 and 9. We are asked to sum up all rows and columns individually and find the row or column with the lowest sum.

We are using the numpy functions for summing later on, so we are reading the input into a 2-D numpy array of integers. Once we have the array, we can get the row- and columns sums by calling the function .sum(axis=N) with N=0 for the rows and N=1 for the columns. This results in 2 one-dimensional arrays from which we take the lowest single element.

Part 2

In part 2, we treat the array as path costs and find the best path from the top-left corner to coordinate (15, 15). For entering a cell at coordinates (x,y) we need to pay the costs in the amount of the element at array position (x,y). Movement is only possible down or right.

For getting the total path costs, we are using dynamic programming. We are using a 2-D array to save the best path costs until now for each cell. Since we are only interested in the costs, not the exact path taken, we only need to save the costs. For both the cells in the topmost and leftmost row and column, we can calculate the costs directly. For any other cell, the costs of getting to an arbitrary cell is only determined by the costs of getting to the cell above or left to it. The minimum of both cells is the path we are taking:

for row in range(1, len(best_path)):
for col in range(1, len(best_path[0])):
best_path[row][col] = min(best_path[row - 1, col], best_path[row, col - 1]) + grid[row][col]  

Finally the answer is the element at coordinate (15, 15).

Part 3

In part 2, we should extend the search of part 2. We should now find the costs to the cell at the lower right corner. Movement is still only possible down and right.

We can reuse the previous function for dynamic programming. We introduced a parameter for the target cell. Since the computation is fast enough, we always calculate everything and just return the element at grid coordinate of the target cell. 

Link to my solutions

No comments:

Post a Comment