Code Jam – Anagrams Code Kata 2

Posted by Conrad Benham on April 07, 2008

Recently we called a Code Jam in which the aim was to give people the opportunity to practice Pair Programming and Test Driven Development. The event also gave people the opportunity to share ideas about how to solve the problem. Most people solved the problem in Java or .NET though one pair solved it using Lua.

Code Jam Photo

We chose Prag Daves Anagram Code Kata as the problem to solve. This code kata which involves identifying anagrams in a given list of words is simple enough to solve in a short period of time while offering some interesting challenges from an algorithm point of view.

I have uploaded a solution to the problem in Java. The solution I came up with was entirely Test Driven except for the Main class. I chose to go for an Object Oriented approach as opposed to a small, potentially terse, solution. If you inspect the code you will see it is quite easy to perform arbitrary queries on the anagrams (via the Anagrams.operate method). It should be a simple exercise to create a class that will find the largest set of anagrams or find any other piece of interesting information.

In attempting this problem, the solution I arrived at found 2531 anagrams – Dave Thomas claims there are only 2530. I’m sure there is a further check I could add but I just can’t see what it is at this point. If I ever stumble on it I’ll be sure to make an update to the code and upload it here.

My solution can be found here.

The solution contains the bare minimum, I have not included a build script, nor have I included any binaries. I decided not to include project files either as people were using different IDE’s for their development.

On an unrelated side note, we will call another meeting just as soon as we’ve found a new venue. The venue we were using for our meetings has unfortunately closed. If you know of somewhere near Central that would be suitable please let me know.


Use this link to trackback from your own site.


Leave a response

  1. Dave Kirby Tue, 08 Apr 2008 01:08:26 UTC

    I got the following results:

    found 2531 anagrams
    longest = [‘algorithmically’, ‘logarithmically’]
    most = [‘pares’, ‘parse’, ‘pears’, ‘rapes’, ‘reaps’, ‘spare’, ‘spear’]

    This took me ten minutes and ten lines of python, compared with your 210 lines of Java in six files (excluding tests).

    This is why programming in Java brings me out in a rash.

  2. bilal Mon, 27 Oct 2008 16:49:12 UTC

    i want the code how we check that the words are anagram