Skip to content

Instantly share code, notes, and snippets.

@amandaclarck
Created January 13, 2017 00:31
Show Gist options
  • Save amandaclarck/36496a7598638b6622797f3807cb994b to your computer and use it in GitHub Desktop.
Save amandaclarck/36496a7598638b6622797f3807cb994b to your computer and use it in GitHub Desktop.
def pairs( a,k)
x = 0
#y = 0
resp = 0
m = a.length.to_i
while x < a.length
y = m - 1
while y < m
#puts y
if((a[y] - a[x])==k)
resp +=1
end
y-=1
if(y < 0)
break
end
end
x+=1
end
return resp
end
#pairs([1,5,3,4,2],2)
pairs([2,3],1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment