Sort 44 Discussions, By:
Please Login in order to post a comment
main = do interact (concat . (\[p,q]->zipWith (\x y-> [x,y]) p q) . lines)
Using list comprehension in Haskell
mingle :: String -> String -> String
mingle a b = concat [[x, y] | (x, y) <- zip a b]
My Racket solution:
(define (mingle p q)
(let iter ([accu empty] [p (string->list p)] [q (string->list q)])
(if (empty? p)
(list->string (reverse accu))
(iter (cons (first q) (cons (first p) accu)) (rest p) (rest q)))))
(define p (read-line))
(define q (read-line))
(displayln (mingle p q))
Suggestions for improvement welcome.
Has anyone, using clojure, used a high order function to solve this? I was getting timeouts until I stopped using them. I'm curious to know if I'm just using the high order functions inefficiently. If you have such a solution please PM me.
mingle "" "" = ""
mingle p q = (head p) : (head q) : mingle (tail p) (tail q)
main = do
p <- getLine
q <- getLine
putStrLn $ mingle p q