Java Solve Simple Java Annagrams Problem

  • Thread starter Thread starter akan
  • Start date Start date
  • Tags Tags
    Java
AI Thread Summary
The discussion revolves around enhancing a Java class designed to find anagrams from single words to sentences. The original assignment involved creating a HashMap that maps sorted sequences of letters to their corresponding anagrams using a HashSet. The new challenge is to adapt this functionality for multi-word phrases while keeping the existing database structure intact. A proposed approach includes splitting the input sentence into individual words, applying the existing anagram logic to each word, and then generating combinations of the resulting anagrams. The complexity of generating all possible combinations, especially for longer sentences, is acknowledged, with a suggestion to start with two-word combinations before scaling up. The original poster has since found a solution, indicating the discussion is now closed.
akan
Messages
58
Reaction score
0
[SOLVED] Simple Java Problem

Hello,

In my computer science class, we were assigned to design an annagrams class, which would create a HashMap of String => HashSet, a sorted sequence of letters mapped to all annagrams of those letters found in the dictionary. This was done.

Sample entries from the "database":
opst => 'spot', 'pots', 'tops', 'stop';
'act' => 'act', 'cat';

Now, the new assignment is to generalize the class such that the class could find annagrams of sentences, not just single words. And the professor is suggesting that the mapping database should remain as-is, with no further modifications. Can someone please give a hint as to how this could possibly be done "the right way"?

Sample of desired output:
'computer science' => 'cement occupiers', 'ecumenic copters'.

Thank you.
 
Last edited:
Technology news on Phys.org
I'm not sure about the right way but this is how i'd do it:

1. Convert the input string into separate words and store each word in a new string.
2. Apply whatever method you used in your initial class to produce HashSets for each of these word strings.
3. Convert these HashSets to arrays of Strings.
4. Produce a new array of strings where each string is one possible combination of the annagrams in the right order.

There's probably an easier way and I'm not sure if this helps either, perhaps some insight into how your initial class works, i mean maybe you wouldn't even need to split the string up into different words. Number 4 would probably be the most difficult to implement trying to get every combination especially with longer sentences. Perhaps it'd be easier to try and produce every combination for 2 words first and then extend the method to more when it works.
 
Thanks, but I've already found a solution. :)
The question may now be considered closed.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
13
Views
3K
Replies
1
Views
3K
Replies
5
Views
3K
Replies
1
Views
3K
Replies
5
Views
3K
Replies
1
Views
3K
Replies
2
Views
3K
Replies
1
Views
4K
Back
Top