From 8839c2f9c7a7a898912f0624473cd41bd0219e4b Mon Sep 17 00:00:00 2001 From: Morgan Date: Sat, 4 Jul 2015 01:19:36 +0000 Subject: [PATCH] commit @duckinator's minimum-unambiguous-path fn, per #16 --- src/pronouns/util.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pronouns/util.clj b/src/pronouns/util.clj index 8327568..6a27c30 100644 --- a/src/pronouns/util.clj +++ b/src/pronouns/util.clj @@ -43,3 +43,13 @@ acc2 (conj acc pair)] (if (empty? todo) (reverse acc2) (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))))))