fork download
  1. import Data.List
  2. import Data.Tuple
  3. import Control.Arrow
  4. import Control.Monad
  5. main :: IO ()
  6. main = do
  7. zipWithM_ (f >>> (>>> print)) [3..7]
  8. $ replicate 3 [1..10]
  9. zipWithM_ (g >>> (>>> print)) [3..10]
  10. $ replicate 3 [1..10] ++ replicate 3 [1..15]
  11. print $ f465 "We will encourage you to develop the three great virtues of a programmer: laziness, impatience, and hubris."
  12.  
  13. f :: Int -> [a] -> [[a]]
  14. f = (flip divMod >>> (length >>>)) >>> (>>> swap) >>> (>>> ((((first signum >>> uncurry (+)) >>= flip (fst >>> replicate)) &&& (snd >>> repeat)) >>> (uncurry (++)))) >>> (>>= flip (mapAccumL (flip splitAt >>> (>>> swap)))) >>> (>>> (snd >>> takeWhile (null >>> not)))
  15.  
  16. g :: Float -> [a] -> [[a]]
  17. g n xs = map (\i -> let b = ceiling $ (i - 1) * a in take (ceiling (i * a) - b) $ drop b xs) [1..n]
  18. where a = (fromIntegral $ length xs) / n
  19.  
  20. f465 :: String -> [(Char, Int)]
  21. f465 = sort >>> group >>> map (head &&& length)
  22.  
Success #stdin #stdout 0s 6264KB
stdin
Standard input is empty
stdout
[[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]]
[[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],[11,12,13],[14,15]]
[[1,2,3],[4,5],[6,7],[8,9],[10,11],[12,13],[14,15]]
[[1,2],[3,4],[5,6],[7,8],[9,10],[11,12],[13,14],[15]]
[(' ',16),(',',2),('.',1),(':',1),('W',1),('a',7),('b',1),('c',2),('d',2),('e',14),('f',1),('g',3),('h',3),('i',6),('l',4),('m',3),('n',4),('o',6),('p',3),('r',8),('s',4),('t',6),('u',4),('v',2),('w',1),('y',1),('z',1)]