Hi, Finally I managed to write my program, see below. It is probably not optimized at all (I had some issues with vector concatenation..) but at least it does the same as my java program. Thanks again!
Regards, Nicolas (defrecord Pos [name value] Object (toString [this] (str "<Name: " name ", Value: " value ">"))) (def options [(Pos. "IBM", -50) (Pos. "ACCOR", -30); (Pos. "IBM", -10); (Pos. "APPLE", -20); (Pos. "AIRFRANCE", -20)]) (def actions [(Pos. "IBM", 55) (Pos. "ACCOR", 40) (Pos. "AIRFRANCE", 10) (Pos. "LUFTHANSA", 100)]) (defn matchOneOptionWithOneAction [options actions x y] (if ( = (:name (get options x)) (:name (get actions y))) (let [sum (+ (:value (get options x)) (:value (get actions y)) )] [ (reduce conj (reduce conj (subvec options 0 x) (vector (Pos. (:name (get options x)) (min 0 sum)))) (subvec options (+ 1 x) (.length options)) ) (reduce conj (reduce conj (subvec actions 0 y) (vector (Pos. (:name (get actions y)) (max 0 sum)))) (subvec actions (+ 1 y) (.length actions)) ) ] ) [options actions] ) ) (defn matchOptionsWithActions [options actions x y] (if (>= x (.length options)) [options actions] (if (>= y (.length actions)) (matchOptionsWithActions options actions (+ 1 x) 0) (let [matchCouple (matchOneOptionWithOneAction options actions x y)] (matchOptionsWithActions (get matchCouple 0) (get matchCouple 1) x (+ 1 y) ) ) ) ) ) (defn matchIt [options actions] (matchOptionsWithActions options actions 0 0 ) ) (let [[matchedOptions matchedActions] (matchIt options actions) ] (println "matched options: " (map str matchedOptions)) (println "matched actions: " (map str matchedActions)) ) On 10 jan, 09:35, Nicolas Garcin <nicolas.etienne.gar...@gmail.com> wrote: > Thanks a lot to all of you. > > Regards, > Nicolas > > On 10 jan, 08:14, Brian Mosley <brian.d.mos...@gmail.com> wrote: > > > > > > > > > Oops. > > A possible solution might look something like that... -- 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