Sunday, 1 June 2014

Berlin Clock


The programming exercise below was shown to me by the writer of From Fragile to Agile.
Click here to see my answer  on GitHub.

"Create a representation of the Berlin Clock for a given time (hh::mm:ss).
The Berlin Uhr (Clock) is a rather strange way to show the time. On the top of the clock there is a yellow lamp that blinks on/off every two seconds. The time is calculated by adding rectangular lamps.
The top two rows of lamps are red. These indicate the hours of a day. In the top row there are 4 red lamps. Every lamp represents 5 hours. In the lower row of red lamps every lamp represents 1 hour. So if two lamps of the first row and three of the second row are switched on that indicates 5+5+3=13h or 1 pm.

The two rows of lamps at the bottom count the minutes. The first of these rows has 11 lamps, the second 4. In the first row every lamp represents 5 minutes. In this first row the 3rd, 6th and 9th lamp are red and indicate the first quarter, half and last quarter of an hour. The other lamps are yellow. In the last row with 4 lamps every lamp represents 1 minute.
The lamps are switched on from left to right.

Test Cases (Y = Yellow, R = Red, O = Off)
Input Result 00:00:00 Y OOOO OOOO OOOOOOOOOOO OOOO
13:17:01 O RROO RRRO YYROOOOOOOO YYOO
23:59:59 O RRRR RRRO YYRYYRYYRYY YYYY
24:00:00 Y RRRR RRRR OOOOOOOOOOO OOOO"


7 comments:

  1. I just forked it, I'll take a look later today :)

    ReplyDelete
  2. We have pretty similar implementations, the main difference is that what you have as private methods I abstracted into their own classes, did you take a look at mine?

    ReplyDelete
    Replies
    1. I've taken a look at your implementation it is quite similar. I was about to go all object oriented and create objects for each rows of lights plus a light bulb object to represent the light bulbs in each row, but then I thought it is not worth the effort on such a small exercise :).

      Delete
  3. I have lived in Berlin 2 years and never in my life seen this clock! :D

    ReplyDelete
    Replies
    1. Hahaha, I think I read somewhere the clock is located in front of a tourist information center in the Berlin Europa Center.

      Delete
  4. Apparently it is in Budapester Straße in front of Europa-Center (wikipedia) :)

    ReplyDelete
  5. Hi Sameeran,

    Sorry to post the irrelevant comment here. I have been using the "Tamil Vanavil FM Player" in Apple iphone. After the IOS 11 update, it is not working anymore. It needs to be updated to the latest 64-bit version. Could you please update the same at the earliest. Thanks.

    ReplyDelete