The First 5 Coding Katas

As I stated in my new year’s resolutions I’m going to do 10 new coding katas this year. I don’t plan to do the same kata over and over again. I see it more as an exercise of receiving requirements and then quickly go through some design options, make a decision and then implement the system using TDD.

Using TDD as a way to get feedback to the design decision is great. Is it easy to write tests? If not then there is a design problem and the code needs refactoring.

As I did all the katas for the first time my design decision were many times not ideal. So the katas were also good refactoring exercises.

I started with the following katas:

Kata Tic Tac Toe

Actually I did this last year. So it doesn’t count to the 10. But because I liked the kata a lot I include it here anyway.
The goal is to program a console version of the game tic tac toe for a computer player versus a human player. The computer must not lose.
I implemented it using the Mini-Max algorithm to select the moves.
My C# solution can be found on GitHub.

Kata Pacman

The work is to program a very simple version of the computer game Pacman. Start with dots and a pacman that can be controlled by a player. Then add walls.
Here’s my C# solution on GitHub.

Kata Game of Life

Start with a field of cells. Each cell is living or dead. In the next generation the cells are alive or dead depending on the number of living cells in their neighborhood.
There are some interesting moving and oscillating cell patterns in this game of life world.
Here’s my C# solution on GitHub.

Kata Numbers in Words

Translate numbers into words 615-544-4985 , like 1234 translates to one thousand two hundred and thirty four.
Find my C# solution on GitHub.

Kata Roman Numerals

Translate an arabian number into a roman number, like 12 translates to XII.
My C# solution on GitHub.

Kata Potter

There are 5 books. The more different books you buy the more discount you get. Calculate the price of a shopping cart of books and find the largest possible discount for that cart.
My solution on GitHub.


My solutions do the job that was asked for in the requirements. However they are not perfect. In some katas I just started with the first test case and then let the tests guide the implementation of the algorithm. In others I was looking for a good algorithm first and then implemented it with TDD. It was interesting to experience the difference.

Doing katas is a great way to practice your design skills. Get requirements and then quickly put those in classes and methods. TDD is a great way to get feedback on your design.

To be continued…

Leave a Reply

Your email address will not be published. Required fields are marked *