Posted to tcl by kbk at Sat Nov 28 17:58:15 GMT 2009view raw
- variable ascA ; scan A %c ascA
- proc spreadcol {n} {
- variable ascA
- set k [expr {int(log(25 * $n + 1)/log(26))}]
- set m [expr {$n - ((26 ** $k) - 1) / 25}]
- while {$k > 0} {
- append r [format %c [expr {$ascA + ($m % 26)}]]
- set m [expr {$m / 26}]
- incr k -1
- }
- return [string reverse $r]
- }
- foreach x [list 1 26 26+1 26*26+26 26*26+26+1 26*26*26+26*26+26 26*26*26+26*26+26+1] {
- puts [list $x [expr $x] [spreadcol [expr $x]]]
- }
Comments
Posted by kbk at Sat Nov 28 18:10:16 GMT 2009 [text] [code]
variable ascA ; scan A %c ascA proc spreadcol {n} { variable ascA set k [expr {int(log(25 * $n + 1)/log(26))}] set m [expr {$n - ((26 ** $k) - 1) / 25}] while {$k > 0} { append r [format %c [expr {$ascA + ($m % 26)}]] set m [expr {$m / 26}] incr k -1 } return [string reverse $r] } proc parsespreadcol {s} { variable ascA set r 0 foreach c [split $s {}] { scan $c %c d set r [expr {26 * $r + $d - $ascA}] } incr r [expr {(26 ** [string length $s] - 1) / 25}] return $r } foreach x [list 1 26 26+1 26*26+26 26*26+26+1 26*26*26+26*26+26 26*26*26+26*26+26+1] { puts [list $x [expr $x] [set s [spreadcol [expr $x]]] [parsespreadcol $s]] }