Build an ASCII Fibonacci Clock
Python 2, 194 182 bytes
from random import*
h=m=H,M=input()
while[h,m]!=[H,M/5]:
h=m=0;s=[]
for n in 1,1,2,3,5:c=randint(0,3);h+=c%2*n;m+=c/2*n;s=zip(*(["WRGB"[c]*n]*n+s)[::-1])
for L in s:print"".join(L)
The algorithm is just rejection sampling, so it keeps generating clocks until it gets one that's right. The clock is built by starting with nothing, then doing "add a square above and rotate clockwise" 5 times.
Takes two comma-separated integers via STDIN.
>>> ================================ RESTART ================================
>>>
7,17
BBBWWWWW
BBRWWWWW
RRRWWWWW
RRRWWWWW
RRRWWWWW
>>> ================================ RESTART ================================
>>>
7,17
GGBRRRRR
GGRRRRRR
WWWRRRRR
WWWRRRRR
WWWRRRRR
CJam, 61 bytes
l~5/]:A{;L[TT][XXYZ5]{4mr_2bW%Mf*@.+\Ps=M*aM*@+W%z\}fMA=!}gN*
Takes two space-separated integers via STDIN, and uses 3.14
instead of WRGB
respectively. Try it online.
Here is the "sane" RGBW
version for a few extra bytes:
l~5/]:A{;L[TT][XXYZ5]{4mr_2bW%Mf*@.+\"WRGB"=M*aM*@+W%z\}fMA=!}gN*
Explanation
The algorithm is the same as my Python answer — rejection sampling by generating clocks until we get one that's correct.
l~5/]:A Read input and make array [<hours> <minutes>/5]
{...}g Do...
; Pop the only element on the stack
L Push empty array, which will become our clock
[TT] Push [0 0] for [h m], to keep track of our sample
[XXYZ5]{...}fI For I in [1 1 2 3 5]...
4mr Push random number from [0 1 2 3]
_2bW% Copy and get reversed base 2 rep for one of [0] [1] [0 1] [1 1]
If* Multiply bit(s) by I
@.+ Add element-wise to [h m] array
\Ps= Index the random number into stringified pi for one of "3.14"
I*aI* Make into I by I square
@+W%z\ Add above clock and rotate clockwise
A=! ... while the resulting clock is incorrect
N* Riffle clock with newlines
Python 2, 421 bytes
Ugh, I'm sure this can be golfed more.
from itertools import*
from random import*
f,r=[1,1,2,3,5],range
c={_:[x for x in chain(*[combinations(f,i)for i in r(6)])if sum(x)==_]for _ in r(13)}
k=[[2,1,4],[2,0,4]]+[[3,4]]*3
def b(h,m):
o=['W']*5;m/=5;h,m=choice(c[h]),choice(c[m])
l=dict(zip(zip('WWR',[m,h,m]),'GRB'))
for x in h,m:
d={1:[0,1],2:[2],3:[3],5:[4]}
for _ in x:j=d[_].pop();o[j]=l[o[j],x]
print'\n'.join([''.join(o[i]*f[i]for i in _)for _ in k])
Test case:
>>> b(7,20)
WWBRRRRR
WWRRRRRR
GGGRRRRR
GGGRRRRR
GGGRRRRR
>>> b(7,20)
RRBWWWWW
RRRWWWWW
BBBWWWWW
BBBWWWWW
BBBWWWWW