HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2010/11
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:
Get out your solution to Exercise 11 - or borrow a working one from someone. Remember to give them credit.
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 to generate a random selection of seven letters to start the cheater with.
(For the bored) Generate your random selection on the Scrabble distribution for English.
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 will 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) 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)?
Now look back to the shapes exercise last semester - You have come a long way in Java! And you have survived! The next exercises will be in C++.