AoC Day One Spoilers Ahead!
I’m trying to answer AoC Day 1, and I know the solution in my head, but I’m having a hard time getting the types right. I wrote up, almost line for line(!) this solution: AoC 2025: Day 1 - #6 by guidoschmidt , here are some of the relevant lines:
const max = 100;
var dial: i32 = 50;
// ...
const sign: i32 = if (row[0] == 'L') -1 else 1;
// ...
dial += sign;
dial = @mod(dial, max);
Now I know why the author made dial a signed integer, but it shouldn’t be, right? The dial can hold positions 0 - 99, those are all signed integers. I’m trying to find the most elegant, and zig-idiomatic way to type these variables such that the math is clear (without a thousand @casts), and the types are semantic (dial should be u7). Any ideas?