Skip to content

Instantly share code, notes, and snippets.

@betawaffle
Created August 25, 2011 12:49
Show Gist options
  • Save betawaffle/1170573 to your computer and use it in GitHub Desktop.
Save betawaffle/1170573 to your computer and use it in GitHub Desktop.
Find the Missing Integer
def missing(list)
min, max, sum = list.reduce([f = list.first, f, 0]) do |(l, h, s), n|
[n < l ? n : l, n > h ? n : h, s + n]
end
max * (max + 1) / 2 - min * (min - 1) / 2 - sum
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment