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 > > > wrote: > > On Sat, Sep 25, 2010 at 3:40 PM, Jules > >

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 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 list? > > > that

Re: finding value nearest x

2010-09-27 Thread Adam Burry
On Sep 25, 11:41 am, Glen Rubin 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: http://en.wikipedia.org/

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 pa

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 wrote: > On Sep 27, 2010, at 9:28 AM

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 dis

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 wrote: > min-key looks good!  thx guys!!! > > On Sep 25,

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 wrote: > On Sat, Sep 25, 2010 at 3:40 PM, Jules 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 Googl

Re: finding value nearest x

2010-09-25 Thread Chouser
On Sat, Sep 25, 2010 at 10:44 AM, Nicolas Oury wrote: > On Sat, Sep 25, 2010 at 3:40 PM, Jules 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/ab

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 binary

Re: finding value nearest x

2010-09-25 Thread Jules
Yes, you're right. On Sep 25, 4:44 pm, Nicolas Oury wrote: > On Sat, Sep 25, 2010 at 3:40 PM, Jules 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 "Cloju

Re: finding value nearest x

2010-09-25 Thread Nicolas Oury
On Sat, Sep 25, 2010 at 3:40 PM, Jules 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 clojure@googlegroup

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 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! -- You received thi

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