1
# Shapes are all 3x3.
2
3
# input = DATA.read
4
input = File.read('12.input')
5
6
shapes = input.split("\n\n")
7
regions = shapes.pop.split("\n")
8
9
shapes = Hash[shapes.map do |e|
10
num, *ides = e.split("\n")
11
[num.to_i, ides]
12
end]
13
14
15
regions.map! do |e|
16
size, requirements = e.split(": ")
17
[*size.split("x").map(&:to_i), requirements.split(" ").map(&:to_i)]
18
end
19
20
p regions.count { |(w, h, reqs)|
21
reqs.map.with_index { |c, ix| shapes[ix].map { |l| l.count('#') }.sum * c }.sum <= w * h
22
}
23
24
__END__
25
0:
26
###
27
##.
28
##.
29
30
1:
31
###
32
##.
33
.##
34
35
2:
36
.##
37
###
38
##.
39
40
3:
41
##.
42
###
43
##.
44
45
4:
46
###
47
#..
48
###
49
50
5:
51
###
52
.#.
53
###
54
55
4x4: 0 0 0 0 2 0
56
12x5: 1 0 1 0 2 2
57
12x5: 1 0 1 0 3 2
58