12 lines
364 B
Ruby
12 lines
364 B
Ruby
|
#!/bin/env ruby
|
||
|
|
||
|
depths = File.readlines('./input').map(&:to_i)
|
||
|
|
||
|
# Part 1
|
||
|
changes = depths.each_cons(2).map { |first, second| second - first}
|
||
|
pp changes.reject { |num| num.negative?}.count
|
||
|
|
||
|
# Part 2
|
||
|
sums = depths.each_cons(3).map { |nums| nums.sum }
|
||
|
changes = sums.each_cons(2).map { |first, second| second - first}
|
||
|
pp changes.reject { |num| !num.positive?}.count
|