Skip to content

Instantly share code, notes, and snippets.

@pvpshoot
Created December 2, 2022 08:47
Show Gist options
  • Save pvpshoot/15a5a30d5c9e99ec4c3686a0a4367c6f to your computer and use it in GitHub Desktop.
Save pvpshoot/15a5a30d5c9e99ec4c3686a0a4367c6f to your computer and use it in GitHub Desktop.
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