On Oct 19, 2:01 am, Michael Linfield <globyy3... / hotmail.com> wrote:
> Thanks all ----
>
> Final Result:
>
> ##############################
>
> require 'rubygems'
> require 'facets/enumerable'
>
> puts "###################################"
> puts "###        Anagram Solver       ###"
> puts "###################################"
>
> print "Enter Word: "
> letters = gets.chomp
> modletters = letters.split('')
> res = []
>
> modletters.each_permutation {|word| res << word.join}
> puts "Finding All Possible Combinations..."
>
> file = open('dict1.txt') {|p|  p.readlines}
> dict = []
> file.each {|p| dict << p}
>
> res.collect! {|c| c + "\n"}
>
>     puts "Finished."
>     puts "Solution: #{res&dict}"
>
> ######################################
>
> How accurate it is depends on the dictionary, i used an 8mb password
> dictionary so the common issue is that it comes up with garble words in
> the list of solutions sometimes, and sometimes spells the word
> backwards, but none-the-less the word im looking for is always there.
>
> Feel free to improve it if you see a flaw or a better way of doing it

Can your program solve this anagram (a very common word)?
"aaabcehilllpty"

It might take a while. The word provides a hint (in two separate ways)
for an improvement.

Using my code from another post will speed up the permutation
generation by a factor of 3, but that is no match for an O(n!)
algorithm. I think you'll need a new technique for longer words.

Also, since the anagram and the actual word must be the same length to
match, you can partition the dictionary by word size. That and the
hint above should get you a long way down the road.

Brian Adkins