banovski

Into-quarters splitter (Me)

Aug 30th, 2026 (edited)
77
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 0.68 KB | Source Code | 0 0
  1. -- The app reads a column of lines of text from STDIN and splits the
  2. -- column into four equal or almost equal parts with an empty line as a
  3. -- separator.
  4.  
  5. import Data.List (intercalate)
  6. import System.Exit (die)
  7.  
  8. splitIntoFour :: [a] -> [[a]]
  9. splitIntoFour list = let
  10.   l = length list
  11.   q1 = div l 4
  12.   q2 = div l 2 - q1
  13.   q3 = div (l - div l 2) 2
  14.   in
  15.   if l < 4
  16.   then
  17.     map (:[]) list
  18.   else
  19.     [take q1 list, take q2 $ drop q1 list, take q3 $ drop (q1 + q2) list, drop (q1 + q2 + q3) list]
  20.  
  21. main :: IO ()
  22. main = do
  23.   input <- getContents
  24.   if null input
  25.     then
  26.       die "No input!"
  27.     else
  28.       putStr $ unlines $ intercalate [""] (splitIntoFour $ lines input)
  29.  
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment