WIP: implement part 1
This commit is contained in:
parent
393f80f314
commit
f088a5a21a
1 changed files with 25 additions and 4 deletions
|
|
@ -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 {
|
||||||
|
|
@ -173,6 +190,10 @@ const Region = struct {
|
||||||
pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion {
|
pub fn createEmpty(self: Self, allocator: std.mem.Allocator) !EmptyRegion {
|
||||||
return try .init(allocator, self.width, self.height);
|
return try .init(allocator, self.width, self.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn area(self: Self) usize {
|
||||||
|
return self.width * self.height;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const EmptyRegion = struct {
|
const EmptyRegion = struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue