Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Created September 9, 2009 13:58
Show Gist options
  • Save NicolasT/183731 to your computer and use it in GitHub Desktop.
Save NicolasT/183731 to your computer and use it in GitHub Desktop.
val a = 1 :: 2 :: 3 :: 4 :: 3 :: 2 :: 5 :: 4 :: Nil
def r[A](h: List[A], t: List[A]): List[A] = {
if(t isEmpty)
return h
if(t.tail exists(i => i == t.head))
h ::: r(Nil, t.tail)
else
h ::: (t.head :: Nil) ::: r(Nil, t.tail)
}
println(r(Nil, a reverse) reverse)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment