Resolve day 1

main
Guillaume Dott 2021-12-01 15:32:46 +01:00
parent aa1a08be1c
commit c7fa7b0567
4 changed files with 6028 additions and 0 deletions

2000
01/input 100644

File diff suppressed because it is too large Load Diff

2004
01/output-ruby.txt 100644

File diff suppressed because it is too large Load Diff

2001
01/output-shell.txt 100644

File diff suppressed because it is too large Load Diff

23
01/script.rb 100755
View File

@ -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