Last active
January 6, 2018 07:01
-
-
Save msszczep/08dda9b2f4e1cdad2c00 to your computer and use it in GitHub Desktop.
Subanagram Generator Draft in Clojure
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 subanagram-generator [submitted-word] | |
(let [words (->> (slurp "/Users/msszczep1/Scripts/npr_puzzle_scripts/ni2.txt") | |
(clojure.string/split-lines)) | |
submitted-word-freqs (merge | |
(zipmap "abcdefghijklmnopqrstuvwxyz" (repeat 26 0)) | |
(frequencies (clojure.string/lower-case submitted-word)))] | |
(->> words | |
(filter (fn [word] | |
(let [lc-word (clojure.string/lower-case word)] | |
(every? #(<= ((frequencies lc-word) %) | |
(submitted-word-freqs %)) | |
(set lc-word))))) | |
(group-by count) | |
sort))) | |
(subanagram-generator "representative") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment