16
1
Someone built a really fancy clock using Fibonacci numbers, which looks really nice but is fairly unusable. Just the way we like it! Let's recreate this.
The clock is made up of 5 sections corresponding to the first five Fibonacci numbers, starting from 1 (i.e. 1, 1, 2, 3, 5):
ccbeeeee
ccaeeeee
dddeeeee
dddeeeee
dddeeeee
The clock is capable of displaying the 12-hour time in increments of 5 minutes. Here is how that works. Consider the time 7:20. The hour 7 can be decomposed into the given Fibonacci numbers as
7 = 2 + 5
There are also 4 units of five minutes. The 4 can be decomposed as
4 = 2 + 1 + 1
Now the hours are shown in red, the minute chunks in green, and if a number is used for both hours and minutes it's shown in blue. If a number isn't used at all, it remains white. So the above would be shown as:
BBGRRRRR
BBGRRRRR
WWWRRRRR
WWWRRRRR
WWWRRRRR
But wait, there's more. The above decompositions aren't the only possibilities. One can also write 7 = 3 + 2 + 1 + 1
and 4 = 3 + 1
, which would give one of
GGRWWWWW GGBWWWWW
GGBWWWWW GGRWWWWW
BBBWWWWW or BBBWWWWW
BBBWWWWW BBBWWWWW
BBBWWWWW BBBWWWWW
depending on which 1
is chosen. Of course there are other combinations as well. The clock chooses from all valid decompositions at random.
As I said... this might not win a usability award, but it sure is nice to look at.
The Challenge
Your task is to implement such a clock. Your program (or function) should print an ASCII representation of the current time (rounded down to the last multiple of 5 minutes) as described above to STDOUT or closest alternative. You may choose to read the time in any common format as input or obtain it with standard library functions. You must not assume that the current/given time is divisible by 5 minutes.
Your solution must choose randomly from all possible representations of the current time. That is each representation must be printed with non-zero probability.
Midnight and noon should be treated as 0:00
(as opposed to 12:00
).
You may optionally print a single trailing newline character.
You may use any four distinct printable ASCII characters (character codes 0x20 to 0xFE) in place of RGBW
. Please state your choice in your answer and use it consistently.
This is code golf, so the shortest answer (in bytes) wins.
(a) can we assume that the input follows the 12=0 rule? (b) does the output have to be in that orientation, or can we rotate it? – sirpercival – 2015-05-08T14:18:52.573
@sirpercival a) Yes, I think that counts as "any common format". b) It has to be the orientation given in the challenge. – Martin Ender – 2015-05-08T14:20:08.033
2This challenge spawned the unfortunate verb "fibclocking." – Alex A. – 2015-05-08T19:05:37.447
1What's the motivation for midnight/noon being 0 instead of 12? The first five numbers in the sequence add up to 12 exactly. – Brian J – 2015-05-08T19:20:54.763
@BrianJ I just wanted to choose one to make it consistent and happened to pick zero. It shouldn't really affect solutions too much anyway. I figured this choice would make things simpler because the minutes also have a 0..11 range. – Martin Ender – 2015-05-08T19:25:07.237