commit @duckinator's minimum-unambiguous-path fn, per #16

This commit is contained in:
Morgan 2015-07-04 01:19:36 +00:00
parent 72705caa5e
commit 8839c2f9c7

View File

@ -43,3 +43,13 @@
acc2 (conj acc pair)] acc2 (conj acc pair)]
(if (empty? todo) (reverse acc2) (if (empty? todo) (reverse acc2)
(recur acc2 row next (rest todo)))))) (recur acc2 row next (rest todo))))))
(defn minimum-unambiguous-path
([pronouns-table sections] (minimum-unambiguous-path pronouns-table sections 1))
([pronouns-table sections number-of-sections]
(let [sections-subset (take number-of-sections sections)
results (filter (fn [pronouns] (= (take number-of-sections pronouns) sections-subset)) pronouns-table)]
(case (count results)
0 nil
1 (clojure.string/join "/" sections-subset)
(recur pronouns-table sections (+ number-of-sections 1))))))