Resolve day 1
This commit is contained in:
parent
aa1a08be1c
commit
c7fa7b0567
2004
01/output-ruby.txt
Normal file
2004
01/output-ruby.txt
Normal file
File diff suppressed because it is too large
Load Diff
2001
01/output-shell.txt
Normal file
2001
01/output-shell.txt
Normal file
File diff suppressed because it is too large
Load Diff
23
01/script.rb
Executable file
23
01/script.rb
Executable 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
|
Loading…
x
Reference in New Issue
Block a user