diff options
Diffstat (limited to 'main.zig')
-rw-r--r-- | main.zig | 39 |
1 files changed, 39 insertions, 0 deletions
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} <day> <part> < <input> \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), + }; +} |