aoc-2023/src/main.zig
2023-12-02 13:42:48 +02:00

36 lines
1.0 KiB
Zig

const std = @import("std");
const StringArray = std.ArrayList([]const u8);
const Day1 = @import("./day1.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer {
if (gpa.deinit() == .leak) @panic("Leaked memory");
}
var file = try std.fs.cwd().openFile("input.txt", .{});
defer file.close();
var buf_reader = std.io.bufferedReader(file.reader());
var reader = buf_reader.reader();
var lines = StringArray.init(allocator);
defer {
for (lines.items) |line| {
allocator.free(line);
}
lines.deinit();
}
var line_buf: [1024]u8 = undefined;
while (try reader.readUntilDelimiterOrEof(&line_buf, '\n')) |line| {
var trimmed_line = std.mem.trimRight(u8, line, &.{'\r'});
try lines.append(try allocator.dupe(u8, trimmed_line));
}
std.debug.print("day1: {d}\n", .{Day1.part1(lines.items)});
std.debug.print("day2: {d}\n", .{Day1.part2(lines.items)});
}