24 lines
294 B
Ruby
24 lines
294 B
Ruby
contents = File.open("01.txt").read
|
|
|
|
ans1 = contents
|
|
.split("\n\n")
|
|
.map do |s|
|
|
s.split("\n")
|
|
.map(&:to_i)
|
|
.sum
|
|
end
|
|
.max
|
|
puts ans1
|
|
|
|
ans2 = contents
|
|
.split("\n\n")
|
|
.map do |s|
|
|
s.split("\n")
|
|
.map(&:to_i)
|
|
.sum
|
|
end
|
|
.sort
|
|
.last(3)
|
|
.sum
|
|
puts ans2
|
|
|