Python
You got me good, Eric.
hint
Think of the simplest check you can make for a region.
click to view code
# This does not work for the sample :D
def solve(data: str):
# split input
blocks = data.split("\n\n")
shape_blocks = blocks[:-1]
region_block = blocks[-1]
# for every shape, get the number of occupied cells
shape_area = []
for shape_block in shape_blocks:
shape_area.append(shape_block.count('#'))
fit_regions = 0
# for every region, check if the area is sufficient to fit all shapes
for region_data in region_block.splitlines():
size_data, shape_data = region_data.split(': ')
# get region size
m, n = [int(dim) for dim in size_data.split('x')]
# get area needed to fit all shapes, without considering arrangement
area_needed = 0
for id, freq in enumerate(map(int, shape_data.split(' '))):
area_needed += shape_area[id] * freq
# if the region area is sufficient, count it as a fit (!!!)
if m * n > area_needed:
fit_regions += 1
return fit_regions