Resolve day 1
parent
aa1a08be1c
commit
c7fa7b0567
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,23 @@
|
|||
#!/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
|
Loading…
Reference in New Issue