-
-
Save dropkickfish/7462bcc03efdcf27121c7aa0f8ab7e7e to your computer and use it in GitHub Desktop.
Advent of Code 2020 - Day 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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