Add day3 solution.

This commit is contained in:
Danila Fedorin 2020-12-02 21:14:34 -08:00
parent 0651feb111
commit 00e8704ac3
1 changed files with 29 additions and 0 deletions

29
day3.cr Normal file
View File

@ -0,0 +1,29 @@
INPUT = File.read("day3.txt").lines.map(&.chomp)
def run(input, slopes)
prod = 1_i64
slopes.each do |slope|
trees = 0
pos = 0
line = 0
right, down = slope
while line < input.size
trees += 1 if input[line][pos] == '#'
pos = (pos + right) % input[line].size
line += down
end
prod *= trees
end
prod
end
def part1
puts run(INPUT, [{3,1}])
end
def part2
puts run(INPUT, [{1,1}, {3,1}, {5,1}, {7,1}, {1,2}])
end
part1
part2