Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created October 26, 2012 05:02
Show Gist options
  • Save amalloy/3956900 to your computer and use it in GitHub Desktop.
Save amalloy/3956900 to your computer and use it in GitHub Desktop.
(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