24 lines
451 B
Ruby
24 lines
451 B
Ruby
|
#!/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
|