From 4bb34be4a61d5abd55231c64b0242891d91770e7 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Tue, 3 Dec 2019 07:43:59 -0800 Subject: [PATCH] [2019][ruby][3.b] --- 2019/ruby/day_03.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/2019/ruby/day_03.rb b/2019/ruby/day_03.rb index c99257a..f29e025 100644 --- a/2019/ruby/day_03.rb +++ b/2019/ruby/day_03.rb @@ -13,11 +13,12 @@ wire_points = wire_paths.map {|path| when ?D then [x, y-i-1] end } - } + }.map.with_index.to_h } -intersections = wire_points[0] & wire_points[1] +intersections = wire_points[0].select {|k, _| wire_points[1].has_key?(k) } intersections.delete([0, 0]) -distances = intersections.map {|(x, y)| x.abs + y.abs } +# distances = intersections.map {|(x, y), _| x.abs + y.abs } +distances = intersections.map {|p, d| d + wire_points[1].fetch(p) } puts distances.min