solved day 1

master
s00ner 2021-12-01 13:56:06 -05:00
parent ea46dbb964
commit 3862cfb0b1
2 changed files with 2012 additions and 0 deletions

2000
day01/input Normal file

File diff suppressed because it is too large Load Diff

12
day01/solution.rb Normal file
View File

@ -0,0 +1,12 @@
#!/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