Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Function
- import Data.List
- orderLists :: [a] -> [a] -> ([a], [a])
- orderLists xs ys
- | on compare length xs ys == LT = (xs, ys)
- | otherwise = (ys, xs)
- listsLengthQuotient :: ([a], [a]) -> ([a], [a], Int)
- listsLengthQuotient (xs, ys) =
- (xs, ys, (round $ on (/) (fromIntegral . length) ys xs) :: Int)
- chunksOf :: Int -> [a] -> [[a]]
- chunksOf n [] = []
- chunksOf x xs = take x xs : chunksOf x (drop x xs)
- groupListItems :: ([a], [a], Int) -> ([[a]], [[a]])
- groupListItems (xs, ys, q) = (chunksOf 1 xs, chunksOf q ys)
- merge :: ([a], [a]) -> [a]
- merge (xs, []) = xs
- merge ([], ys) = ys
- merge (x:xs, y:ys) = y : x : merge (xs, ys)
- mixLists :: [a] -> [a] -> [a]
- mixLists xs ys =
- concat $ merge $ groupListItems $ listsLengthQuotient $ orderLists xs ys
- main :: IO ()
- main = do
- input <- getContents
- mapM_ putStrLn $
- foldl1 mixLists $ sortBy (on compare length) (group . sort $ lines input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement