Draw a BCD Binary clock
Ruby, 107 103 99 94 90 characters
$><<[$/,(gets||Time.now.to_s[11,8]).tr(z=" .':","").bytes.map{|a|$><<z[a/4-12];z[a%4]}]*""
Note that the input shouldn't contain a linebreak, so to test the solution use something like echo -n "01:08:01" | ruby1.9 bcd.rb
.
To test the default behavior, run it with ruby1.9 bcd.rb
and enter ^D
(i.e. a literal EOF).
Golfscript (+ruby/date) - 46 chars
"#{`date`}"10>+9<" .':":S-.{4/12-S=}%n@{4%S=}%
You can replace `date`
with Time.now
if necessary (+2 chars).
Windows PowerShell, 81
Since I did not create an implementation when writing the task I feel myself eligible to golf it from the start, too :-)
-join" .':
"[(($d="$(date)$args"[-8..-1]-ne58)|%{($_-band12)/4})+,4+($d|%{$_%4})]
History:
- 2011-02-26 23:50 (119) First attempt.
- 2011-02-26 23:55 (108) Inlining fun.
- 2011-02-27 00:03 (102) Optimized selecting the first line.
[Math]::Floor
is waaaayy too long. I hate that. - 2011-02-27 02:22 (101) I don't need
:
for the first line. - 2011-02-27 02:53 (95) Optimized getting input or current time.
- 2011-03-04 20:36 (88) Only a single join remains. Indexing every character needed (including the line break) from a single string.
- 2011-03-04 20:39 (83) Using
58
instead of:
which auto-casts to integer as well – no more need to enclose$_
in quotes :-) - 2011-03-04 20:42 (81) The parentheses after the
-join
are no longer necessary.