Method Help with Ruby
Go to solution
Solved by flowalex,
Thank you for your help, I was talking with a classmate and they noticed I made a mistake in the method creation. Here is the code for future reference
#method creationdef to_array letter return letter.chars.to_aenddef get_permutations letter_array return letter_array.permutation.map(&:join)end#asking for user inputprint "Please enter a string of letters: "input_str = gets.chomp#opening the dictionarydictionary = File.open("dict.txt", "r") #assigning the arrayarray = to_array(input_str)#getting the permutationsperms = get_permutations(array)#while loop that compares the permutations with the unix dictionarywhile line = dictionary.gets perms.each do |perm| if line.chomp.downcase == perm.downcase print perm, "\n" exit end endend#closes the dictionary filedictionary.close
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now