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
275 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|
map.each_slice(dy).map(&:first)
.map.with_index {|row,i| row[dx*i % cols] }
.count(?#)
}.reduce(&:*)