Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Power-set/Lambdatalk/power-set.lambdatalk
Normal file
29
Task/Power-set/Lambdatalk/power-set.lambdatalk
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{def powerset
|
||||
|
||||
{def powerset.r
|
||||
{lambda {:ary :ps :i}
|
||||
{if {= :i {A.length :ary}}
|
||||
then :ps
|
||||
else {powerset.r :ary
|
||||
{powerset.rr :ary :ps {A.length :ps} :i 0}
|
||||
{+ :i 1}} }}}
|
||||
|
||||
{def powerset.rr
|
||||
{lambda {:ary :ps :len :i :j}
|
||||
{if {= :j :len}
|
||||
then :ps
|
||||
else {powerset.rr :ary
|
||||
{A.addlast! {A.concat {A.get :j :ps}
|
||||
{A.new {A.get :i :ary}}}
|
||||
:ps}
|
||||
:len
|
||||
:i
|
||||
{+ :j 1}} }}}
|
||||
|
||||
{lambda {:ary}
|
||||
{A.new {powerset.r :ary {A.new {A.new}} 0}}}}
|
||||
|
||||
-> powerset
|
||||
|
||||
{powerset {A.new 1 2 3 4}}
|
||||
-> [[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3],[4],[1,4],[2,4],[1,2,4],[3,4],[1,3,4],[2,3,4],[1,2,3,4]]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue