1const std = @import("std");
2const day1 = @import("./day1.zig");
3const day2 = @import("./day2.zig");
4const day3 = @import("./day3.zig");
5
6pub fn main() !void {
7 var args = std.process.args();
8 _ = args.skip();
9
10 const day_str = args.next() orelse {
11 std.debug.print("Needs day arg\n", .{});
12 std.process.exit(0);
13 };
14
15 const test_str = args.next() orelse "";
16
17 var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
18 const allocator = gpa.allocator();
19
20 const day = try std.fmt.parseInt(u4, day_str, 10);
21
22 const input_path = try std.fmt.allocPrint(allocator, "inputs/day{d}{s}.txt", .{ day, test_str });
23 defer allocator.free(input_path);
24
25 const input_file = try std.fs.cwd().openFile(input_path, .{});
26 defer input_file.close();
27
28 var buf: [4096]u8 = undefined;
29
30 var reader = input_file.reader(&buf);
31 const input_content = try reader.interface.allocRemaining(allocator, .unlimited);
32 defer allocator.free(input_content);
33
34 switch (day) {
35 1 => try day1.run(input_content),
36 2 => try day2.run(input_content),
37 3 => try day3.run(input_content),
38 else => {},
39 }
40}