diff options
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}); |