Was mainly working on refactoring my advent of code framework yesterday.
Didn’t have too much mental capacity yesterday left, so my solution is just stupidly iterating through the rotations, counting how often it sees a 0. Not the most elegant solution but it yielded the correct solution.
var row_it = std.mem.tokenizeSequence(u8, @embedFile("puzzle"), "\n");
const max = 100; // 0 - 99 = 100
var dial: i32 = 50;
var result: u32 = 0;
while (row_it.next()) |row| {
// parse 'L' as negative rotation
const sign: i32 = if (row[0] == 'L') -1 else 1;
const number = try std.fmt.parseInt(i32, row[1..], 10);
var change = sign * number;
while (change != 0) : (change += -1 * sign) {
dial += sign;
dial = @mod(dial, max);
if (dial == 0) result += 1;
}
}
std.debug.print("\nResult: {d}", .{result});