AoC2021/day01/solution.rb

12 lines
364 B
Ruby
Raw Normal View History

2021-12-01 18:56:06 +00:00
#!/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