Version 13 of Code Golf Saving Time

Updated 2008-10-21 22:37:39 by dkf

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

set O {1 7 16 25 34 43 46 40 31 22 13 4}
set C {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 $O [expr {($h%12)}]]
	set m [lindex $O [expr {($m/5)}]]
	if {$m==$h} { 
	    set c [lreplace $C $m $m x] 
	} else {
	    set c [lreplace $C $h $h h]
	    set c [lreplace $c $m $m m]
	}
	foreach {s o b} $c { puts -nonewline [string repeat " " $s]$o$b }
    }
}

Example output:

% tclsh w.tcl 21:35
	o
    o       o

 o	     o

h	       o

 o	     o

    m       o
	o

DKF: This can be shortened to:

scan [gets stdin] %d:%d h m
set p [list {*}[split oAoBoCoDoEoFoGoHoIoJoKon\n {}] 2 {  } 5 {     }]
lset p [set h [expr $h%12*2]] h
lset p [set m [expr $m/5*2]] [expr $h-$m?"m":"x"]
puts [string map L\ $p { 25Ln22K25Ann J255 BnnI555Cnn H255 Dnn22G25En 25F}]

(Note that the actual problem calls for the time to be suppled on stdin, not the command line.)