Version 1 of Code Golf Saving Time

Updated 2008-10-21 13:14:52 by jdc

jdc 21-oct-2008 A Tcl solution to http://codegolf.com/saving-time

set offsets {1 7 16 25 34 43 46 40 31 22 13 4}
set clock   {8 o \n 4 o {} 7 o \n 0 {} \n 1 o {} 13 o \n 0 {} \n 0 o {} 15 o \n 0 {} \n 1 o {} 13 o \n 0 {} \n 4 o {} 7 o \n 8 o \n}
foreach t $argv {
    if {[regexp {0?(\d+):0?(\d+)} $t -> h m]} {
	set h [lindex $offsets [expr {($h%12)}]]
	set m [lindex $offsets [expr {($m/5)}]]
	if {$m!=$h} {
	    set c [lreplace $clock $h $h h]
	    set c [lreplace $c $m $m m]
	} else {
	    set c [lreplace $clock $m $m x]
	}
	foreach {s o b} $c {
	    puts -nonewline [string repeat " " $s]$o$b
	}
	puts ""
    }
}

Example output:

% tclsh w.tcl 21:35
        o
    o       o

 o             o

h               o

 o             o

    m       o
        o

enter categories here