r/o

833cce89043d318ef60e3c871066940577d6f7c8 parent 7db711f5

authored by Asherah Connor <aconnor@gitlab.com> 1 month ago
committed by Asherah Connor <aconnor@gitlab.com> 1 month ago

12 FOR SHAME.

12.rb | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/12.rb b/12.rb
index a21b375..a801390 100644
--- a/12.rb
+++ b/12.rb
@@ -1,6 +1,7 @@
# Shapes are all 3x3.
-input = DATA.read
+# input = DATA.read
+input = File.read('12.input')
shapes = input.split("\n\n")
regions = shapes.pop.split("\n")
@@ -13,9 +14,12 @@ end]
regions.map! do |e|
size, requirements = e.split(": ")
- [size.split("x").map(&:to_i), requirements.split(" ").map(&:to_i)]
+ [*size.split("x").map(&:to_i), requirements.split(" ").map(&:to_i)]
end
-p regions
+
+p regions.count { |(w, h, reqs)|
+ reqs.map.with_index { |c, ix| shapes[ix].map { |l| l.count('#') }.sum * c }.sum <= w * h
+}
__END__
0: