Compare commits

..

2 commits

Author SHA1 Message Date
f088a5a21a WIP: implement part 1 2025-12-12 16:35:12 +00:00
393f80f314 WIP: implement part 1 2025-12-12 14:48:57 +00:00

View file

@ -111,13 +111,26 @@ pub fn run(allocator: std.mem.Allocator) !void {
} }
} }
for (presents.items, 0..) |present, i| { var accumulator: usize = 0;
std.debug.print("{d}:\n{f}\n\n", .{i, present});
}
for (regions.items) |region| { for (regions.items) |region| {
std.debug.print("{f}\n", .{region}); var area_needed: usize = 0;
for (region.required_presents, 0..) |amount, i| {
area_needed += amount * presents.items[i].area();
}
if (area_needed < region.area()) {
std.debug.print("{f}\nfits\n", .{region});
accumulator += 1;
}
} }
var buffer: [8]u8 = undefined;
var stdout_writer = std.fs.File.stdout().writer(&buffer);
const stdout = &stdout_writer.interface;
try stdout.print("{d}\n", .{accumulator});
try stdout.flush();
} }
const Present = struct { const Present = struct {
@ -147,6 +160,10 @@ const Present = struct {
const index = (y * Width) + x; const index = (y * Width) + x;
return self.shape.isSet(index); return self.shape.isSet(index);
} }
pub fn area(self: Self) usize {
return self.shape.count();
}
}; };
const Region = struct { const Region = struct {
@ -169,5 +186,54 @@ const Region = struct {
} }
} }
} }
pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion {
return try .init(allocator, self.width, self.height);
}
pub fn area(self: Self) usize {
return 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;
}
}; };