Angel \”Java\” Lopez on Blog

May 6, 2013

TDD Kata (2): Alien Language

Previous Post
Next Post

Some week ago, Google Code Jam was mentioned in Spanish list TDDev.  One of the  past problems of this contest was Alien Language.

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:

https://github.com/ajlopez/TddOnTheRocks/tree/master/AlienLanguage

You can read commit history, with test granularity, at:

https://github.com/ajlopez/TddOnTheRocks/commits/master/AlienLanguage

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 ;-)

Keep tuned!

Angel “Java” Lopez
http://www.ajlopez.com
http://twitter.com/ajlopez

2 Comments »

  1. [...] TDD Kata (2): Alien Language [...]

    Pingback by TDD Kata (2): Alien Language | MVPs de LATAM — May 7, 2013 @ 3:19 pm

  2. [...] Previous Post [...]

    Pingback by TDD Kata (3): TaTeTíTomek | Angel "Java" Lopez on Blog — May 8, 2013 @ 1:42 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Theme: Shocking Blue Green. Get a free blog at WordPress.com

Follow

Get every new post delivered to your Inbox.

Join 67 other followers

%d bloggers like this: