Skip to content

Instantly share code, notes, and snippets.

@cshepp
Created March 22, 2015 21:10
Show Gist options
  • Save cshepp/da6082d77bbe7520b54c to your computer and use it in GitHub Desktop.
Save cshepp/da6082d77bbe7520b54c to your computer and use it in GitHub Desktop.
(defn calculate-fitness [genome]
"Returns the total distance travelled for a given solution"
(let [path (pathify genome)
distances (map get-distance path)]
(reduce + distances)))
(defn pathify [vec]
"turns a vector into a vector of transitions,
including last element back to the first
ex: [0 1 2] -> [[0 1] [1 2] [2 0]]"
(map (fn [i]
(subvec (into vec vec) i (+ 2 i)))
(range (count vec))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment