Skip to content

Instantly share code, notes, and snippets.

Created January 7, 2013 18:09
Show Gist options
  • Save anonymous/4477082 to your computer and use it in GitHub Desktop.
Save anonymous/4477082 to your computer and use it in GitHub Desktop.
makeUpTo n = mlu n []
where
mlu n pre [] = [pre]
mlu n [] (w:ws) = mlu n w ws
mlu n pre (w:ws) | length pre + 1 + length w <= n = mlu n (pre ++ ' ' : w) ws
| otherwise = pre : mlu n [] (w:ws)
t2 n i = putStrLn
$ unlines
$ makeUpTo n
$ [ frag | w <- words i, frag <- splitIntoSize n w ]
-- basically a library function, and useful for other kinds of list
splitIntoSize :: Int -> [a] -> [[a]]
splitIntoSize n = map (take n) . takeWhile (not . null) . iterate (drop n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment