September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
43
Task/Permutations/Modula-3/permutations-4.mod3
Normal file
43
Task/Permutations/Modula-3/permutations-4.mod3
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
MODULE GPermutations EXPORTS Main;
|
||||
|
||||
IMPORT IO, IntSeq, IntSetTree, IntSeqSeq, IntPermutations;
|
||||
|
||||
CONST
|
||||
|
||||
n = 7;
|
||||
|
||||
VAR
|
||||
|
||||
chosen: IntSeq.T;
|
||||
remaining: IntSetTree.T;
|
||||
result: IntSeqSeq.T;
|
||||
|
||||
PROCEDURE Factorial(n: CARDINAL): CARDINAL =
|
||||
VAR result := 1;
|
||||
BEGIN
|
||||
FOR i := 2 TO n DO
|
||||
result := result * i;
|
||||
END;
|
||||
RETURN result;
|
||||
END Factorial;
|
||||
|
||||
BEGIN
|
||||
|
||||
(* initial setup *)
|
||||
chosen := NEW(IntSeq.T).init(n);
|
||||
remaining := NEW(IntSetTree.T).init();
|
||||
result := NEW(IntSeqSeq.T).init(Factorial(n));
|
||||
FOR i := 1 TO n DO EVAL remaining.insert(i); END;
|
||||
|
||||
IntPermutations.GeneratePermutations(chosen, remaining, result);
|
||||
|
||||
IO.Put("Printing "); IO.PutInt(result.size());
|
||||
IO.Put(" permutations of "); IO.PutInt(n); IO.Put(" elements \n");
|
||||
FOR i := 0 TO result.size() - 1 DO
|
||||
FOR j := 0 TO result.get(i).size() - 1 DO
|
||||
IO.PutInt(result.get(i).get(j)); IO.PutChar(' ');
|
||||
END;
|
||||
IO.PutChar('\n');
|
||||
END;
|
||||
|
||||
END GPermutations.
|
||||
Loading…
Add table
Add a link
Reference in a new issue