1const std = @import("std");
2const Allocator = std.mem.Allocator;
3
4pub fn run(_: Allocator, input: []u8) !struct { u64, u64 } {
5 var lines = std.mem.tokenizeScalar(u8, input, '\n');
6
7 var dial: u8 = 50;
8 var answer1: u64 = 0;
9 var answer2: u64 = 0;
10 while (lines.next()) |line| {
11 const direction: i2 = switch (line[0]) {
12 'L' => -1,
13 'R' => 1,
14 else => unreachable,
15 };
16 const turns = try std.fmt.parseInt(u16, line[1..], 10);
17
18 const new_rotation: i17 = dial + @as(i17, direction) * turns;
19
20 var zeroes_clicked: u64 = @intCast(@abs(@divTrunc(new_rotation, 100)));
21 if (dial != 0 and new_rotation <= 0) {
22 zeroes_clicked += 1;
23 }
24
25 dial = @intCast(@mod(new_rotation, 100));
26
27 if (dial == 0) {
28 answer1 += 1;
29 }
30
31 answer2 += zeroes_clicked;
32 }
33
34 return .{ answer1, answer2 };
35}