-
-
Save orendon/99c7ba3c24160aa140f9c9f39a476660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn permutations [s] | |
(lazy-seq | |
(if (seq (rest s)) | |
(apply concat (for [x s] | |
(map #(cons x %) (permutations (remove #{x} s))))) | |
[s]))) | |
(defn cost [proposoals s] | |
{:permutation s | |
:cost (apply + (map-indexed (fn [project candidate-str] | |
(let [[candidate _] (clojure.string/split candidate-str #"-")] | |
(get-in proposoals [candidate project]))) | |
s))}) | |
(defn basic-seq [candidates max-per] | |
(let [opts (range 0 max-per)] | |
(flatten (map (fn [c] | |
(map (fn [opt] (str c "-" opt)) opts)) | |
candidates)))) | |
(defn mini [proposoals max-per] | |
(apply min-key :cost (map (partial cost proposoals) (permutations (basic-seq (keys proposoals) max-per))))) | |
(mini {"c1" [1 2 30 4] "c2" [4 3 200 1]} 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment