shouldnt both words contain the same value since both have the same characters? [...] is there any sort of value that is stored based on the characters that make a word? If there are then i could just create a list and search each word for this value until the pairs match. |
For example "bucky" the scrambled word would be "ubcyk" |
; definition (defn find-originals [scrambled-word] (let [all-words (-> "dictionary_with_one_word_per_line.txt" slurp (clojure.string/split #"\n")) target-frequencies (frequencies scrambled-word)] (filter #(= (frequencies %) target-frequencies) all-words))) ; usage (find-originals "ertlan") ; ("antler" "learnt" "rental") |
The aha! insight is to sign each word in the dictionary so that words in the same anagram class have the same signature, ... We'll use a signature based in sorting: order the letters within the word alphabetically. (Footnote: This anagram algorithm has been independently discovered by many people, dating at least as far back as the mid-1960's.) ... When an equivalence relation defines classes, it is helpful to define a signature such that every item in the class has the same signature and no other item does. Sorting the Jon Bentley in 'Programming Pearls' http://www.amazon.com/Programming-Pearls-Jon-Bentley/dp/8177588583 |
|
|