[2020][ruby][3.x] too clever

master
Alpha Chen 4 years ago
parent 4dd5e8d920
commit ea6d3fed3b

@ -1,4 +1,6 @@
map = ARGF.read.split("\n").map(&:chars) map = ARGF.read.split("\n").map(&:chars)
rows = map.size
cols = map[0].size
slopes = [ slopes = [
[1, 1], [1, 1],
[3, 1], [3, 1],
@ -7,12 +9,7 @@ slopes = [
[1, 2], [1, 2],
] ]
puts slopes.map {|dx,dy| puts slopes.map {|dx,dy|
x, y = 0, 0 map.each_slice(dy).map(&:first)
trees = 0 .map.with_index {|row,i| row[dx*i % cols] }
until y >= map.length .count(?#)
trees += 1 if map[y][x % map[0].size] == ?#
x += dx
y += dy
end
trees
}.reduce(&:*) }.reduce(&:*)

Loading…
Cancel
Save