Compare commits
No commits in common. "f088a5a21a5da063947e66089213ba0aa220d8ff" and "b55a6d61da63d5eab872d4987d515edf808d7015" have entirely different histories.
f088a5a21a
...
b55a6d61da
1 changed files with 5 additions and 71 deletions
|
|
@ -111,26 +111,13 @@ pub fn run(allocator: std.mem.Allocator) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var accumulator: usize = 0;
|
for (presents.items, 0..) |present, i| {
|
||||||
|
std.debug.print("{d}:\n{f}\n\n", .{i, present});
|
||||||
|
}
|
||||||
|
|
||||||
for (regions.items) |region| {
|
for (regions.items) |region| {
|
||||||
var area_needed: usize = 0;
|
std.debug.print("{f}\n", .{region});
|
||||||
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 {
|
||||||
|
|
@ -160,10 +147,6 @@ 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 {
|
||||||
|
|
@ -186,54 +169,5 @@ 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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue