Optional: Enter a clue for each word. Choose whether you would like to scramble the entire word, or just middle letters. Then 'Click to Scramble'. Now your words are scrabled and you can 'Make Word Scramble'. You can then add images, colors and change the size of the font with options in the blue menu (next page). How can I create a simple word unscrambler in java? The program will start by asking the user to input a 'scrambled' word. Then it will compute and output all possible re-arrangements of the letters in the user's input.
![Word Word](/uploads/1/2/6/0/126081545/906214765.gif)
Word Jumble Solver is a small program written in Java which solves word jumble problem.
- Anagram Solver ( Jumbled words to find a meaningful Dictionary word ): Java Program Anagram Solver is one of the most common algorithm which is asked in the interview of the Top most companies like Goldman sachs, Facebook.
- I cannot get my program to compile. What I am trying to do is get the program to print out all the jumbled words with the dictionary words that can be made from it printed next to it.
This program is developed for coding challenge from Twice
Description
- WordJumbleSolver uses a quick lookup dictionary using the words file generally found at
/usr/share/dict/words
on un*x type operating systems. - If running on non-un*x based operating system the user must provide a file containing words delimited by newline like this which will be used as valid dictionary words.
- WordJumbleSolver then build a dictionary from this file where each word is hashed with the product of prime number associated to its characters. Since, products of primes are unique this gurantees that all the word which fall under the same key will be anagrams
- WordJumbleSolver solves the jumble word by generating all possible combination of the jumbled word and finding its anagrams from the dictionary.
- Here is an example
jumbled word : ogd
Word Jumble Solver: Here are the valid words -
og go god dog oddo
File Structure
Filename | Description |
---|---|
App.java | The main Word Jumble Solver class |
AlphabetToPrimeMap.java | Stores alphabet to prime number mapping and calculates prime factors for words |
Combinatorics.java | Combinatorics class which generates all possible combination of string |
Dictionary.java | The dictionary class which stores all the dictionary words which are anagrams to each other in a hash where the key is product of their character's prime number |
OSType.java | The class which helps to determines the type of operating system. Code adopted from here |
##DependenciesThis project depends on the following:
- A newline dependent words file on non-un*x operating system.
##How to useClone the repository on you local machine and from the command line excute to following command from the parent directory
r******@R*****-MacBook-Pro> mvn package
![Word Word](/uploads/1/2/6/0/126081545/111520346.png)
r******@R*****-MacBook-Pro> java -cp target/WordJumbleSolver-1.0-BETA.jar com.rohitsinha.wordjumble.App ogd
On non Un*ix operating system you must provide the path to the words file (a newline delimited file containing all the words). In this case the command will be
java -cp target/WordJumbleSolver-1.0-BETA.jar com.rohitsinha.wordjumble.App filepath ogd
Testing
The program has been tested on following operating systems:
- Mac OSX 10.9.2
- Ubuntu 13.10
##Version1.0 beta
##Contact InformationPlease report any bugs or issues to:[email protected]
##LicenseMIT License
8 Jul 2009CPOL
Find all words that can be derived from a character string using recursion, LINQ, and COM
Introduction
In a recent article, Permutations in C# Using Recursion, I demonstrated the use of a recursive algorithm to calculate all permutations of a given set of items. The algorithm was one of three algorithms introduced in Alexander Bogomolny’s article, Counting and Listing All Permutations. The article can be found on the Interactive Mathematics Miscellany and Puzzles website. In this article and accompanying application, I will use the recursive algorithm to create a word descrambler. Based on a twist to the classic Jumble puzzle, the user inputs a string of 2 to 7 randomly ordered characters. The application will attempt to ‘unscramble’ the string by deriving all permutations of the input string and then searching for them in an English-language dictionary.
Note, you can choose to input any type of characters – letters, numbers, or symbols. All unique permutations will be returned. However, only character-only strings will be correctly identified as known words by the application.
Background
We've all seen the Jumble word scramble game in the newspaper. An example of this classic puzzle game can also be found online at UCLICKgames.com. The letters that make up a word are displayed in a random order. The goal is to rearrange the letters and discover the hidden word. Jumble puzzles normally have only one right answer. Jumble puzzles usually range from simple four-letter words to harder-to-solve six-letter words. While four letters have only 120 possible permutations, six letters have six times as many possible permutations (720), making them much harder to solve.
The application uses the recursive algorithm to solve the puzzle very similar to how we might solve it. We usually start visualizing or jotting down combinations of letters in the puzzle until we chance upon a recognizable word. Sometimes, we just ‘see’ the word right off; other times we struggle incessantly for the answer. Of course, sometimes the answer eludes us because of the limits of our vocabulary. We chance upon a word, but since we are unfamiliar with it, we discount it and continue permuting. Unlike us, the application can quickly search an entire dictionary for all possible matches.
Word Jumble Java Code
Using the Code
To demonstrate the use of recursive algorithm to descramble a string of characters, I have created a simple Windows Forms Application. The application is built in C# 3.0, using Visual Studio 2008, on the .NET Framework 3.5. It consists of a single Windows form and a separate, small class file containing the methods, fields, and properties that define the game’s logic. As discussed earlier, the application uses Bogomolny’s original methods, which have been converted to C# from Java. The original methods, fields, and properties are renamed to create more readable, easy-to-understand C# code.
Below is the Permutations.cs class file, which contains the game’s logic. The actual source code has full commenting for each method.
Microsoft Word 11.0 Object Library
Daily Word Jumble
The application uses the spell checking capabilities of Microsoft Office Word 2003 to determine if each permutation is a recognized word. I did so adding a COM reference to the Microsoft Word 11.0 Object Library assembly to the project. If you own Microsoft Office Word 2007, you will need to add the Microsoft Word 12.0 Object Library assembly to your project. Using COM or Microsoft Word are not necessarily the best, or the only solutions. There are other applications and utilities, including freeware, which could be interfaced with the application. An alternate approach would be a web service. Each permutation or a list of permutations could be sent to a remote web service, which would provide spell checking.
To minimize memory usage, the application creates a single instance of the Word Application interface (
wordApp
) to call the CheckSpelling(string theWord)
method for each individual permutation. When complete or when an exception occurs, the wordApp
object is destroyed by calling the Quit()
method. When wordApp
is processing permutations, you will note an instance of WINWORD.EXE running in Task Manager’s Processes tab.The Descrambler Process
- Construct a character array from the string input by the user (ex.
cdeo
->{c, d, e, o}
). - Use the recursive algorithm to calculate each permutation of the characters based on the character’s position (example:
{1, 4, 2, 3}
). - Create the character permutation, by matching the numeric position-based permutation to the corresponding characters in the character array (ex.
{1, 4, 2, 3}
->{c, o, d, e}
). - Store the character permutation as a
string
in aList<string>
object (ex.{code}
). - Remove any duplicate permutations from the
List<string>
. See explanation below. - Use LINQ’s
Where()
extension to send each permutation in theList<string>
to theCheckSpelling(string theWord)
method, which in turn calls Microsoft Word. - Store only those permutations that have a return Boolean value from the
CheckSpelling(string theWord)
method oftrue
, indicating the permutation was found in Word’s dictionary, in a secondList<string>
object. - Return a sorted list of all permutations to the user, with correct answer(s) listed first. Also included at the end is a summary of the results.
The recursive algorithm’s methods are very fast, while passing the results to the Word object for spell checking can be time consuming. A progress bar at the bottom of the UI is updated as each permutation is spell-checked by Word. It is important not to change windows while the application is running.
Handling Duplicate Permutations
Unlike the Console Application in the previous article, this Windows Application removes duplicate permutations using LINQ’s
Distinct()
extension. Duplicates are produced when identical characters exist in the input string, producing duplicate permutations. For example, the word ‘tester’ has two letter t’s and two e’s, which would generate 540 duplicate permutations out a total of 720 possible permutations. Permutations in the existing List<string>
are copied to a second List<string>
object using LINQ’s Distinct()
extension, eliminating duplicates. See the example below, which has been foreshortened for display purposes.Installing the Source Code
To use the source code, create a Windows Forms Application in Microsoft Visual Studio 2008 entitled ‘Unscramble’. Replace the default Form1.cs files with the source code’s Form1.cs files. Add in the Permutations.cs class file. Lastly, add a COM reference to the Microsoft Word 11.0 Object Library assembly (
Microsoft.Office.Interop.Word
). In doing so, two other assemblies, Microsoft.Vbe.Interop
and Interop.Microsoft.Office.Core
, will be automatically added to your project’s reference folder. If you implement an alternate spell checking method other than Word, you will need to modify the CheckTheSpelling(string)
method. History
- June 28, 2009 - version 1.0
- Initial version
- July 6, 2009 - version 1.1
- Rewrote the
OutputPermutations()
method to list correct answers first, and provide a better results summary - Changed maximum input
string
length from 6 characters (720 possible permutations) to 7 characters (5,040 possible permutations) - Updated article and article’s code references
- Rewrote the