Skip to content

Instantly share code, notes, and snippets.

@metallurgix
Created December 10, 2014 08:54
Show Gist options
  • Save metallurgix/1a22b244b7ea79c1d3ce to your computer and use it in GitHub Desktop.
Save metallurgix/1a22b244b7ea79c1d3ce to your computer and use it in GitHub Desktop.
Codility-Lesson 2-Challenge 2
def solution(x, a)
sum=(x*(x+1))/2
pos=-1
b=Array.new(x,0)
(0..a.length-1).each do |i|
if b[a[i]-1]==0
b[a[i]-1]=1
sum-=a[i]
if sum==0
pos=i
break
end
end
end
pos
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment