Advertisement
banovski

Quick, reliable pseudo-shuffler

Feb 26th, 2024 (edited)
2,097
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 0.29 KB | Source Code | 1 0
  1. import Data.List
  2. import Data.Function
  3.  
  4. merge :: [a] -> [a] -> [a]
  5. merge xs [] = xs
  6. merge [] ys = ys
  7. merge (x:xs) (y:ys) = y : x : merge xs ys
  8.  
  9. main :: IO ()
  10. main = do
  11.   input <- getContents
  12.   mapM_ putStrLn . foldl1 merge $
  13.     sortBy (on compare length) (group . sort $ lines input)
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement