tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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