On Wed, Nov 10, 2010 at 3:28 PM, David Jacobs <develo...@allthingsprogress.com> wrote: > I have a sorted list, and I'd like to derive from that a list > containing all "ties" in the original. > > That is, if I have (1 2 3 4 4 5 5 5 5 5 6 9 12 12), I want to get back > the sequence (4 4 5 5 5 5 5 12 12). > > My first thought was to try to filter down the list, but filter takes > each element of a list in step. One hack might be to pass the original > list through a partition function[0], then filter that list using > (filter #(> (count %) 1)). Seems messy, though. > > Is there a standard solution to this problem that I'm not aware of?
If the sequence is always sorted as in the example: (loop [s the-input-seq o [] last nil] (if (empty? s) o (let [n (first s)] (if (or (= n (second s)) (= n last)) (recur (rest s) (conj o n) n) (recur (rest s) o n))))) It's non-lazy but oughta do the job. :) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en