fork download
  1. part m xxs@(_:xs) = last $ loop (length xxs - m) [[map (:[]) $ take i xxs] | i <- [1..m]] xs
  2. where
  3. loop 0 xss _ = xss
  4. loop n (xs:xss) (y:ys) = loop (n-1) (step (update y xs) xss ys) ys
  5. step p [] _ = [p]
  6. step p (xs:xss) (y:ys) = p : step (update y xs ++ map ([y]:) p) xss ys
  7. update y xs = concatMap (go y) xs
  8. where
  9. go y [] = []
  10. go y (x:xs) = ((y:x):xs) : map (x:) (go y xs)
  11. main = print $ part 3 [1..5]
Success #stdin #stdout 0s 8388607KB
stdin
Standard input is empty
stdout
[[[5,4,1],[2],[3]],[[4,1],[5,2],[3]],[[4,1],[2],[5,3]],[[5,1],[4,2],[3]],[[1],[5,4,2],[3]],[[1],[4,2],[5,3]],[[5,1],[2],[4,3]],[[1],[5,2],[4,3]],[[1],[2],[5,4,3]],[[5,4],[3,1],[2]],[[4],[5,3,1],[2]],[[4],[3,1],[5,2]],[[5,4],[1],[3,2]],[[4],[5,1],[3,2]],[[4],[1],[5,3,2]],[[5,4],[3],[2,1]],[[4],[5,3],[2,1]],[[4],[3],[5,2,1]],[[5],[4,3,1],[2]],[[5],[3,1],[4,2]],[[5],[4,1],[3,2]],[[5],[1],[4,3,2]],[[5],[4,3],[2,1]],[[5],[3],[4,2,1]],[[5],[4],[3,2,1]]]