December 27, 2025

Solution for Codyssi 2024 - Sensors and Circuits

Link to the puzzle text

Part 1

We are given a file with 512 boolean values in a file. Each value corresponds to one sensor with an id equal to the line in the file. We should find the sum of all sensor outputting true.

We used a list expression to get all sensor ids with true values and used sum to get the sum.

Part 2

In part 2, we should simulate a simple circuit. The sensors are grouped into pairs and alternative used as input for an AND and an OR gate. So sensors 1 and 2 are input for an AND, sensor 3 and 4 for an OR gate and so on. We should find the number of gates outputting true.

We wrote a function to simulate this circuit. The inputs are paired and depending on the gate index we use a different gate function. Finally the all gate outputs are returned and we count the number of true values.

Part 3

In part 3, we should repeat the previous circuit until only one value remains. During this computation, we should count the number of gates outputting true.

We reused the previously written function and always summed the number of true gates while there is still enough input left. The total sum was return as the final answer.

Link to my solutions

No comments:

Post a Comment