Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View nbeloglazov's full-sized avatar

Mikita Belahlazau nbeloglazov

View GitHub Profile
@nbeloglazov
nbeloglazov / salesman.clj
Created August 15, 2012 09:17 — forked from djanatyn/salesman.clj
salesman
(defn move-to-front [first others]
"Moves an item to the front of the list"
(cons first (remove #(identical? first %) others)))
(defn first-level [list]
"Returns a list of all first-level permutations."
(map #(move-to-front % list) list))
(defn permute-deeper [depth list]
"Takes a list and a depth. Ignores the first few items according to the depth, and returns a list of all permutations for the rest."
(let [head-of-list (take depth list)
rest-of-list (drop depth list)