Skip to content

Instantly share code, notes, and snippets.

@michaelbarton
Created April 17, 2012 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelbarton/2406699 to your computer and use it in GitHub Desktop.
Save michaelbarton/2406699 to your computer and use it in GitHub Desktop.
#!/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