Merge branch 'master' of http://git.doublehack.me/s00ner/AoC2020 into master

master
Jeff Yates 2020-12-04 08:49:51 -05:00
commit fea02241b8
1 changed files with 38 additions and 0 deletions

38
day03/solution2.rb Executable file
View File

@ -0,0 +1,38 @@
#!/bin/env ruby
slopes = {
:one => { :right => 1, :down => 1},
:two => { :right => 3, :down => 1},
:three => { :right => 5, :down => 1},
:four => { :right => 7, :down => 1},
:five => { :right => 1, :down => 2}
}
input = Array.new
File.readlines('./input').each.with_index do |line, i|
line.strip!
input[i] = line.split('')
end
input.each do |x|
x.map! do |y|
y == '#' ? true : false
end
end
collisions = Array.new
slopes.each do |num, slope|
i = 0
trees = 0
len = input[0].length
input.each.with_index do |row, row_num|
next if (slope[:down] == 2 and row_num.odd?)
trees += 1 if row[i]
i +=slope[:right]
i = i - len if i >= len
end
collisions.push(trees)
puts "On slope #{num.to_s} We hit #{trees} trees"
end
puts "Multiplied together we get: #{collisions.inject(:*)}"