You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2020/ruby/day_03.rb

16 lines
271 B

map = ARGF.read.split("\n").map(&:chars)
rows = map.size
cols = map[0].size
slopes = [
[1, 1],
[3, 1],
[5, 1],
[7, 1],
[1, 2],
]
puts slopes.map {|dx,dy|
Array.new(rows / dy) {|i| [dx*i % cols, dy*i] }
.map {|x,y| map[y][x] }
.count(?#)
}.reduce(&:*)