From 393f80f314c5b99afc3c567314b8df96d3d963bd Mon Sep 17 00:00:00 2001 From: ktkk Date: Fri, 12 Dec 2025 14:48:57 +0000 Subject: [PATCH] WIP: implement part 1 --- src/days/day12.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/days/day12.zig b/src/days/day12.zig index d940d18..17f6c7e 100644 --- a/src/days/day12.zig +++ b/src/days/day12.zig @@ -169,5 +169,50 @@ const Region = struct { } } } + + pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion { + return try .init(allocator, self.width, self.height); + } +}; + +const EmptyRegion = struct { + grid: [][]bool, + filled_spaces: usize, + + allocator: std.mem.Allocator, + + const Self = @This(); + + pub fn init(allocator: std.mem.Allocator, width: u8, height: u8) !Self { + const h = try allocator.alloc([]bool, height); + for (0..height) |i| { + const w = try allocator.alloc(u8, width); + @memset(w, false); + h[i] = w; + } + return .{ + .grid = h, + .filled_spaces = 0, + .allocator = allocator, + }; + } + + pub fn deinit(self: Self) void { + for (self.grid) |row| { + self.allocator.free(row); + } + self.allocator.free(self.grid); + } + + pub fn fits(self: Self, present: Present) bool { + std.debug.assert(self.grid.len > 0); + const size = self.grid.len * self.grid[0].len; + if ((size - self.filled_spaces) < present.shape.count()) { + return false; + } + + // TODO: Implementation + return false; + } };