Advertisement
Guest User

Untitled

a guest
Dec 29th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.23 KB | None | 0 0
  1. object P08 {
  2. def compress[A](xs: List[A]): List[A] = xs match {
  3. case x :: xs =>
  4. val (_, rs) = ((x, List(x)) /: xs) { case ((prev, rs), x) => (x, if (x == prev) rs else x :: rs) }
  5. rs.reverse
  6. case _ => xs
  7. }
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement