Solution for Day 03

This commit is contained in:
2020-12-03 10:52:37 +01:00
parent 95b04662d6
commit 5598936603
3 changed files with 358 additions and 0 deletions

23
day_03/second.rb Normal file
View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
input = File.readlines './input'
width = input.first.strip.size
output = []
[
{ r: 1, d: 1 },
{ r: 3, d: 1 },
{ r: 5, d: 1 },
{ r: 7, d: 1 },
{ r: 1, d: 2 }
].each do |dir|
count = 0
input.each_with_index.select do |_, i|
i % dir[:d] == 0
end.each_with_index do |row, i|
count += 1 if row.first[i * dir[:r] % width] == '#'
end
output << count
end
puts output.inject :*