From ee6c6e975dabc6c14f7e8e62e2de1551a431cc7a Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Sat, 3 Dec 2022 19:28:32 +0100 Subject: refactor to use a meta test --- day-1/main_1.zig | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 day-1/main_1.zig (limited to 'day-1/main_1.zig') diff --git a/day-1/main_1.zig b/day-1/main_1.zig deleted file mode 100644 index 5e502d3..0000000 --- a/day-1/main_1.zig +++ /dev/null @@ -1,34 +0,0 @@ -const std = @import("std"); -const slurp = @import("util/file.zig").slurp; -const min_idx = @import("util/mem.zig").min_idx; - -var gpa = std.heap.GeneralPurposeAllocator(.{}){}; -const allocator = gpa.allocator(); - -pub fn main() !void { - const file_buffer = try slurp(allocator, "./input"); - defer allocator.free(file_buffer); - - var iter = std.mem.split(u8, file_buffer, "\n"); - var count: i32 = 0; - var max: [3]i32 = std.mem.zeroes([3]i32); - - while (iter.next()) |line| { - if (line.len == 0) { - const lowest_u = min_idx(i32, &max); - if (count > max[lowest_u]) { - max[lowest_u] = count; - } - count = 0; - } else { - count += try std.fmt.parseInt(i32, line, 0); - } - } - - count = 0; - for (max) |v| { - count += v; - } - - std.debug.print("{d}\n", .{count}); -} -- cgit v1.2.3