HTW Berlin
Fachbereich 4
Internationaler Bachelor Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Summer Term 2018
Exercise 12: Scrabble Cheater Deluxe
Finger exercises :
What was a permutation? How can you generate all permutations of the characters in a String? What if some of the letters are the same.
Given a selection of n pizza toppings - how can you generate a list of all of the different k-toppings where k<n? Hint: Look at the binomial coefficient. Write a method that takes a String of n characters and returns an array of k-character Strings that are all characters in the original string.
In class:
Choose one of your solutions to Exercise 11 from last week (or borrow a working one from someone. Remember to give them credit!).
If you didn't do this last week, write a method bool isPermutation (String a, String b) {...} that determines if a and b are permutations. Use this in your output from the cheater so that only permutations of the input string are printed out, and not all of the collisions.
Adapt your main method to generate a random selection of seven letters to start the cheater with.
Make a class that upon instantiation with a given String of characters, determines all of the Strings that are substrings in the sense that they only contain letters from the given String, with multiples only up to the number of multiples available. The order of the letters is irrelevant, so this is a bag. For example with 4 letters "JAVA" this would be {"AAJV", "AJV", "AAJ", "AAV", "AA", "AJ", "AV", "JV"}. Don't worry about single letters. Your finger exercise should come in handy here.
Now set up the Scrabble Cheater DeLuxe: read in 7 letters, split them into collections of 7-, then 6-, then 5-, ... words contained in the input bag of letters. Look up each word in each collection in the corresponding dictionary. If you find something, output it.
(For the bored) Generate your random selection of characters depending on the Scrabble distribution for English
(For the bored) Collect up all the words which are only permutations of the looked up word, and sort them all, irrespective of length, alphabetically, before outputting them.
(For the really bored) Check out http://www.morewords.com and see that you can use wild cards such as "-" for matching any one character and "*" for matching any string. Can you replicate this behavior (even if it is much slower than morewords)?