On Fri, Jul 1, 2011 at 3:28 PM, .Bill Smith <william.m.sm...@gmail.com>wrote:
> I want a concise function that, given an arbitrary length sequence, > determines whether the sequence is of consecutive integers starting with > one. So: > > (f [1 2 3]) returns true > > (f [1 2 4]) returns false > > (f [0 1 2]) returns false > > My first try, which I am not proud of, follows: > > (defn f [numbers] > (every? (fn [[x y]] (= x y)) (partition 2 (interleave (iterate inc 1) > numbers)))) > > > Can someone suggest something better? > (defn f [xs] (every? #(apply = %) (map vector xs (iterate inc 1)))) -- 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