Skip to content

Instantly share code, notes, and snippets.

@tenebrousedge
Created December 3, 2020 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenebrousedge/23ccafe417b8d9a8b5e34688e32aaa8e to your computer and use it in GitHub Desktop.
Save tenebrousedge/23ccafe417b8d9a8b5e34688e32aaa8e to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
INPUT = File.readlines("#{__dir__}/input.txt")
WIDTH = INPUT[0].size
def slope(dx, dy)
x = 0
(dy...INPUT.size).step(dy).count do |y|
x += dx
INPUT[y][x % WIDTH] == '#'
end
end
puts slope(3, 1) # => 162
#slopes = [[3, 1], [1, 1], [5, 1], [7, 1], [1, 2]]
#puts slopes.product { |(dx, dy)| slope(dx, dy) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment