Correct Tcl solution. Very slow.