import Data.Listimport Data.Tupleimport Control.Arrowimport Control.Monadmain :: IO ()main = zipWithM_ ((print .) . f) [3, 4, 6, 7] $ replicate 4 [1..10]f :: Int -> [a] -> [[a]]f = ((takeWhile (not . null) . uncurry (flip (++)) . first (: [])) .) . ((flip (mapAccumL ((swap .) . flip splitAt)) =<<)) . ((uncurry (++) . ((flip (replicate . fst) =<< (uncurry (+) . first signum)) &&& repeat . snd)).) . (swap .) . ((. length) . flip divMod)
Standard input is empty
[[1,2,3,4],[5,6,7],[8,9,10]] [[1,2,3],[4,5,6],[7,8],[9,10]] [[1,2],[3,4],[5,6],[7,8],[9],[10]] [[1,2],[3,4],[5,6],[7],[8],[9],[10]]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!