28 lines
438 B
Ruby
Executable File
28 lines
438 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require_relative '../common'
|
|
|
|
class Day01 < Day
|
|
def part1
|
|
input.each_with_object([0]) do |row, result|
|
|
if row == ""
|
|
result << 0
|
|
else
|
|
result[-1] += row.to_i
|
|
end
|
|
end.max
|
|
end
|
|
|
|
def part2
|
|
input.each_with_object([0]) do |row, result|
|
|
if row == ""
|
|
result << 0
|
|
else
|
|
result[-1] += row.to_i
|
|
end
|
|
end.sort[-3..-1].sum
|
|
end
|
|
end
|
|
|
|
Day01.run
|