Embedded file directly into the binary

This commit is contained in:
2024-12-08 19:00:05 +01:00
parent d2f66dc8e9
commit 2aa4647c25
16 changed files with 33 additions and 160 deletions
+2 -7
View File
@@ -1,5 +1,6 @@
const std = @import("std");
const print = std.debug.print;
const file = @embedFile("input");
const LookingFor = enum {
m,
@@ -10,14 +11,8 @@ const LookingFor = enum {
Y,
};
var file_buf: [1024 * 1024]u8 = undefined; // The file do 20kB, I give it 1MB
pub fn main() !void {
const file = try std.fs.cwd().openFile("day3/input", .{});
defer file.close();
const len = try file.readAll(&file_buf);
try std.testing.expectEqual(190604937, try parse(file_buf[0..len]));
try std.testing.expectEqual(190604937, try parse(file));
}
fn parse(input: []const u8) !u32 {
+2 -8
View File
@@ -1,5 +1,6 @@
const std = @import("std");
const print = std.debug.print;
const file = @embedFile("input");
const LookingFor = enum {
m_or_d,
@@ -16,15 +17,8 @@ const LookingFor = enum {
r_brace_do,
};
var file_buf: [1024 * 1024]u8 = undefined; // The file do 20kB, I give it 1MB
pub fn main() !void {
const file = try std.fs.cwd().openFile("day3/input", .{});
defer file.close();
const len = try file.readAll(&file_buf);
try std.testing.expectEqual(82857512, try parse(file_buf[0..len]));
try std.testing.expectEqual(82857512, try parse(file));
}
fn parse(input: []const u8) !u32 {