The challenge of the WordJumble applet. The challenge of this applet comes from the fact that the number of characters in the Jumble is variable. It's usually 4, 5, 6, or even 7 characters. In a Java program, this means that you can't have simple nested for loops. Fro instance, if you knew that there would be only 5 characters in each. Hidden words. My HiddenWords puzzle-game applet is based on the well-known Jumble word puzzle. Created in 1954 by Martin Nadle, and seen in many newspapers, Jumble presents a set of scrambled letters that you must unscramble to unveil the hidden word or words. Jumble Word Game in Java. In Jumble word game, the computer program randomly picks up a secret word from a database of words and then shuffles it. The shuffled word is presented to the user and he is asked to guess the original word. The program ends when the user correctly guesses the word. The program also prints the number []. Jumble Solver is a simple, fast and easy to use jumble word solver. You enter the jumbled/scrambled words and it tells you the possible words or answers, that can be made from those letters (think of it like a single word anagram). One of them, which I found in my old Java assignments, was a word guessing game. Very small, nothing special. As such, I decided to re-implement it. The game works as follows: You enter the 'secret' word, and then you have 10 tries to guess it.
In my country there is Game Show called Slagalica where one of the tasks is to find longest word in array of 12 letters. Size of the longest word is always 10, 11 or 12.
I have file with words from my language I use as database. Words that have 10, 11 or 12 letters in them I've saved in List (listWordSize10_11_12).When I enter jumbled word [12 letters] in I want from my program to find what word is that originally. I know how to make it work when jumbled word is 12 letters word but I can't work it out when it's less.
Example: 10 letter word is jumbled + 2 random letters.
Goal is for that 10 letter word to be recognized and printed in original state.
Where is what I've done:
Thanks!!!P.S. This is not a homework or some job, just project I've been doing for fun!
Thanks everyone for the help, I've learned a lot!
Word Jumble Unscrambler
2 Answers
Your basic approach for 12 characters, which I would characterize as fingerprinting, will also work for 10 or 11 letter words with some modification.
That is, rather that just sorting the letters in each candidate word as you examine it to create the fingerprint, pre-process your array to create a small(ish) fingerprint of each word as a byte[]
. Using the English alphabet and ignoring case, for example, you could create a 26-byte array for each word, where each byte position contained the count of each letter in the word.
That is fingerprint[0]
contains the number of 'a'
characters in the word, and fingerprint[25]
the number of 'z'
characters.
Then just replace your sorted_Mistery_Word.charAt(j)!=longWords.charAt(i)
check with a loop that increments a temporary array for each letter in the mystery word. Finally, check that the temporary array has at least the same value for every position. Something like:
Here I omitted the creation of the fingerprintList
- but it just involves fingerprint each word.
There are plenty of optimizations possible, but this should already be quite a bit faster than your version (and is 'garbage free' in the main loop). It can handle candidates of any length (not just 10-12 chars). The biggest optimization, if you will check many words, is to try to use the 'fingerpint' as a key for direct lookup. For the 12 character case this is trivial (direct lookup), but for the 10 and 11 or this you would likely have to use type of technique for higher-dimensional searching - locality sensitive hashing seems like a natural fit.
BeeOnRopeBeeOnRopeHere's one way to go about the problem. Let's say (since no example input was provided) that there's 3 String[]'s, arr3
(that represents the 10-letter-words you have), arr4
(that represents the 11-letter-words you have), and arr5
(you guessed it, represents the 12-letter words you have). This is what I made for those:
So based on what you said, if we got the input of pam
, we'd want the output of map
. If we got the input of enni
we'd want the output of nine
. And if we got the input of yfunn
we'd want the output of funny
. So how to go about doing this? I like what @cricket_007 mentioned about using maps. But first, let's get the permutations down.
Based off of the linked SO question, I came up with this modified/variation to get the jumbled text:
This code will let us easily construct a single map for us to store jumbled text in as a key, and the answer to that jumbled text as a value.
Jumble Solver Two Words
All together, the final code looks like this:
Which gives the resulting output of:
Now applying this logic, adapting for your case of 10, 11, and 12 letter words should be relatively simple. Cheers!