Posted to tcl by sevarat at Thu Oct 24 23:32:02 GMT 2024view raw
- #!/bin/tclsh
- array set alnum {
- 2 abc
- 3 def
- 4 ghi
- 5 jkl
- 6 mno
- 7 pqrs
- 8 tuv
- 9 wxyz
- }
- set numbers [split [lindex $argv 0] {}]
- set letters [lmap n $numbers {split [lindex [array get alnum $n] 1] ""}]
- proc letterMap {x y} {
- return [lmap a $x {lmap b $y {string cat $a $b}}]
- }
- proc phoneLetters {letterList} {
- if {[llength $letterList] < 2} {return [join $letterList]}
- return [phoneLetters [list [join [letterMap {*}[lrange $letterList 0 1]]] {*}[lrange $letterList 2 end]]]
- }
- puts [phoneLetters $letters]