Non-continuous subsequences: Difference between revisions

m
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Minor tidy)
(One intermediate revision by one other user not shown)
Line 2,835:
{{libheader|Wren-fmt}}
Needed a bit of doctoring to do the character example as Wren only has strings.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var ncs = Fn.new { |a|
Line 2,872:
ncs.call(ca)</syntaxhighlight>
 
{{out}}
<pre>
1 3
1 4
2 4
1 2 4
1 3 4
 
a c
a d
a e
b d
b e
c e
a b d
a b e
a c d
a c e
a d e
b c e
b d e
a b c e
a b d e
a c d e
</pre>
 
=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">proc NCS(A, Size, Char);
int A, Size, Char;
int C, M;
 
proc Generate(M, K, C); \recursive
int M, K, C;
int I, J;
[if K = M then
[if C(M-1) # C(0)+M-1 then
[for I:= 0 to M-1 do
[if Char then ChOut(0, A(C(I)))
else IntOut(0, A(C(I)));
ChOut(0, ^ );
];
CrLf(0);
];
]
else
[for J:= 0 to Size-1 do
[if K = 0 or J > C(K-1) then
[C(K):= J;
Generate(M, K+1, C);
];
];
];
];
 
[C:= Reserve(Size*4);
for M:= 2 to Size-1 do Generate(M, 0, C);
];
 
int A, CA;
[A:= [1, 2, 3, 4];
NCS(A, 4, false);
CrLf(0);
CA:= [^a, ^b, ^c, ^d, ^e];
NCS(CA, 5, true);
]</syntaxhighlight>
{{out}}
<pre>
9,476

edits