summaryrefslogtreecommitdiff
path: root/src/day10.zig
diff options
context:
space:
mode:
authorXander Bil <xander@biltopia.org>2024-12-12 01:53:37 +0100
committerXander Bil <xander@biltopia.org>2024-12-12 01:53:37 +0100
commit45bd0d906ecc1864c42402fd88288666ec4b46ab (patch)
treed652fd5ad0ade33985575dc755abc437c4d45357 /src/day10.zig
parent0c43f32a9349a2c7fbec3b42e3791a4e8fdcfe53 (diff)
downloadaoc2024-45bd0d906ecc1864c42402fd88288666ec4b46ab.tar.xz
aoc2024-45bd0d906ecc1864c42402fd88288666ec4b46ab.zip
add day11 solution
Diffstat (limited to 'src/day10.zig')
-rw-r--r--src/day10.zig32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/day10.zig b/src/day10.zig
index 13bed52..a0eb88d 100644
--- a/src/day10.zig
+++ b/src/day10.zig
@@ -125,16 +125,19 @@ fn part2(buffer: []const u8, allocator: std.mem.Allocator) !void {
@memset(grid[i], 0);
}
+ var list = std.ArrayList(std.meta.Tuple(&.{ usize, usize })).init(allocator);
+ defer list.deinit();
+
var row: usize = 0;
while (lines.next()) |line| {
if (line.len == 0) break;
for (line, 0..) |item, col| {
- if (item == '.') {
- grid[row][col] = 15;
- } else {
- grid[row][col] = item - '0';
+ grid[row][col] = item - '0';
+ if (item == '0') {
+ try list.append(.{ row, col });
}
}
+
row += 1;
}
@@ -143,19 +146,16 @@ fn part2(buffer: []const u8, allocator: std.mem.Allocator) !void {
for (0..width) |i| {
lookup[i] = try allocator.alloc(i32, width);
}
+
defer allocator.free(lookup);
- for (0..width) |r| {
- for (0..width) |c| {
- if (grid[r][c] == 0) {
- out += try dfs2(
- lookup,
- grid,
- @intCast(r),
- @intCast(c),
- -1,
- );
- }
- }
+ for (list.items) |zero| {
+ out += try dfs2(
+ lookup,
+ grid,
+ @intCast(zero[0]),
+ @intCast(zero[1]),
+ -1,
+ );
}
for (0..width) |i| {