diff options
author | Xander Bil <xander@biltopia.org> | 2024-12-10 20:30:02 +0100 |
---|---|---|
committer | Xander Bil <xander@biltopia.org> | 2024-12-10 20:30:02 +0100 |
commit | 0c43f32a9349a2c7fbec3b42e3791a4e8fdcfe53 (patch) | |
tree | 6f576df3b8931728cbb021c86d0667b044a7c3ea /src/day10.zig | |
parent | 2cb1933700edd3af17dabedeff37b18dbaa0e07d (diff) | |
download | aoc2024-0c43f32a9349a2c7fbec3b42e3791a4e8fdcfe53.tar.xz aoc2024-0c43f32a9349a2c7fbec3b42e3791a4e8fdcfe53.zip |
make day10 brrrrr
Diffstat (limited to 'src/day10.zig')
-rw-r--r-- | src/day10.zig | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/day10.zig b/src/day10.zig index b72c9e3..13bed52 100644 --- a/src/day10.zig +++ b/src/day10.zig @@ -139,17 +139,14 @@ fn part2(buffer: []const u8, allocator: std.mem.Allocator) !void { } var out: i32 = 0; + const lookup: [][]i32 = try allocator.alloc([]i32, width); + 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) { - var lookup: [][]i32 = try allocator.alloc([]i32, width); - defer allocator.free(lookup); - - for (0..width) |i| { - lookup[i] = try allocator.alloc(i32, width); - @memset(lookup[i], 0); - } - out += try dfs2( lookup, grid, @@ -157,15 +154,12 @@ fn part2(buffer: []const u8, allocator: std.mem.Allocator) !void { @intCast(c), -1, ); - - for (0..width) |i| { - allocator.free(lookup[i]); - } } } } for (0..width) |i| { + allocator.free(lookup[i]); allocator.free(grid[i]); } print("{d}\n", .{out}); |