summaryrefslogtreecommitdiff
path: root/main.zig
blob: 871eec20c5881300d1eae674ef69919b9ad10054 (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
40
41
42
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");

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),
        else => print("Day not yet implemented", .{}),
    };
}