Created
October 26, 2012 05:02
-
-
Save amalloy/3956900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn trim-head [coll] | |
(loop [so-far [], indexes {}, index 0, coll (seq coll)] | |
(if-not coll | |
{:origin nil, :pattern so-far} ;; ?? not specified in question | |
(let [x (first coll), xs (rest coll)] | |
(if (contains? indexes x) | |
{:origin (subvec so-far 0 (indexes x)) | |
:pattern (subvec so-far (indexes x))} | |
(case x | |
0 {:origin so-far, :pattern [x]} | |
1 {:origin nil, :pattern (conj so-far x)} | |
(recur (conj so-far x) (assoc indexes x index) (inc index) (seq xs)\ | |
))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment