Created
December 2, 2022 08:47
-
-
Save pvpshoot/15a5a30d5c9e99ec4c3686a0a4367c6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = File.open("input"); | |
lines = file.readlines | |
arr = [] | |
subA = [] | |
i = 0 | |
for line in lines do | |
i += 1 | |
n = line.to_i | |
if n > 0 | |
subA.push(n) | |
else | |
arr.push(subA); | |
subA = [] | |
end | |
if(i == lines.count) | |
arr.push(subA); | |
end | |
end | |
v = arr.reduce { |acc, cur| acc.push(cur.sum()) } | |
p v.sort().last(3).sum() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment