blob: 4facde27d16ebc6bf72818932cc615e9d0eac78b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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),
};
}
|