From 1c2490f5f2c9419ddb5035fc3a8967beef691e6c Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Mon, 2 Dec 2024 23:38:23 +0100 Subject: solutions day1 and day2 --- main.zig | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 main.zig (limited to 'main.zig') diff --git a/main.zig b/main.zig new file mode 100644 index 0000000..4facde2 --- /dev/null +++ b/main.zig @@ -0,0 +1,39 @@ +const std = @import("std"); +const print = std.debug.print; + +const day01 = @import("src/day01.zig"); +const day02 = @import("src/day02.zig"); + +const Day = enum { day01, day02 }; + +pub fn main() !void { + if (std.os.argv.len != 3) { + print("Usage: {s} < \n", .{std.os.argv[0]}); + return; + } + + const stdin = std.io.getStdIn(); + + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + const allocator = gpa.allocator(); + defer { + _ = gpa.deinit(); + } + + const stat = try stdin.stat(); + const buffer = try stdin.readToEndAlloc(allocator, stat.size); + defer allocator.free(buffer); + + const args = try std.process.argsAlloc(allocator); + defer std.process.argsFree(allocator, args); + + const day = std.meta.stringToEnum(Day, args[1]) orelse { + print("Not valid day or day not yet implemented\n: {s}", .{args[1]}); + return; + }; + + try switch (day) { + .day01 => day01.solve(args[2], buffer, allocator), + .day02 => day02.solve(args[2], buffer), + }; +} -- cgit v1.2.3