Created
April 11, 2013 15:38
-
-
Save jonathan/5364445 to your computer and use it in GitHub Desktop.
actually do the letter matching for the scrabble program.
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 match-letters? [letters line] | |
(loop [letter-freq (frequencies (clojure.string/lower-case letters)) | |
line-freq (frequencies (clojure.string/lower-case line))] | |
(if (empty? line-freq) | |
(if (not-any? neg? (vals letter-freq)) true false) | |
(if (contains? letter-freq (key (first line-freq))) | |
(recur (update-in letter-freq [(key (first line-freq))] - (line-freq (key (first line-freq)))) (dissoc line-freq (key (first line-freq)))) | |
false)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment