diff --git a/2018/ruby/day_03.rb b/2018/ruby/day_03.rb new file mode 100644 index 0000000..af017ba --- /dev/null +++ b/2018/ruby/day_03.rb @@ -0,0 +1,13 @@ +p ARGF.read.lines.each.with_object(Hash.new(0)) {|line, fabric| + line =~ /(\d+),(\d+): (\d+)x(\d+)$/ + x = $1.to_i + y = $2.to_i + width = $3.to_i + height = $4.to_i + + width.times {|dx| + height.times {|dy| + fabric[[y + dy, x + dx]] += 1 + } + } +}.count {|_,v| v > 1 }