Skip to content

Instantly share code, notes, and snippets.

@dropkickfish
Created December 3, 2020 18:44
Show Gist options
  • Save dropkickfish/7462bcc03efdcf27121c7aa0f8ab7e7e to your computer and use it in GitHub Desktop.
Save dropkickfish/7462bcc03efdcf27121c7aa0f8ab7e7e to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 3
matrix = []
$totaltrees = []
x, y, $trees, slope = 0, 0, 0, -1
File.foreach('3.txt') { |line| matrix << line.strip.split('') and slope += 1 }
possibilities = [[1,1],
[3,1],
[5,1],
[7,1],
[1,2]]
possibilities.each do |possibility|
xtrav = possibility[0]
ytrav = possibility[1]
while y < slope
x += xtrav
y += ytrav
if x > 30
x -= 31
end
pos = matrix[y][x]
if pos == '#'
$trees += 1
end
end
$totaltrees << $trees
x, y, $trees = 0, 0, 0
end
puts $totaltrees.reduce(:*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment