diff options
Diffstat (limited to 'aoc/2021/10/part-one.zig')
-rw-r--r-- | aoc/2021/10/part-one.zig | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/aoc/2021/10/part-one.zig b/aoc/2021/10/part-one.zig index 27ac20c..130fc4a 100644 --- a/aoc/2021/10/part-one.zig +++ b/aoc/2021/10/part-one.zig @@ -1,4 +1,4 @@ -const Stack = @import("stack.zig").Stack; +const Stack = @import("Stack.zig"); const page_allocator = std.heap.page_allocator; const print = std.debug.print; const std = @import("std"); @@ -11,17 +11,17 @@ pub fn main() !void { if (line.len > max_len) max_len = line.len; } - var stack = try Stack(u8).alloc(page_allocator, max_len); + var stack = try Stack.alloc(page_allocator, max_len); defer stack.free(); var sum: usize = 0; defer print("{}\n", .{ sum }); input.reset(); - while (input.next()) |line| { + while (input.next()) |line| : (stack.reset()) for (line) |c| switch (c) { '(', '[', '{', '<' => stack.push(c), - else => if (stack.pop() ^ c > 6) { + else => if (stack.pop().? ^ c > 6) { sum += @as(usize, switch (c) { ')' => 3, ']' => 57, '}' => 1197, '>' => 25137, else => unreachable, @@ -29,6 +29,4 @@ pub fn main() !void { break; }, }; - stack.reset(); - } } |