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
40
41
42
43
44
|
const std = @import("std");
const print = std.debug.print;
const day01 = @import("src/day01.zig");
const day02 = @import("src/day02.zig");
const day03 = @import("src/day03.zig");
const day04 = @import("src/day04.zig");
const day05 = @import("src/day05.zig");
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.fmt.parseInt(usize, args[1], 10) catch {
print("Not valid day format\n: {s}", .{args[1]});
return;
};
try switch (day) {
1 => day01.solve(args[2], buffer, allocator),
2 => day02.solve(args[2], buffer),
3 => day03.solve(args[2], buffer, allocator),
4 => day04.solve(args[2], buffer, allocator),
5 => day05.solve(args[2], buffer, allocator),
else => print("Day not yet implemented", .{}),
};
}
|