2021/01/script.rb

24 lines
451 B
Ruby
Raw Normal View History

2021-12-01 15:32:46 +01:00
#!/usr/bin/env ruby
require_relative '../common'
class Day01 < Day
def part1
measurements.each_with_index.inject(0) do |count, (value, i)|
i > 0 && value > measurements[i - 1] ? count.succ : count
end
end
def part2
measurements.size.times.select do |i|
i > 2 && measurements[i - 2, 3].sum > measurements[i - 3, 3].sum
end.size
end
def measurements
@measurements ||= input.map(&:to_i)
end
end
Day01.run