On Mar 8, 10:26 am, Fred Concklin <fredconck...@gmail.com> wrote: > Tests whether list is arithmetic progression. > > Thoughts, feedback: > > (defn arithmetic-progression? [intlist] > "tests if list is arithmetic progression." > (apply = > (map > #(apply - %) > (partition 2 1 (reverse intlist))))) >
You lose the benefit of laziness when you use reverse. That won't matter in the case where the input actually is an arithmetic progression, because you'll have to check the whole sequence anyway. But when it's not an arithmetic progression, you want to bail out and return false early. How about: (defn arithmetic-progression? [intlist] "tests if list is arithmetic progression." (apply = (map - (rest instlist) intlist))) You'll probably want to add checks for special cases, like an empty or one-element sequence, too. - Chris -- 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