summaryrefslogtreecommitdiff
path: root/main.zig
diff options
context:
space:
mode:
authorXander Bil <xander@biltopia.org>2024-12-02 23:38:23 +0100
committerXander Bil <xander@biltopia.org>2024-12-02 23:38:23 +0100
commit1c2490f5f2c9419ddb5035fc3a8967beef691e6c (patch)
tree0dd2cb0a588e5fff69d7002585ace9bc81099fb4 /main.zig
downloadaoc2024-1c2490f5f2c9419ddb5035fc3a8967beef691e6c.tar.xz
aoc2024-1c2490f5f2c9419ddb5035fc3a8967beef691e6c.zip
solutions day1 and day2
Diffstat (limited to 'main.zig')
-rw-r--r--main.zig39
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),
+ };
+}