Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Created September 9, 2015 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtacconi/d68a382b18b9b3a175d6 to your computer and use it in GitHub Desktop.
Save rtacconi/d68a382b18b9b3a175d6 to your computer and use it in GitHub Desktop.
# https://codility.com/demo/results/demoJ2Q7MX-R8M/
# 100% performance and correctness
def solution(a)
return 1 unless a && a.size > 0
length = a.length + 1
sum1 = 0
sum2 = 0
sum1 = a.inject(&:+)
sum2 = (((length+1)*length)/2) - sum1
sum2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment