ONQOGY2EUWGA5ATHOESEQHAQJLBSNPX7MAHY53SOC3R2IPXSVJ6AC test {_ = @import("day01.zig");}
const std = @import("std");const aoc2020 = struct {const day01 = @import("day01.zig");};const days = 1;pub fn main() anyerror!void {var timer = try std.time.Timer.start();var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);defer arena.deinit();var buffer = std.io.bufferedWriter(std.io.getStdOut().writer());const stdout = buffer.writer();try stdout.print("{s:<8}{s:>20}{s:>20}\n", .{"Day", "Result", "Time"});comptime var day: u5 = 0;inline while (day < days) : (day += 1) {comptime var buf: [5]u8 = undefined;const day_str = comptime try std.fmt.bufPrint(&buf, "day{d:0>2}", .{day + 1});timer.reset();const first_res = @field(aoc2020, day_str).first(arena.allocator()) catch unreachable;const first_time = timer.read() / std.time.ns_per_us;try stdout.print("{s}a: {d:>20}{d:>20} us\n", .{ day_str, first_res, first_time });if (day < 24) {timer.reset();const second_res = @field(aoc2020, day_str).second(arena.allocator()) catch unreachable;const second_time = timer.read() / std.time.ns_per_us;try stdout.print("{s}b: {d:>20}{d:>20} us\n", .{ day_str, second_res, second_time });}}try buffer.flush();}
const std = @import("std");const PATH = "../input/day01.txt";const MAX_LINES = 200;pub fn first(allocator: ?std.mem.Allocator) anyerror!usize {_ = allocator;const input = try parseInput();for (input) |item| {for (input) |elem| {if (item + elem == 2020) {return item * elem;}}}unreachable;}pub fn second(allocator: ?std.mem.Allocator) anyerror!usize {_ = allocator;const input = try parseInput();for (input) |item| {for (input) |elem| {for (input) |third| {if (item + elem + third == 2020) {return item * elem * third;}}}}unreachable;}fn parseInput() ![]usize {const file = @embedFile(PATH);var lines = std.mem.tokenize(u8, file, "\n");var ret: [MAX_LINES]usize = undefined;var counter: usize = 0;while (lines.next()) |line| : (counter += 1) {ret[counter] = try std.fmt.parseUnsigned(usize, line, 0);}return &ret;}test "day01a" {try std.testing.expectEqual(@as(usize, 482811), try first(std.testing.allocator));}test "day01b" {try std.testing.expectEqual(@as(usize, 193171814), try second(std.testing.allocator));}
1714196012561597185316091936200316481903124815251330128115731892156315001858176180213701708145313421830158016071848162616021919164015741414766158119241727194914063239571862135414271583106718631553192319906911372135718871485179912701743160114571723188812721600188013811413145227718661542169317601637167519751304132719851842125519151266194418241770139212591313154712931393189618281642197918711502154815087101786184513341362194020091271144819641676165418041835191019391298157217041841139915761164186810352621569163916691543161616581750176517181861135115311665177113481289875140814861275162515941816704180015641291123419811843138719381827188319111755135318081498141620061916141115391963187418981951129213661912136914781359185914211384153412831913179414941860131218691730151013191428170614321532
const std = @import("std");// number of days availableconst days = 1;pub fn build(b: *std.build.Builder) void {// Standard target options allows the person running `zig build` to choose// what target to build for. Here we do not override the defaults, which// means any target is allowed, and the default is native. Other options// for restricting supported target set are available.const target = b.standardTargetOptions(.{});// Standard release options allow the person running `zig build` to select// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.const mode = b.standardReleaseOptions();const exe = b.addExecutable("aoc2020", "src/main.zig");exe.setTarget(target);exe.setBuildMode(mode);exe.install();const run_cmd = exe.run();run_cmd.step.dependOn(b.getInstallStep());if (b.args) |args| {run_cmd.addArgs(args);}const run_step = b.step("run", "Run all solver");run_step.dependOn(&run_cmd.step);const exe_tests = b.addTest("src/main_test.zig");exe_tests.setTarget(target);exe_tests.setBuildMode(mode);const test_step = b.step("test", "Run unit tests");test_step.dependOn(&exe_tests.step);}
.git.DS_Store**/zig-cache/zig-out