Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Power-set/Tcl/power-set-1.tcl
Normal file
8
Task/Power-set/Tcl/power-set-1.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
proc subsets {l} {
|
||||
set res [list [list]]
|
||||
foreach e $l {
|
||||
foreach subset $res {lappend res [lappend subset $e]}
|
||||
}
|
||||
return $res
|
||||
}
|
||||
puts [subsets {a b c d}]
|
||||
12
Task/Power-set/Tcl/power-set-2.tcl
Normal file
12
Task/Power-set/Tcl/power-set-2.tcl
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
proc powersetb set {
|
||||
set res {}
|
||||
for {set i 0} {$i < 2**[llength $set]} {incr i} {
|
||||
set pos -1
|
||||
set pset {}
|
||||
foreach el $set {
|
||||
if {$i & 1<<[incr pos]} {lappend pset $el}
|
||||
}
|
||||
lappend res $pset
|
||||
}
|
||||
return $res
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue