2022-12-01 17:46:44 +00:00
|
|
|
const std = @import("std");
|
|
|
|
|
2022-12-01 18:13:35 +00:00
|
|
|
const day01 = @import("day01.zig");
|
2022-12-02 06:05:23 +00:00
|
|
|
const day02 = @import("day02.zig");
|
2022-12-01 23:12:39 +00:00
|
|
|
const utils = @import("utils.zig");
|
2022-12-01 17:46:44 +00:00
|
|
|
|
2022-12-02 15:49:37 +00:00
|
|
|
fn solve_day(comptime day_num: u8, day: anytype, stdout: anytype, timer: *std.time.Timer) !void {
|
|
|
|
try stdout.print("Day {}\n", .{day_num});
|
|
|
|
|
|
|
|
const part1_start = timer.read();
|
|
|
|
var part1 = try day.solve_part1(day.input);
|
|
|
|
const part1_end = timer.read();
|
|
|
|
const part1_time = utils.HumanTime.new(part1_end - part1_start);
|
|
|
|
try stdout.print("Part 1: {} ({d:.2} {s})\n", .{ part1, part1_time.value, part1_time.unit.abbr() });
|
|
|
|
|
|
|
|
const part2_start = timer.read();
|
|
|
|
var part2 = try day.solve_part2(day.input);
|
|
|
|
const part2_end = timer.read();
|
|
|
|
const part2_time = utils.HumanTime.new(part2_end - part2_start);
|
|
|
|
try stdout.print("Part 2: {} ({d:.2} {s})\n", .{ part2, part2_time.value, part2_time.unit.abbr() });
|
|
|
|
}
|
|
|
|
|
2022-12-01 18:13:35 +00:00
|
|
|
pub fn main() !void {
|
2022-12-01 17:46:44 +00:00
|
|
|
const stdout_file = std.io.getStdOut().writer();
|
|
|
|
var bw = std.io.bufferedWriter(stdout_file);
|
|
|
|
const stdout = bw.writer();
|
2022-12-01 23:12:39 +00:00
|
|
|
var timer = std.time.Timer.start() catch @panic("need timer to benchmark solutions");
|
2022-12-01 17:46:44 +00:00
|
|
|
|
2022-12-02 15:49:37 +00:00
|
|
|
try solve_day(1, day01, &stdout, &timer);
|
|
|
|
try solve_day(2, day02, &stdout, &timer);
|
2022-12-02 06:05:23 +00:00
|
|
|
|
2022-12-01 18:13:35 +00:00
|
|
|
try bw.flush();
|
2022-12-01 17:46:44 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 18:13:35 +00:00
|
|
|
test {
|
|
|
|
std.testing.refAllDecls(@This());
|
|
|
|
|
|
|
|
_ = day01;
|
2022-12-02 06:05:23 +00:00
|
|
|
_ = day02;
|
2022-12-01 23:12:39 +00:00
|
|
|
_ = utils;
|
2022-12-01 17:46:44 +00:00
|
|
|
}
|