From 3601c50b2281916a89ac0d0cbb0b8af3d7d159b8 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 2 Dec 2020 21:26:05 -0800 Subject: [PATCH] [2020][ruby][3.x] this is better --- 2020/ruby/day_03.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/2020/ruby/day_03.rb b/2020/ruby/day_03.rb index 9e762a7..32f0e70 100644 --- a/2020/ruby/day_03.rb +++ b/2020/ruby/day_03.rb @@ -9,7 +9,7 @@ slopes = [ [1, 2], ] puts slopes.map {|dx,dy| - map.each_slice(dy).map(&:first) - .map.with_index {|row,i| row[dx*i % cols] } + Array.new(rows / dy) {|i| [dx*i % cols, dy*i] } + .map {|x,y| map[y][x] } .count(?#) }.reduce(&:*)