Welcome, guest | Sign In | My Account | Store | Cart

This simple TCL script can generate all possible variants of pnone number spells using numbers and letters

Tcl, 36 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
array set recode {
	1 {1}		2 {2 A B C}	3 {3 D E F}
	4 {4 G H I}	5 {5 J K L}	6 {6 M N O}
	7 {7 P Q R S}	8 {8 T U V}	9 {9 W X Y Z}
			0 {0}
}

set number {2 6 7 7 4 6 8}

set results {}
set temp {}
set is_first 1

foreach i $number {

	set temp_list [split $recode($i) " "]

	if {$is_first} {
		set is_first 0
		foreach j $temp_list {
			lappend results $j
		}
	} else {
		foreach item $results {
			foreach j $temp_list {
				lappend temp "$item$j"
			}
		}
		set results $temp
		set temp {}
	}
}

foreach item $results {
	puts $item
}
Created by Slava Lysunkin on Fri, 10 Aug 2007 (MIT)
Tcl recipes (162)
Slava Lysunkin's recipes (1)

Required Modules

  • (none specified)

Other Information and Tasks