Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Power-set/ALGOL-68/power-set.alg
Normal file
27
Task/Power-set/ALGOL-68/power-set.alg
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
MODE MEMBER = INT;
|
||||
|
||||
PROC power set = ([]MEMBER s)[][]MEMBER:(
|
||||
[2**UPB s]FLEX[1:0]MEMBER r;
|
||||
INT upb r := 0;
|
||||
r[upb r +:= 1] := []MEMBER(());
|
||||
FOR i TO UPB s DO
|
||||
MEMBER e = s[i];
|
||||
FOR j TO upb r DO
|
||||
[UPB r[j] + 1]MEMBER x;
|
||||
x[:UPB x-1] := r[j];
|
||||
x[UPB x] := e; # append to the end of x #
|
||||
r[upb r +:= 1] := x # append to end of r #
|
||||
OD
|
||||
OD;
|
||||
r[upb r] := s;
|
||||
r
|
||||
);
|
||||
# Example: #
|
||||
test:(
|
||||
[][]MEMBER set = power set((1, 2, 4));
|
||||
FOR member TO UPB set DO
|
||||
INT upb = UPB set[member];
|
||||
FORMAT repr set = $"("f( upb=0 | $$ | $n(upb-1)(d", ")d$ )");"$;
|
||||
printf(($"set["d"] = "$,member, repr set, set[member],$l$))
|
||||
OD
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue