Output the current time in ascii art
Perl, 592 579 540 522 510 bytes
Under a sector!
($L,$C,$b)=unpack"W/aW/aB*",q!12346677889999 _|/\)(
'<,>.` PP¨
¨@T @ôäð˜SÀ§€fÌU`à¨Àäð'€GÖf`3 X½`fÍ5 s Î|½`gËÖ— $¡))õ™˜À8Sô BÁªx~O àÔýåËþÏÃÆ~O‡ŸY¬Àf s
½`À*õŸ/X8|½`p>^€<¯åkgúºÖ·Óʸ°ªÀj® kª¸•p¸å\× ô!;@c=map{$i<<=$_-$P if$_>$P;$P=$_;sprintf"%${l}b",$i++}$L=~/./g;while($b){$b=~s/^$c[$_]// and$g.=($C=~/./sg)[$_]for 0..$#c}$_=pop;s/-/:/;y/apm-/;</d;for$a(0..5){map{$o.=substr((split$/,$g)[$a],($x=-48+ord)*12,('6356766766099'=~/./g)[$x]+3)}/./g;$o.=$/}print$o
This program expects the time in the 2nd format ("12-34-am") as a commandline argument.
Commented:
($L,$C,$b) = unpack "W/aW/aB*", # extract code lengths, chars, and bitstream
q!12346677889999 _|/\)(
'<,>.` PP¨
¨@T @ôäð˜SÀ§€fÌU`à¨Àäð'€GÖf`3 X½`fÍ5 s Î|½`gËÖ— $¡))õ™˜À8Sô BÁªx~O àÔýåËþÏÃÆ~O‡ŸY¬Àf s
½`À*õŸ/X8|½`p>^€<¯åkgúºÖ·Óʸ°ªÀj® kª¸•p¸å\× ô!;
@c = map { # reconstruct huffman prefix codes
$i <<= $_-$P if $_ > $P; # increase code size
$P = $_; # keep track of previous code
sprintf "%${l}b", $i++ # append code as bitstring
}
$L=~/./g; # canonical huffman prefix lengths
while ( $b ) { # decompress font
$b =~ s/^$c[$_]// # match and strip prefix code
and $g .= ($C=~/./sg)[$_] # append char for prefix code
for 0..$#c # iterate prefix codes in order
} # luckily we can omit checking trailing bytes
$_ = pop; # get cmdline arg "12-34-am"
s/-/:/; # ord(':')-ord('0')=10
y/apm-/;</d; # 'a'-> chr(11), 'p' -> chr(12), strip -,m
for $a (0..5) { # iterate 6 output lines
map { # iterate each char in input
$o .= substr(
( split $/, $g )[$a], # grab line $a
( $x=-48+ord ) * 12, # $x=glyph index, 12=glyph width
('6356766766099'=~/./g)[$x]+3 # glyph display width
)
} /./g;
$o .= $/ # append newline
}
print $o # output
Note that due to character encoding issues, when you paste the above code in a file, the output may be somewhat malformed. So here's the golfed version, base-64 encoded. Copy it, and paste it into base64 -d > 510.pl
:
KCRMLCRDLCRiKT11bnBhY2siVy9hVy9hQioiLHEhDjEyMzQ2Njc3ODg5OTk5DiBffC9cKSgKJzws
Pi5gFQBQAVACqAIgCqgBQBVUAqAFQAH05PAOmANTwBqngGbMBlVgHOAaqMDk8AcngEfWZmAzAA9Y
Ar1gZs0DNQBzoAHOBny9YGfL1g+XoAUkoSkp9ZmYDMAHOANT9A1Cwap4Bn5PABzgH9T9AeV/GBAB
y/7Pw8Z+Tx+Hn1mswGYAc6AKvWAMwCr1gZ8vWAc4Bny9YA5wPl6APK/lrWtn+rrWt9PKuAawBqrA
aq4AawGquAeVcA64AeVcAdcAAAABrfQhO0BjPW1hcHskaTw8PSRfLSRQIGlmJF8+JFA7JFA9JF87
c3ByaW50ZiIlJHtsfWIiLCRpKyt9JEw9fi8uL2c7d2hpbGUoJGIpeyRiPX5zL14kY1skX10vLyBh
bmQkZy49KCRDPX4vLi9zZylbJF9dZm9yIDAuLiQjY30kXz1wb3A7cy8tLzovO3kvYXBtLS87PC9k
O2ZvciRhKDAuLjUpe21hcHskby49c3Vic3RyKChzcGxpdCQvLCRnKVskYV0sKCR4PS00OCtvcmQp
KjEyLCgnNjM1Njc2Njc2NjA5OSc9fi8uL2cpWyR4XSszKX0vLi9nOyRvLj0kL31wcmludCRv
Here's the font I'm using. I've spaced the glyphs 12 characters apart (the size of the am/pm) for easy indexing.
___ __ ___ ____ _ _ _____ __ ______ ___ ___
/ _ \ /_ | |__ \ |___ \ | || | | ____| / / |____ | / _ \ / _ \ _
| | | | | | ) | __) | | || |_ | |__ / /_ / / | (_) | | (_) | (_) __ _ _ __ _ __ _ __
| | | | | | / / |__ < |__ _| |___ \ | '_ \ / / > _ < \__, | _ / _` | ' \ | '_ \ ' \
| |_| | | | / /_ ___) | | | ___) | | (_) | / / | (_) | / / (_) \__,_|_|_|_|| .__/_|_|_|
\___/ |_| |____| |____/ |_| |____/ \___/ /_/ \___/ /_/ |_|
This font is 592 bytes.
The previous approach used a few variations on RLE compression to reduce this to 353 bytes, at the cost of 78 bytes decompression code.
The Huffman coding compresses the font to 221 bytes at the cost of 154 bytes for the decompression algorithm.
C++, 938 Bytes
Revised version with some basic compression of input data: Test here
#include <stdio.h>
#include <time.h>
int main(){char e[]="!1`2!3`1!2`1!4`2!4`!1`!4`4!4`1!3`5!4`2!4`2!35^!`!]!1^`!}!}`1!]!1}`2!]!1}!}1!}!2}!`3}!2^!^!2}`3!1}!2^!`!]!2^!`!]!31`!}!}!}!}!1}!}!3*!}!2`1*!}!}!}1!}`!1}!}`1!3^!^`!6^!^!2}!)`*!}!}!)`*!}!2`1!`!`!`1!3`!`1!`!`1!4)`*}!}!}!}!1}!}!2^!^!2}`1!=!1}`1!2`}!}`2!]!1}!(`!]!4^!^!4?!`!=!2]`1-!}!1^!`a!}!(!1]!1}!(`!]!(!1]!4`!}!}`}!}!1}!}!1^!^`!2`2*!}!3}!}!3`2*!}!}!)`*!}!2^!^!4}!)`*!}!3^!^!2]`1-`}`}`}`}!}!/`1^`}`}`}!2)`*!]`2^!2}`}!}`3}!}`3^!4}`}!2}`3^!2]`2^!2^`^!6]`2^!3^`^!16}`}!14",l[]="8578988998>?3",f[666],*q=f,*p=e,c,r;time_t z;time(&z);tm*u=localtime(&z);while(*p){if(*p>47&&*p<58){r=*p++-48;if(*p>47&&*p<58)r=r*10+*p++-48;while(r--)*q++=c;}else{*q++=c=*p++==94?48:p[-1];}}c=u->tm_hour;sprintf(e,"%02d<%02d%c",c%12,u->tm_min,':'+c/12);for(int s,n,o,r=0;r<6;r++){for(q=e;*q;q++){o=r*111;for(n=0; n<*q-48;n++)o+=l[n]-48;s=l[n]-48;for(n=o;n<o+s;n++)putchar(f[n]-1);}putchar('\n');}return 0;}
Bash + GNU utilities + figlet, 134
Not sure if figlet is allowed or not, but it does seem to provide the right fonts - big
for the digits and small
for the :
and {a,p}m
:
f=figlet\ -f
b()(date +%$1|sed 's/./& /g'|$f big)
b -I|paste - <(echo " ";$f small ": ") <(b M) <(echo;date +%P|$f small)|tr \\t \
The rest is just getting the right info from date
and shuffling the formating around so it looks right:
___ _____ ___
/ _ \ _ | ____| / _ \
| (_) | (_) | |__ | | | | __ _ _ __
> _ < _ |___ \ | | | | / _` | ' \
| (_) | (_) ___) | | |_| | \__,_|_|_|_|
\___/ |____/ \___/
Figlet may be installed on Ubuntu with sudo apt-get install figlet
.