home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math
- Path: sparky!uunet!decwrl!csus.edu!netcomsv!sjsumcs!kellum
- From: kellum@sjsumcs.sjsu.edu (Ken Kellum)
- Subject: Re: Factorial program...
- Message-ID: <1992Jul22.222658.3613@sjsumcs.sjsu.edu>
- Organization: San Jose State University - Math/CS Dept.
- References: <1992Jul20.160312.10723@infonode.ingr.com>
- Date: Wed, 22 Jul 1992 22:26:58 GMT
- Lines: 77
-
- In article <1992Jul20.160312.10723@infonode.ingr.com> "Vilva Natarajan <vilva@madras.b23b.ingr.COM>" writes:
- >Hi,
- >
- > I am looking for source code that prints out all the factorial
- > combinations of a set of numbers.
- >
- >
- > Eg.
- >
- > factorial combo of 1 2 3 4 would be, (there are 24 of them)
- >
- > 1 2 3 4
- > 1 2 4 3
- > 1 3 2 4
- > 1 3 4 2
- > 1 4 2 3
- > 1 4 3 2
- >
- > 2 1 3 4
- > 2 1 4 3
- > 2 3 1 4
- > 2 3 4 1
- > 2 4 1 3
- > 2 4 3 1
- >
- > 3 1 2 4
- > 3 1 4 2
- > 3 2 1 4
- > 3 2 4 1
- > 3 4 1 2
- > 3 4 2 1
- >
- > 4 1 2 3
- > 4 1 3 2
- > 4 2 1 3
- > 4 2 3 1
- > 4 3 1 2
- > 4 3 2 1
- >
- >
- > Any help would be appreciated. Thanks>
- >
- >vn
-
- The following (pseudo) Pascal procedure prints all the permutations
- of a one dimensional array. It can be modified to do what you want.
-
- Procedure Permute (var A : array [1..n] of whatever)
-
- Procedure Inner (i : integer);
- { prints the permutations of a[i] .. a[n] }
- var j : integer
- temp : whatever;
-
- begin
- if i > n then
- writeln(a)
- else
- for j := i to n do begin
- temp := a[i]; a[i] := a[j]; a[j] := temp;
- Inner (i + 1);
- temp := a[i]; a[i] := a[j]; a[j] := temp;
- end;
- end; { Inner }
-
- begin {permute}
- Inner(1);
- end;
-
- It's an amusing exercise to construct an inductive proof that this
- procedure works.
-
- Kenneth Kellum
- ___________________________________________
-
- Those who give up claims of uniqueness only become more unbearable
- when they claim to be representative.
-