2024-12-02 19:47:21 -05:00
|
|
|
const std = @import("std");
|
|
|
|
const print = std.debug.print;
|
|
|
|
|
|
|
|
pub fn readAllInput(day: u8, allocator: std.mem.Allocator) ![]const u8 {
|
|
|
|
var fileName: [16]u8 = undefined;
|
|
|
|
const inputFile = try std.fmt.bufPrint(&fileName, "day{d}.txt", .{day});
|
|
|
|
const file = try std.fs.cwd().openFile(inputFile, .{});
|
|
|
|
defer file.close();
|
|
|
|
const stat = try file.stat();
|
|
|
|
return try file.reader().readAllAlloc(allocator, stat.size);
|
|
|
|
}
|
2024-12-04 17:43:21 -05:00
|
|
|
|
|
|
|
pub fn inputToArrayList(comptime T: type, allocator: std.mem.Allocator, input: []const u8) !std.ArrayList(T) {
|
|
|
|
var out = std.ArrayList(T).init(allocator);
|
|
|
|
errdefer out.deinit();
|
|
|
|
var items = std.mem.tokenizeScalar(u8, input, ' ');
|
|
|
|
while (items.next()) |item| {
|
|
|
|
try out.append(try std.fmt.parseInt(T, item, 10));
|
|
|
|
}
|
|
|
|
return out;
|
|
|
|
}
|