summaryrefslogtreecommitdiff
path: root/day-2/util
diff options
context:
space:
mode:
authorChristian Segundo2022-12-03 19:28:32 +0100
committerChristian Segundo2022-12-03 19:28:32 +0100
commitee6c6e975dabc6c14f7e8e62e2de1551a431cc7a (patch)
tree834829061b796f3e6168ec1d6b7e1e8ff4469934 /day-2/util
parent78fa87cd43cd18f2f9ec4a04c45bcb8036143fd8 (diff)
downloadadvent-of-zig-2022-ee6c6e975dabc6c14f7e8e62e2de1551a431cc7a.tar.gz
refactor to use a meta test
Diffstat (limited to 'day-2/util')
l---------day-2/util1
-rw-r--r--day-2/util/file.zig15
-rw-r--r--day-2/util/mem.zig17
3 files changed, 1 insertions, 32 deletions
diff --git a/day-2/util b/day-2/util
new file mode 120000
index 0000000..40c3fc5
--- /dev/null
+++ b/day-2/util
@@ -0,0 +1 @@
+../util \ No newline at end of file
diff --git a/day-2/util/file.zig b/day-2/util/file.zig
deleted file mode 100644
index 90849e9..0000000
--- a/day-2/util/file.zig
+++ /dev/null
@@ -1,15 +0,0 @@
-const std = @import("std");
-
-/// Reads an entire file into memory, caller owns the returned slice.
-pub fn slurp(allocator: std.mem.Allocator, file_path: []const u8) ![]u8 {
- var path_buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
- const path = try std.fs.realpath(file_path, &path_buffer);
-
- const file = try std.fs.openFileAbsolute(path, .{});
- defer file.close();
-
- return try file.readToEndAlloc(
- allocator,
- (try file.stat()).size,
- );
-}
diff --git a/day-2/util/mem.zig b/day-2/util/mem.zig
deleted file mode 100644
index 89ba67b..0000000
--- a/day-2/util/mem.zig
+++ /dev/null
@@ -1,17 +0,0 @@
-const std = @import("std");
-const math = std.math;
-
-/// Returns the position of the smallest number in a slice.
-pub fn min_idx(comptime T: type, slice: []const T) usize {
- var best = slice[0];
- var idx: usize = 0;
-
- for (slice[1..]) |item, i| {
- const possible_best = math.min(best, item);
- if (best > possible_best) {
- best = possible_best;
- idx = i + 1;
- }
- }
- return idx;
-}