aoc2025 @ abd28ba4a4eee1af0f95ed69f4322389923f6b45

  1diff --git a/build.zig b/build.zig
  2index a2c95a1b24be84341ee23c8894c471f414898382..81cd3afc991dfa73518b812c85fd668b3b02860d 100644
  3--- a/build.zig
  4+++ b/build.zig
  5@@ -9,7 +9,6 @@         .name = "aoc2024",
  6         .root_module = b.createModule(.{
  7             .root_source_file = b.path("src/main.zig"),
  8             .target = target,
  9-            .link_libc = false,
 10             .optimize = optimize,
 11             .single_threaded = true,
 12         }),
 13diff --git a/src/day3.zig b/src/day3.zig
 14new file mode 100644
 15index 0000000000000000000000000000000000000000..611da9e689a588d3c19cd0e6f057f897e4f78066
 16--- /dev/null
 17+++ b/src/day3.zig
 18@@ -0,0 +1,75 @@
 19+const std = @import("std");
 20+
 21+pub fn pt1(input: []const u8) u64 {
 22+    var counter: u64 = 0;
 23+
 24+    var lines = std.mem.splitScalar(u8, input, '\n');
 25+
 26+    while (lines.next()) |l| {
 27+        if (l.len == 0) return counter;
 28+
 29+        var buff_line: [100]u8 = undefined;
 30+        parseLine(&buff_line, l);
 31+        counter += calcJolts(2, &buff_line);
 32+    }
 33+
 34+    return counter;
 35+}
 36+
 37+pub fn pt2(input: []const u8) u64 {
 38+    var counter: u64 = 0;
 39+
 40+    var lines = std.mem.splitScalar(u8, input, '\n');
 41+
 42+    while (lines.next()) |l| {
 43+        if (l.len == 0) return counter;
 44+
 45+        var buff_line: [100]u8 = undefined;
 46+        parseLine(&buff_line, l);
 47+        counter += calcJolts(12, &buff_line);
 48+    }
 49+
 50+    return counter;
 51+}
 52+
 53+fn parseLine(buff_line: []u8, line: []const u8) void {
 54+    for (0..line.len, line) |i, l| {
 55+        const d = l - '0';
 56+        buff_line[i] = d;
 57+    }
 58+}
 59+
 60+fn calcJolts(n: usize, js: []const u8) u64 {
 61+    var counter: u64 = 0;
 62+    var index: usize = 0;
 63+    for (0..n) |p| {
 64+        var inner_index = index;
 65+
 66+        // plus one to fix disparity between index (starts at 0) and size
 67+        const upper_bound = js.len - (n - p) + 1;
 68+        for (index..upper_bound) |i| {
 69+            if (js[inner_index] < js[i]) inner_index = i;
 70+        }
 71+
 72+        // the amounts of zeros is inverse to the position of p in relation to
 73+        // size. At p=0 we have the maximum numbers of zero n. At p=n-1, which
 74+        // p reached its maximum value, pow(10,0) which is 1 (thanks math for
 75+        // helping with the edge case).
 76+        const res = js[inner_index] * std.math.pow(u64, 10, n - p - 1);
 77+
 78+        counter += res;
 79+        index = inner_index + 1; // don't forget to advance index.
 80+    }
 81+
 82+    return counter;
 83+}
 84+
 85+test "Day 3 par 1" {
 86+    const res = pt1(@embedFile("./input/day3"));
 87+    try std.testing.expect(res == 17311);
 88+}
 89+
 90+test "Day 3 par 2" {
 91+    const res = pt2(@embedFile("./input/day3"));
 92+    try std.testing.expect(res == 171419245422055);
 93+}
 94diff --git a/src/input/day3 b/src/input/day3
 95new file mode 100644
 96index 0000000000000000000000000000000000000000..98c171568b84dc3e4111e407cc1c8d45c940bc27
 97Binary files /dev/null and b/src/input/day3 differ
 98diff --git a/src/main.zig b/src/main.zig
 99index a4db764ce025c1f5602895b2bd39383d4d53333f..93f82e0a5b5b0ae9e893ad93f303fc42e4b68ca7 100644
100--- a/src/main.zig
101+++ b/src/main.zig
102@@ -1,17 +1,24 @@
103 const std = @import("std");
104 const day1 = @import("day1.zig");
105 const day2 = @import("day2.zig");
106+const day3 = @import("day3.zig");
107 
108 pub export fn main() void {
109     for (1..std.os.argv.len) |i| {
110         const day = std.mem.span(std.os.argv[i]);
111 
112         if (std.mem.eql(u8, "day1", day)) {
113-            print(day1.pt1(@embedFile("./input/day1")));
114-            print(day1.pt2(@embedFile("./input/day1")));
115+            const input = @embedFile("./input/day1");
116+            print(day1.pt1(input));
117+            print(day1.pt2(input));
118         } else if (std.mem.eql(u8, "day2", day)) {
119-            print(day2.pt1(@embedFile("./input/day2")));
120-            print(day2.pt2(@embedFile("./input/day2")));
121+            const input = @embedFile("./input/day2");
122+            print(day2.pt1(input));
123+            print(day2.pt2(input));
124+        } else if (std.mem.eql(u8, "day3", day)) {
125+            const input = @embedFile("./input/day3");
126+            print(day3.pt1(input));
127+            print(day3.pt2(input));
128         }
129     }
130 }