I've been writing a program that will take user jumbled input, find it in a given file, and print the unjumbled word. I've written most the code up to this point but I haven't been able to finish it and am stuck at how to fix it. I've included the code below for viewing, any mistakes you see or pointers would be a great help.
Here's what I have to do:
Write a user defined function (to_array) that converts a String object to an array
Write a method (get_permulations) that inputs an array of single characters (like ["j", "o", "e"]). The method returns an array of all permutations of the Jumble string. The permutations in the array will be in string format
Then after that compare the words in the Unix dictionary(dict.txt as seen in below code) to the permutation strings in the array and print any matches
Here's my code, I know there are a lot mistakes, again any help would be appreciated:
def to_array() s = [" "] s.each do |a| end print a, "\n" def gets_permutations() perms = a.permutation(3).to_array.collect do |perm| perm.join end print perms, "\n" print "Enter Word to jumble: " c = STDIN.gets.chomp a = to_array(c) print a, "\n" perms = get_permutations(a) print perms, "\n" fin = file.open("dict.txt", "r") while line = fin.gets word = line.chomp if word = word.downcase for perm in perms if perm = word print word, "\n" end end end end fin.close