Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The app reads a column of lines of text from STDIN and splits the
- -- column into four equal or almost equal parts with an empty line as a
- -- separator.
- import Data.List (intercalate)
- import System.Exit (die)
- splitIntoFour :: [a] -> [[a]]
- splitIntoFour list = let
- l = length list
- q1 = div l 4
- q2 = div l 2 - q1
- q3 = div (l - div l 2) 2
- in
- if l < 4
- then
- map (:[]) list
- else
- [take q1 list, take q2 $ drop q1 list, take q3 $ drop (q1 + q2) list, drop (q1 + q2 + q3) list]
- main :: IO ()
- main = do
- input <- getContents
- if null input
- then
- die "No input!"
- else
- putStr $ unlines $ intercalate [""] (splitIntoFour $ lines input)
Advertisement