We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# String Mingling

# String Mingling

+ 0 comments Haskell oneliner:

main = do interact (concat . (\[p,q]->zipWith (\x y-> [x,y]) p q) . lines)

+ 1 comment Using list comprehension in Haskell

mingle :: String -> String -> String mingle a b = concat [[x, y] | (x, y) <- zip a b]

+ 0 comments My Racket solution:

#lang racket (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.

+ 3 comments 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.

[deleted] + 1 comment Using recursion:

mingle "" "" = "" mingle p q = (head p) : (head q) : mingle (tail p) (tail q) main = do p <- getLine q <- getLine putStrLn $ mingle p q

Load more conversations

Sort 48 Discussions, By:

Please Login in order to post a comment