Code Kata: Berlin Clock

22. Juni 2014 - Code Kata / Computer Science

Berlin ClockRecently I discovered a nice “new” Code Kata – the Berlin Clock. This is a nice Kata for practising Test Driven Development. I’m neither going to explain the Code Katas in general nor Test Driven Development in this post – maybe this will become a separate post later.

For a historical background please check the detailed description of the Berlin Clock. For implementing such a clock in the language of your choice, you need to know the following specification:

The time is calculated by adding the lit rectangular lamps. The top lamp is a pump which is blinking on/off every two seconds. In the upper line of red lamps every lamp represents 5 hours. In the lower line of red lamps every lamp represents 1 hour. So if in the first line 2 lamps are lit and in the second line 3 lamps its 5+5+3=13h or 1 p.m. In the third line with tall lamps every lamp represents 5 minutes. There are 11 lamps, the 3rd, 6th, and 9th are red indicating the first quarter, half, and the last quarter of the hour. In the last line with yellow lamps every lamp represents 1 minute.

Implement the clock as a function of the three parameter hours (24-based), minutes, seconds and return a multi line string. Find a reasonable representation for the colors and states.

If you don’t follow a test driven approach, try to find reasonable test cases.

Below are two small change request. Implement the standard solution first. Evaluate how much effort it is to adapt your solution. (Hover to make the text readable.)

Build a ticking clock in a textual representation.
Use any graphic frame work supported by your language and implement the running clock with a nice visual representation.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert