diff options
Diffstat (limited to 'day04.zig')
-rw-r--r-- | day04.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/day04.zig b/day04.zig new file mode 100644 index 0000000..3c621b8 --- /dev/null +++ b/day04.zig @@ -0,0 +1,26 @@ +const std = @import("std"); +const data = @embedFile("day04"); + +pub fn main() !void { + var part1: i32 = 0; + var part2: i32 = 0; + + var lines = std.mem.split(u8, data, "\n"); + + while (lines.next()) |line| { + if (line.len == 0) + break; + + var parts = std.mem.tokenize(u8, line, ",-"); + + var a = try std.fmt.parseInt(i32, parts.next().?, 10); + var b = try std.fmt.parseInt(i32, parts.next().?, 10); + var c = try std.fmt.parseInt(i32, parts.next().?, 10); + var d = try std.fmt.parseInt(i32, parts.next().?, 10); + + if ((c - a) * (d - b) <= 0) part1 += 1; + if ((d - a) * (c - b) <= 0) part2 += 1; + } + + std.debug.print("{} {}\n", .{ part1, part2 }); +} |