Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env clj
(use 'clojure.java.io)
(require ['clojure.contrib.string :as 'string])
(def pairs (first *command-line-args*))
(defn reciprocal-edge? [edges]
(let [a (nth edges 0)
b (nth edges 1)]
(= (take 2 a) (take 2 b))))
(defn transform-weight [weight]
(Math/round (- (Math/log10 (+ 1e-40 (Float/parseFloat weight))))))
(defn normalise-edge [edges]
(let [vertices (take 2 (nth edges 1))
weights (map #(transform-weight (last %)) edges)]
(flatten [vertices (apply min weights)])))
(def normalised-edges
(map normalise-edge
(filter reciprocal-edge?
(partition 2 1
(map #(string/split #"\s" %)
(line-seq (reader pairs)))))))
(doseq [i normalised-edges]
(println #(apply str (interpose "\t" i))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.