On Wed, Dec 2, 2009 at 7:59 PM, Don <josereyno...@gmail.com> wrote:

> I still can't figure it out.  If have this set.
>
>  a [2 4 6 7]
>  b [1 3 9 2]
>  c [2 4 5 6]
>  d [6 1 3 8]
>  e [4 8 2 1]
>
> If I do (reduce min (map #(get % 0) (list a b c d e)))
>
> It grabs the min value from index 0 of the five vectors and returns 1
> corresponding to 'b'. But I'm not sure how I would determine it's
> coming from 'b'.  I need to know that it comes from 'b' in order to
> build the new vector.
>
> If I do (vec (map min a b c d e))
>
> It grabs the min value from index (0, 1, 2, 3) and puts it in a vector
>
> [1 1 2 1]
>
> And I don't know from what vector the minimum value is coming from.
>
> The solution is probably already here but I can't think of it.  Sorry.


(defn min-col [col vecs]
  (apply min (map #(nth % col) vecs)))

(defn min-pos [col vecs]
  (let [m (min-col col vecs)]
    (map #(if (= m %) 1 0) (map #(nth % col) vecs))))

(defn min-pos-vecs [vecs]
  (apply map vector
    (map #(min-pos % vecs)
      (range (count (first vecs))))))

user=> (min-pos-vecs [[2 4 6 7] [1 3 9 2] [2 4 5 6] [6 1 3 8] [4 8 2 1]])
([0 0 0 0] [1 0 0 0] [0 0 0 0] [0 1 0 0] [0 0 1 1])

-- 
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

Reply via email to