Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Truth-table/Tcl/truth-table.tcl
Normal file
17
Task/Truth-table/Tcl/truth-table.tcl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
package require Tcl 8.5
|
||||
|
||||
puts -nonewline "Enter a boolean expression: "
|
||||
flush stdout
|
||||
set exp [gets stdin]
|
||||
|
||||
# Generate the nested loops as the body of a lambda term.
|
||||
set vars [lsort -unique [regexp -inline -all {\$\w+} $exp]]
|
||||
set cmd [list format [string repeat "%s\t" [llength $vars]]%s]
|
||||
append cmd " {*}\[[list subst $vars]\] \[[list expr $exp]\]"
|
||||
set cmd "puts \[$cmd\]"
|
||||
foreach v [lreverse $vars] {
|
||||
set cmd [list foreach [string range $v 1 end] {0 1} $cmd]
|
||||
}
|
||||
|
||||
puts [join $vars \t]\tResult
|
||||
apply [list {} $cmd]
|
||||
Loading…
Add table
Add a link
Reference in a new issue