On Sat, Sep 25, 2010 at 10:44 AM, Nicolas Oury <nicolas.o...@gmail.com> wrote: > On Sat, Sep 25, 2010 at 3:40 PM, Jules <julesjac...@gmail.com> wrote: >> Maybe this: (min-key #(abs (- % 136)) xs) >> > Wouldn't that be (apply min-key #(abs (- % 136)) xs)?
Where's your 'abs' function coming from? This works for me: (apply min-key #(Math/abs (- % 136)) xs) Or if you want something slower when building the collection but faster when looking it up, you can use a sorted set: (let [ss (sorted-set 1 2 134 139 4), asc (subseq ss >= 136), desc (rsubseq ss <= 136)] (min-key #(Math/abs (- % 136)) (first asc) (first desc))) That's O(log n) instead the simpler (apply min-key ...) which is O(n). --Chouser http://joyofclojure.com/ -- 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