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 >
>
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
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/
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
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
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
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,
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
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
(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
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
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
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
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
14 matches
Mail list logo