You are viewing a single comment's thread. Return to all comments →
Clojure
(use '[clojure.string :only (join split triml)]) (def n (Integer/parseInt (read-line))) (def data (vec (for [_ (range n)] (let [ x (clojure.string/trimr (read-line)) y (clojure.string/split x #"\s+") z (->>(map #(Integer/parseInt %) y) (apply hash-map))] z)))) (defn gcd-map-pair [m1 m2] (reduce (fn [acc k] (assoc acc k (min (get m1 k 0) (get m2 k 0)))) {} (keys m1))) (defn gcd-maps [li] (sort-by first (reduce #(gcd-map-pair %1 %2) li))) (println (->> (gcd-maps data) (filter (fn [[k v]] (> v 0))) (sort-by first) (flatten) (join " ")))
Seems like cookies are disabled on this browser, please enable them to open this website
Lists and GCD
You are viewing a single comment's thread. Return to all comments →
Clojure