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

mmensik + 0 comments Haskell oneliner:

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

Elmex90s + 0 comments Using list comprehension in Haskell

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

blubberdiblub + 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.

fraburnham + 0 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.

nitinpatel278 + 0 comments 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 44 Discussions, By:

Please Login in order to post a comment