Guest User

Untitled

a guest
Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. def combinationList[T](ls:List[List[List[T]]]) : List[List[List[T]]] = ls match {
  2. case head :: Nil => for(x <- head) yield List(x)
  3. case head :: tail :: Nil =>
  4. for {
  5. hl <- head
  6. tl <- tail
  7. if tl.forall(te => !hl.contains(te))
  8. } yield List(hl, tl)
  9. }
  10.  
  11. case _ => combinationList(combinationList(ls.tail):::List(ls.head))
  12.  
  13. List ( List(1), List(2), List(3) )
  14.  
  15. combinationList(List(combinationList(ls.tail)):::List(ls.head))
Add Comment
Please, Sign In to add comment