Unscramble Letters in Java - Get all possible combinations of the letters

0 votes

I am currently an AP Computer Science student. I have been working on a letter unscrambler that reads in a dictionary and prints a list of words possible with the letter set inputted. To this end I make a map with Map<String,Set<String>> in which "earth" would be entered under the key "aerht" and in the corresponding set.

Example How Would I generate all of these:
CAKE -> ACEK
A          C           E           K
AC        CE           EK               
ACE       CEK            
ACEK

AE       CK
AEK
ACK
AK

The problem I am running into is that that some key values aren't being checked as currently I take in a set of numbers and alphabetize the characters eg earth->aehrt yet this skips combos such as aht->hat or eht -> the.

So basically my Question would be how to simplify the process of obtaining all alphabetical combos contained in such a key. eg earth-> aehrt,a,ae,aeh,aehr,ah,ahr,ahrt,aer,aert and so on so that I can crossreference all these keys with those in the dictionary I read in. letters[] contains a,e,h,r,t in order. Also, test is an ArrayList of Set. Key is "aehrt".

for(int z = 0; z<key.length();z++) {
    Set<String> temp = new HashSet<String>();

    //s1 = t*s0 ∪ {t} ∪ s0 = {t}
    for(String str: test.get(z)) //t*s0
                str+=letters[z];

    test.get(z).add(letters[z]); //{t}  
    test.get(z).addAll(test.get(z-1));//s0
    test.get(z).addAll(temp);
}
Apr 13, 2022 in Java by Rahul
• 3,380 points
962 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
2 answers

Get all the permutations of a string in Java

You could use recursion to do this.  Try ...READ MORE

answered Aug 21, 2019 in Java by Sirajul
• 59,230 points
2,272 views
0 votes
2 answers

How can I get the filenames of all files in a folder which may or may not contain duplicates

List<String> results = new ArrayList<String>(); File[] files = ...READ MORE

answered Sep 12, 2018 in Java by Sushmita
• 6,920 points
1,938 views
+2 votes
3 answers

Listing all the subclasses of a specific class in Java

Try with BurningWave core library. Here an ...READ MORE

answered Dec 29, 2019 in Java by anonymous
• 460 points

edited Jan 9, 2020 by anonymous 14,633 views
+1 vote
2 answers

Retrieve all the implementations of an interface in Java

Take a look to this example: https://github.com/burningwave/co ...READ MORE

answered Dec 21, 2019 in Java by Roberto
• 460 points

edited Jul 7, 2020 by Roberto 38,569 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
4,129 views
+1 vote
6 answers

How can I separate the digits of an int number in Java?

You can also have a look here: To ...READ MORE

answered Dec 9, 2020 in Java by Roshni
• 10,480 points
210,170 views
0 votes
2 answers

What is the use of @Override annotation in Java ? When do we use it ?

@Override annotation is used when we override ...READ MORE

answered Aug 14, 2019 in Java by Sirajul
• 59,230 points
3,494 views
0 votes
1 answer

Purpose of “String args[]” in the “psvm” of Java

Let me give you the complete explanation ...READ MORE

answered May 7, 2018 in Java by code.reaper12
• 3,500 points
4,741 views
0 votes
1 answer

What is the concept of Immutability for strings in Java ? Why are strings immutable ?

According to Effective Java, chapter 4, page 73, ...READ MORE

answered May 11, 2018 in Java by Rishabh
• 3,620 points
1,631 views
0 votes
1 answer

How to get the number of digits in an int?

You can find out the length of ...READ MORE

answered May 14, 2018 in Java by Akrati
• 3,190 points
974 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP