From 971f8c3c71662fa386d85c48d54b2f18d7fe40d3 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Mon, 3 Dec 2018 12:52:02 -0800 Subject: [PATCH] [2018][ruby][3.0] --- 2018/ruby/day_03.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 2018/ruby/day_03.rb 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 }