-2

For example, say I have a string and it has the letters:

RDNAL

This is not an actual English word or it doesn't start an actual english word, so the program would skip this string and would avoid it.

But say the string was:

MICRO

This is the first 5 letters of an actual word, like microwave or microprocessor, etc. And it actually is a word

I want to write a program in Java that will be able to see if a given string contains any block of strings that belong to a potential word.

I'm playing a game where I have to decypher a secret language, so I set numbers equal to each "character", and now I want to run each number and put an English letter to each number and see if it possibly spells out a word.

Is this possible or is this just way too massive to do? I'm asking here because I'm not sure if it's impossible or possible based on the number of combinations or some kind of program to reference to check words against.

I think I can write the program to add a letter to each number then rotate through and spit out a string, but I am not sure about comparing the string to an English word.

  • Just get a dictionary, truncate words to 5 letters and generate a hashset from that. – CodesInChaos Mar 8 '15 at 17:04
1

Possible? Yes.

You should be able to download a word list (example) and compare each word's first five letters with your string, however it isn't going to be very efficient. IMHO.

If you need to check more than a few words, then it may be useful to look into optimizations. For example, you could precompute a giant HashMap which contains all valid 5 letter combinations and easily check against that.

  • 3
    This answer pretty much nails it, but more advice on "optimizations": OP should definitely use at least a binary search in the initial prototype, since it's so simple and will make a huge difference, but if that's not enough then look at tries and/or HashMaps. – Ixrec Mar 8 '15 at 11:01
  • 1
    I disagree because you have no idea whether the OP's performance here even matters in the slightest. – DeadMG Jun 6 '15 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.