Here is another way:

 

(defn f [xs]

  (and 

     (= 1 (first xs)) 

     (apply = (map - (rest xs) xs))))

 

________________________________

From: clojure@googlegroups.com [mailto:clojure@googlegroups.com] On
Behalf Of David Nolen
Sent: Friday, July 01, 2011 3:51 PM
To: clojure@googlegroups.com
Subject: Re: Most concise way to determine that a sequence is
consecutive integers starting with one?

 

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

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