Skip to content

Instantly share code, notes, and snippets.

@angerman
Created December 3, 2009 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save angerman/248074 to your computer and use it in GitHub Desktop.
Save angerman/248074 to your computer and use it in GitHub Desktop.
(defn combine [A B]
(loop [a+ A
b+ B
acc []]
(let [a (first a+)
b (first b+)]
(if (not a) ;; list a ended
(concat acc b+)
(if (not b) ;; list b ended
(concat acc a+)
(if (= a b) ;; items are the same
(recur (next a+) (next b+) (conj acc a))
(if (< a b) ;; either way
(recur (next a+) b+ (conj acc a))
(recur a+ (next b+) (conj acc b)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment