How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Ingo U Your Own Question
Ingo U
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience:  Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
Type Your Homework Question Here...
Ingo U is online now
A new question is answered every 9 seconds

Unscramble permuted words by generating all permutations

Customer Question

Unscramble permuted words by generating all permutations of Jumble string and searching for word in Unix dictionary. It is due no later than Friday. It requires the programming language of Ruby on Rails, the output must be viewed in the command prompt, and the files should be saved as a rb file. There is a txt file for section three. There is three parts to this HW.

1. Write a user defined function named to_array that converts a String object to an array like this:

        s = "dog" a = to_array(s)

        print a, "\n"

            • Output: ["d", "o", "g"]

2. Write a method called get_permulations that inputs an array of single characters (like ["d", "o", "g"]).  The  method should return an array of all permutations of the Jumble string. The permutations in the array should be in string format.

      a = ["d", "o", "g"] perms = get_permutations(a)

      print perms, "\n"

        Output: ["dog", "dgo", "odg", "ogd", "gdo", "god"]

3. Compare the words in the Unix dictionary to the permutation strings in the array. Print any matches that are found. Here is some that might help:

        Define to_array method (Item 1).

        Define get_permutations method (Item 2).

        # ***** main script.

        # ***** in a comment the Jumble strings you

        # ***** for testing. Include at least two test strings.

        Input Jumble string from keyboard. (Be sure to remove "\n" from end of input.)

        Obtain array of letters from Jumble string using to_array method (Item 1).

        Obtain array of permutations from array using get_permutations method (Item 2).

        Open Unix dictionary file to create file object fin.

        while more lines in dictionary file get line

          Get word from line of dictionary file.

          if word starts with a lower case letter

            for each permutation in array called perm

              if perm is equal to word

                 print word

                 exit script




endClose file object fin.


 pseudocode section 3


Submitted: 2 years ago.
Category: Homework
Expert:  Ingo U replied 2 years ago.

HI, I will have a look at this. I got the hw doc and dict.txt, anything else I'll need?

What version of Ruby?

Customer: replied 2 years ago.
Ruby on Rails. 2.2. That's the latest version I've downloaded on my laptop.
Expert:  Ingo U replied 2 years ago.
Thanks - here are your files:
Parts 1#2:
Part 3:
Make sure the dict.txt file is in the same directory.
Please let me know if you need anything else!
Customer: replied 2 years ago.

Is it possible to include test strings included in a comment and source code comments for what each particular section does? They don't have to be detailed just a brief sentence or comment.

Expert:  Ingo U replied 2 years ago.
OK, updated files are in the same place:
Hope that helps!
Customer: replied 2 years ago.
Number 3 retrieves three words, can you possibly have it retrieve only one word. The classes in that document are a bit too advanced at this point in my class.
Expert:  Ingo U replied 2 years ago.
Do you mean only ask the user for 1 word to test, or only look for one match per test word in the dictionary?
Customer: replied 2 years ago.
To ask the user 1 word to tes and have it output one result.
Expert:  Ingo U replied 2 years ago.

You need to spend $3 to view this post. Add Funds to your account and buy credits.
Customer: replied 2 years ago.
It's supposed to unscramble the words being entered. For example, if you type in tac it should print cat.
Expert:  Ingo U replied 2 years ago.
That's what I had before! Then you said one word to test and only one result. So now it only prints the first word found in the dictionary. well if you enter tac, it finds "act" before "cat".
So I took out the line "return" that makes it quit after finding a dictionary word. Now it prints "act" and "cat".
Expert:  Ingo U replied 2 years ago.
just following up, were you able to use my solution?
Please feel free to post any additional questions, comments or concerns you may have regarding this issue.
If you're not yet satisfied with the result, please let me know what is missing.
I will do my best to make it right for you.
Otherwise, please don't forget to rate my service - I don't get paid for my work until your rating is received.
Ingo U