From 0c43f32a9349a2c7fbec3b42e3791a4e8fdcfe53 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Tue, 10 Dec 2024 20:30:02 +0100 Subject: make day10 brrrrr --- src/day10.zig | 18 ++++++------------ 1 file 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}); -- cgit v1.2.3