A long while back Code Golf posted up the Saving Time challenge in which you were required to transform input representing a digital clock into an ASCII analog representation in as few key strokes as possible. Here were my solutions in both PHP and Python:

PHP: 234 characters

``````<?fscanf(STDIN,'%d:%d',\$h,\$m);\$s=array_combine(str_split('0b1a29384756'),array_fill(0,12,'o'));\$s[\$h=dechex(\$h>11?\$h-12:\$h)]='h';\$s[\$m=dechex(\$m>59?0:\$m/5)]=\$h==\$m?'x':'m';vprintf("%9s
%5s%8s

%s%14s

%s%16s

%s%14s

%5s%8s
%9s",\$s)
``````

Not exactly the most beautiful code. If there’s a shorter way of converting from decimal to hex I’d probably cut 10 more characters or so.

Python: 232 characters

``````h,m=[int(x) for x in raw_input().split(':')];s=dict(zip('0b1a29384756','o'*12))
h="%x"%(h,h-12)[h>11]
m="%x"%(m/5,0)[m>59]
s[h]='h';s[m]='mx'[h==m];print "%9s\n%5s%8s\n\n %s%14s\n\n%s%16s\n\n %s%14s\n\n%5s%8s\n%9s"%tuple(s.values())
``````

The Python code is in no way exemplary as it’s mostly a translation of the PHP code. What I can’t fathom is how someone could possibly solve this problem in 134 characters in PHP, the way eyepopslikeamosquito did. That is insane my friend. Probably ran a Perl solution through PHP’s shell command functions.