home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!zaphod.mps.ohio-state.edu!malgudi.oar.net!uoft02.utoledo.edu!desire.wright.edu!jmatthews
- Newsgroups: sci.math
- Subject: Re: Factorial program...
- Message-ID: <1992Jul24.162820.3080@desire.wright.edu>
- From: jmatthews@desire.wright.edu
- Date: 24 Jul 92 16:28:20 EST
- References: <1992Jul20.160312.10723@infonode.ingr.com> <1992Jul22.222658.3613@sjsumcs.sjsu.edu>
- Organization: Wright State University
- Lines: 45
-
- In article <1992Jul22.222658.3613@sjsumcs.sjsu.edu>, kellum@sjsumcs.sjsu.edu (Ken Kellum) writes:
- > 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.
- >> [exampple deleted]
-
- > 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;
-
- The first time I saw this algorith was in Wirth's _Algorithms_+_Data_
- _Structures_=_Programs_. The question was posed as an exercise (3.2)
- in a chapter on recursion. The _answer_ appeared in the following
- chapter as the (otherwise meaningless) sample output of a cross-
- reference generating program.
-
- An Easter egg in a textbook:-)
-
- o----------------------------------------------------------------------------o
- | John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
- | "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
- o----------------------------------------------------------------------------o
-