Others have already shown you how you can generate all permutations of a
sequence without having to type all possible ones.

However, I'd ask why are you using class variables (ones starting with
@@)? At least in its current form, your solution seems quite procedural,
so it seems like simple local variables would suffice. You only need @@
if you want some value to be shared by all instances of a given class.

Sorry if that was actually your intent.

mortee

Michael Linfield 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.
> 
> ################
> 
> 
> puts "Word: "
> @@word = gets.chomp
> @@res = @@word.split('')
> 
> def letters5
>   letters5 = @letters5
> puts "Displaying All Possible Solutions..."
> puts "####################################"
> @@res = @@word.split('')
> 
>   puts "#{@@res[0]}#{@@res[1]}#{@@res[2]}#{@@res[3]}#{@@res[4]}"
>   puts "#{@@res[1]}#{@@res[0]}#{@@res[2]}#{@@res[3]}#{@@res[4]}"
>   puts "#{@@res[2]}#{@@res[1]}#{@@res[0]}#{@@res[3]}#{@@res[4]}"
>   puts "#{@@res[3]}#{@@res[1]}#{@@res[2]}#{@@res[0]}#{@@res[4]}"
>   puts "#{@@res[1]}#{@@res[4]}#{@@res[2]}#{@@res[3]}#{@@res[0]}"
>   puts "#{@@res[1]}#{@@res[2]}#{@@res[0]}#{@@res[3]}#{@@res[4]}"
>   puts "#{@@res[1]}#{@@res[3]}#{@@res[2]}#{@@res[0]}#{@@res[4]}"
> 
>   #THE LIST GOES ON :(
> end
> 
> 
> 
> 
> if @@res.length == 5
>     letters5
>   end
> 
> 
> ##################
> 
> As you can imagine this would take me a ridiculous amount of time for
> words that are 7 characters or longer...
> 
> Any ideas?
> 
> Thanks!