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
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
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
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
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
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:
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
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
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!
--
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
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
(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
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
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
14 matches
Mail list logo