Wikipedia description: "A code kata is an exercise in programming which helps programmers hone their skills through practice and repetition. The term was probably first coined by Dave Thomas, co-author of the book The Pragmatic Programmer, in a bow to the Japanese concept of kata in the martial arts."
We recommend using Test Driven Development to solve these small exercises. Use your favourite programming language or learn a new language through the magic of a kata.
There are loads of different solutions to a kata. Which one will you come up with?
Write a program that returns the numbers 1 - 100 but replacing every number that is divisible by 3 with "Fizz" and every number divisible by 5 with "Buzz".
The program accepts an amount of money and will return the change in the highest denomination of coins possible. E.g. for British coins:
3p --> coins: 2p, 1p
15p --> coins: 10p, 5p
58p --> coins: 50p, 5p, 2p, 1p
A program that converts an arabic number into a roman numeral. E.g. 1 --> I, 2 --> II etc.
Write a program that scores a game of bowling. Here are the details
The method takes two arguments: a string of text and the column width. The task is to return the string with line breaks (\n
) inserted at the write places so the words fit into the columns. The words should not be chopped up - the line break should be where the spaces are.
This kata is practised during the Global Day of Coderetreat. Implement the rules of the game:
The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
- Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
- Any live cell with two or three live neighbours lives on to the next generation.
- Any live cell with more than three live neighbours dies, as if by overpopulation.
- Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The Berlin Clock is a clock that tells the time using a series of illuminated coloured blocks. The top lamp blinks to show seconds- it is illuminated on even seconds and off on odd seconds. The next two rows represent hours. The upper row represents 5 hour blocks and is made up of 4 red lamps. The lower row represents 1 hour blocks and is also made up of 4 red lamps. The final two rows represent the minutes. The upper row represents 5 minute blocks, and is made up of 11 lamps- every third lamp is red, the rest are yellow. The bottom row represents 1 minute blocks, and is made up of 4 yellow lamps.
Write a programm that you can give hours, minutes and seconds and that returns the correct illumination of lamps in each row. More info here
The task is to move a robot around on a finite grid. But be careful, the robots should not fall of the grid! The explanation for this kata is on this github repo.
Search for these katas on youtube and for some of them you'll find loads of screencasts of people solving them.