30 lines
667 B
Text
30 lines
667 B
Text
$ include "seed7_05.s7i";
|
|
|
|
const func array bitset: ncsub (in bitset: seq, in integer: s) is func
|
|
result
|
|
var array bitset: subseq is 0 times {};
|
|
local
|
|
var bitset: x is {};
|
|
var bitset: xs is {};
|
|
var bitset: ys is {};
|
|
begin
|
|
if seq <> {} then
|
|
x := {min(seq)};
|
|
xs := seq - x;
|
|
for ys range ncsub(xs, s + 1 - s rem 2) do
|
|
subseq &:= x | ys;
|
|
end for;
|
|
subseq &:= ncsub(xs, s + s rem 2);
|
|
elsif s >= 3 then
|
|
subseq &:= {};
|
|
end if;
|
|
end func;
|
|
|
|
const proc: main is func
|
|
local
|
|
var bitset: seq is {};
|
|
begin
|
|
for seq range ncsub({1, 2, 3, 4}, 0) do
|
|
writeln(seq);
|
|
end for;
|
|
end func;
|