pascalabcnet/TestSuite/CompilationSamples/Permutations.pas

25 lines
409 B
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Все перестановки
uses Arrays;
const n = 4;
var a: array of integer;
procedure Perm(m: integer);
begin
if m=1 then
a.Writeln;
for var i:=0 to m-1 do
begin
Swap(a[i],a[m-1]); // ставим каждый на место последнего
Perm(m-1);
Swap(a[i],a[m-1]);
end;
end;
begin
SetLength(a,n);
for var i:=0 to n-1 do
a[i] := i+1;
Perm(n);
end.