const std = @import("std"); const Io = std.Io; const shared = @import("shared.zig"); const print = shared.print; pub fn main(init: std.process.Init) !void { try shared.sharedInit(init); const allocator: std.mem.Allocator = init.arena.allocator(); const bytes = shared.loadBytesArg(allocator); var l: shared.LineIter = .{}; var acc: i64 = 50; var part1: i64 = 0; var part2: i64 = 0; while (l.nextLine(bytes)) |line| { const c = line[0]; const r = std.fmt.parseInt(i64, line[1..line.len], 10) catch unreachable; if (c == 'R') { if (acc < 0 and acc + r >= 0) part2 += 1; acc += r; while (acc >= 100) { acc -= 100; part2 += 1; } } if (c == 'L') { if (acc > 0 and acc - r <= 0) part2 += 1; acc -= r; while (acc <= -100) { acc += 100; part2 += 1; } if (acc < 0) acc += 100; } if (acc == 0) part1 += 1; const x: u8 = if (c == 'R') '+' else '-'; print("{d}: '{s}' {d} {c} part1={d} acc={d} part2={d}", .{ l.line, line, r, x, part1, acc, part2 }); } print("answers: {d} {d}", .{ part1, part2 }); }