I've been working on problems from "Programming Challenges" (Skiena)
to learn clojure.  As part of a problem I developed the following
routine.  I sort of scare myself how natural thinking in reduce is
getting, but I was wondering if there is a more clever/idiomatic way
to solve this problem.

(defn break-on-gaps [minutes]
  (reduce (fn [acc x]
            (if (empty? acc)
              [[x]]
              (if (= (inc (last (last acc))) x)
                (conj (vec (butlast acc))
                      (conj (last acc) x))
                (conj acc [x]))))
          []
          minutes))

user=> (break-on-gaps [1 2 3 5 6 7 8 10 20 21])
[[1 2 3] [5 6 7 8] [10] [20 21]]

-- 
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

Reply via email to