Skip to content

Instantly share code, notes, and snippets.

@chmllr
Created January 6, 2012 20:01
Show Gist options
  • Save chmllr/1572152 to your computer and use it in GitHub Desktop.
Save chmllr/1572152 to your computer and use it in GitHub Desktop.
var numbers = readLine.split(" ").map(_.toInt).toList.sorted
numbers = numbers.distinct ++ (numbers diff numbers.distinct)
def solve(acc: Int, list: List[Int]):Int = list match{
case (h::Nil) => acc
case (h::t) => if (h+1 == t.head) solve(acc,t) else solve(acc+1,h+1::t.slice(0,t.size-1))
}
println(solve(0,numbers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment