On Oct 17, 11:48 pm, Michael Linfield <globyy3... / hotmail.com> wrote:
> Making an form of an anagram solver. My approach would be the code
> listed below but there has to be a cleaner way to do it.

As others have mentioned, simply generating all permutations may not
be the best way to solve an anagram, but here's a recursive
permutation generator:

def words chars, result='', &b
  if chars.empty?
    yield result
  else
    chars.length.times do |i|
      c = (x = chars.clone).slice!(i)
      words(x, result + c, &b)
    end
  end
end

word = 'dog';
words(word.split('')) {|s| puts s }