Resolve day 1
This commit is contained in:
parent
4f14f9b5af
commit
b5d8831fe8
27
01/script.rb
Executable file
27
01/script.rb
Executable file
@ -0,0 +1,27 @@
|
|||||||
|
#!/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
|
Loading…
x
Reference in New Issue
Block a user