HTW Berlin Medieninformatik

HTW Berlin
Fachbereich 4
Internationaler Studiengang
Internationale Medieninformatik (Bachelor)
Info 2: Informatik II
Winter Term 2009/10


Exercise 12: Scrabble Cheater Deluxe

Finger exercises :
 

  1. 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.
  2. 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:
  1. Get out your solution to Exercise 11 - or borrow a working one from someone. Remember to give them credit.
  2. 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.
  3. Adapt your main to generate a random selection of seven letters to start the cheater with.
  4. (For the bored) Generate your random selection on the Scrabble distribution for English.
  5. 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.
  6. 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.
  7. (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.
  8. (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++.


Copyright 2009 Prof. Dr. Debora Weber-Wulff
Questions or comments: <weberwu@htw-berlin.de>
Some rights reserved. - Copyright and Warranty