From 061a5bae272f45db6dcde99746922735f9769d25 Mon Sep 17 00:00:00 2001 From: Christian Segundo Date: Mon, 5 Dec 2022 17:00:08 +0100 Subject: add day 5 --- day-1/main.zig | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 day-1/main.zig (limited to 'day-1/main.zig') diff --git a/day-1/main.zig b/day-1/main.zig deleted file mode 100644 index d985c9b..0000000 --- a/day-1/main.zig +++ /dev/null @@ -1,46 +0,0 @@ -const std = @import("std"); -const min_idx = @import("util/mem.zig").min_idx; - -pub fn puzzle_1(input: []const u8) !i32 { - var iter = std.mem.split(u8, input, "\n"); - var count: i32 = 0; - var max: i32 = 0; - - while (iter.next()) |line| { - if (line.len == 0) { - if (count > max) { - max = count; - } - count = 0; - } else { - count += try std.fmt.parseInt(i32, line, 0); - } - } - - return max; -} - -pub fn puzzle_2(input: []const u8) !i32 { - var iter = std.mem.split(u8, input, "\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; - } - - return count; -} -- cgit v1.2.3