Re: finding value nearest x

2014-03-05 Thread Yehonathan Sharvit
In the sorted-set solution, you forgot to handle the case where all the values in the sorted-set are greater than 136... On Saturday, 25 September 2010 17:55:33 UTC+2, Chouser wrote: On Sat, Sep 25, 2010 at 10:44 AM, Nicolas Oury nicola...@gmail.comjavascript: wrote: On Sat, Sep 25, 2010

Re: finding value nearest x

2010-09-27 Thread Glen Rubin
It occurs to me that another way of doing this is to map a new list and then use the min fn. something like: (apply min (map #(Math/abs (- % 136)) xs)) maybe this is better and involves less calculations? On Sep 25, 2:19 pm, Glen Rubin rubing...@gmail.com wrote: min-key looks good!  thx

Re: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:28 AM, Glen Rubin wrote: It occurs to me that another way of doing this is to map a new list and then use the min fn. something like: (apply min (map #(Math/abs (- % 136)) xs)) maybe this is better and involves less calculations? That gives you the minimum distance

Re: finding value nearest x

2010-09-27 Thread Glen Rubin
yes correct. but i can write a fn to determine the index of the minimum distance in my new list? that index applied to my original list will give me the value back. and this still would involve fewer calculations i think. On Sep 27, 10:50 am, Michael Gardner gardne...@gmail.com wrote: On Sep

Re: finding value nearest x

2010-09-27 Thread Michael Gardner
On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote: yes correct. but i can write a fn to determine the index of the minimum distance in my new list? that index applied to my original list will give me the value back. and this still would involve fewer calculations i think. Do you have a

Re: finding value nearest x

2010-09-27 Thread Adam Burry
On Sep 25, 11:41 am, Glen Rubin rubing...@gmail.com wrote: I have a list of numbers and I want to find the one that is closest to 136.  Is there an operator for performing this kind of operation or do I need to to do it algorithmically? I think the normal way to do this is a k-d tree:

Re: finding value nearest x

2010-09-27 Thread Glen Rubin
ok, thx. just trying to keep myself to a high standard while learning this stuff ;) On Sep 27, 11:12 am, Michael Gardner gardne...@gmail.com wrote: On Sep 27, 2010, at 9:59 AM, Glen Rubin wrote: yes correct.  but i can write a fn to determine the index of the minimum distance in my new

finding value nearest x

2010-09-25 Thread Glen Rubin
I have a list of numbers and I want to find the one that is closest to 136. Is there an operator for performing this kind of operation or do I need to to do it algorithmically? thanks! -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this

Re: finding value nearest x

2010-09-25 Thread Jules
Maybe this: (min-key #(abs (- % 136)) xs) On Sep 25, 3:41 pm, Glen Rubin rubing...@gmail.com wrote: I have a list of numbers and I want to find the one that is closest to 136.  Is there an operator for performing this kind of operation or do I need to to do it algorithmically? thanks! --

Re: finding value nearest x

2010-09-25 Thread Nicolas Oury
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)? -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to

Re: finding value nearest x

2010-09-25 Thread Jules
Yes, you're right. On Sep 25, 4:44 pm, 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)? -- You received this message because you are

Re: finding value nearest x

2010-09-25 Thread Eivind Magnus Hvidevold
(use 'clojure.contrib.math) ; for abs (apply min-key #(abs (- 136 %)) [1 3 137 -137 135 0 50 75]) A recent thread in this group noted that min-key applies the function multiple times and there's a better replacement. Also, if you're looking up many such numbers you might want to sort and do

Re: finding value nearest x

2010-09-25 Thread Chouser
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

Re: finding value nearest x

2010-09-25 Thread Glen Rubin
min-key looks good! thx guys!!! On Sep 25, 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)? -- You received this message