# HG changeset patch # User Ted Naleid # Date 1324879678 21600 # Node ID b9195246e889c06901233ecda271dea942b238ad # Parent 1e83f8600029b24b0324b2fa4fe9355f27159f0b answer to 39 diff --git a/src/four_clojure/answered.clj b/src/four_clojure/answered.clj --- a/src/four_clojure/answered.clj +++ b/src/four_clojure/answered.clj @@ -384,10 +384,22 @@ (= (my-replicate [[1 2] [3 4]] 2) '([1 2] [1 2] [3 4] [3 4])) (= (my-replicate [44 33] 2) [44 44 33 33]) -; http://www.4clojure.com/problem/ -; -; +; http://www.4clojure.com/problem/39 +; Interleave Two Seqs +; Write a function which takes two sequences and returns the first item from each, then the second item from each, then the third, etc. +; restriction: interleave +(defn my-interleave ([x y] + (and (seq x) (seq y) (cons (first x) (cons (first y) + (my-interleave (rest x) (rest y))))))) +; or +; mapcat list + + +(= (my-interleave [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c)) +(= (my-interleave [1 2] [3 4 5 6]) '(1 3 2 4)) +(= (my-interleave [1 2 3 4] [5]) [1 5]) +(= (my-interleave [30 20] [25 15]) [30 25 20 15]) ; http://www.4clojure.com/problem/ ;