]> Skullheadx's Git Forge - Advent-of-Code.git/commitdiff
day1 part 2
authorSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Tue, 2 Dec 2025 03:24:51 +0000 (22:24 -0500)
committerSkullheadx <94652084+Skullheadx@users.noreply.github.com>
Tue, 2 Dec 2025 03:24:51 +0000 (22:24 -0500)
day1_test.txt [new file with mode: 0644]
day1_test2.txt [new file with mode: 0644]
src/main.zig

diff --git a/day1_test.txt b/day1_test.txt
new file mode 100644 (file)
index 0000000..53287c7
--- /dev/null
@@ -0,0 +1,10 @@
+L68
+L30
+R48
+L5
+R60
+L55
+L1
+L99
+R14
+L82
diff --git a/day1_test2.txt b/day1_test2.txt
new file mode 100644 (file)
index 0000000..58f243e
--- /dev/null
@@ -0,0 +1,2 @@
+L500
+L50
index 9995a7ce94d554eda4438acca149dc96d5467890..088b4da8daa74a53bdf4b4f91e0a0b65b668a44c 100644 (file)
@@ -23,16 +23,27 @@ pub fn main() !void {
         }
         // std.debug.print("{s}\n", .{chunk[1..]});
         const value = try std.fmt.parseInt(i32, chunk[1..], 10);
+        const d = @divTrunc(value, 100);
+        const r = @rem(value, 100);
+        std.debug.print("old_current:{} value:{s} d:{}, r:{} | ", .{ current, chunk, d, r });
         if (chunk[0] == 'L') {
+            if (r > 0 and current - r < 0 and current != 0) {
+                numZero += 1;
+            }
             current = @mod(current - value, 100);
         } else {
+            if (r > 0 and r + current > 100) {
+                numZero += 1;
+            }
             current = @mod(current + value, 100);
         }
+        numZero += d;
         if (current == 0) {
             numZero += 1;
         }
+        std.debug.print("current:{} numZero:{}\n", .{ current, numZero });
     }
     // Prints to stderr, ignoring potential errors.
-    std.debug.print("{}", .{numZero});
+    std.debug.print("{}\n", .{numZero});
     try aoc.bufferedPrint();
 }