After years of study, scientists at Google Labs have discovered an alien language transmitted from a faraway planet. The alien language is very unique in that every word consists of exactly L lowercase letters. Also, there are exactly D words in this language.
Once the dictionary of all the words in the alien language was built, the next breakthrough was to discover that the aliens have been transmitting messages to Earth for the past decade. Unfortunately, these signals are weakened due to the distance between our two planets and some of the words may be misinterpreted. In order to help them decipher these messages, the scientists have asked you to devise an algorithm that will determine the number of possible interpretations for a given pattern.
A pattern consists of exactly L tokens. Each token is either a single lowercase letter (the scientists are very sure that this is the letter) or a group of unique lowercase letters surrounded by parenthesis ( and ). For example: (ab)d(dc) means the first letter is either a or b, the second letter is definitely d and the last letter is either d or c. Therefore, the pattern (ab)d(dc) can stand for either one of these 4 possibilities: add, adc, bdd, bdc.
I liked the problem. See in the page that we should read an input file with the words and patterns to process. We can download input files from the problem page, and upload an output file with our solution, generated by our problem. Then, Google will return if the answer is correct or not. So, I wrote a solution using TDD:
You can read commit history, with test granularity, at:
One of the latests things I did was to refactor the detection of words that match a pattern. I could improve it, maybe using a word tree instead of a list of words, as I did in SimpleBoggle.
At the end, I wrote a console program that accepts an input file and writes an output file, as Google contest requires. I downloaded a big input file from Google, processed it, and uploaded the solution. Google answered: OK:
TDD rules 😉