Permutations (Original)
#####
#####
=================================================
  P E R M U T A T I O N S   ( O R I G I N A L )
=================================================

PERMUTATIONS(ORIGINAL) is the original program I
wrote in 1977/78 to generate and print all the
permutations of a string of 1 to 10 characters.

The old and new programs function identically. 
The new program has labels for branches and some
cleaner code.  The only difference to the user,
however, is in which memory registers are used:

Old Program (string length after stack):
  R0         // Total # of permutations printed
  R6         // Loop index initialized to N-1
  R7         // Stack pointer (initially -> R8)
  R8-R18     // Stack
* R19        // String length N
  R20-R29    // Character printer codes

New Program (string length before stack pointer):
  R0         // Total # of permutations printed
  R6         // Loop index initialized to N-1
* R7         // String length N
  R8         // Stack pointer (initially -> R9)
  R9-R19     // Stack
  R20-R29    // Character printer codes

Alex Measday
www.geonius.com/
    writing/articles/permutations.html

=================================================

Setting Up:
-----------

Initialize the total # of permutations printed
(R0) to zero:

CLR STO 00

Initialize the character loop index (R6) to N-1,
where N is the length of the string:

<length-1> STO 06

Specify the length N (R19) of the string:

<length> STO 19

Initialize the stack pointer (R7) to point to the
first entry (memory register 8) on the stack:

8 STO 07

Specify the N character indices (1-9 and 0) of
the initial string.  Enter an N-digit number,
where N is the length of the string and each
digit is the offset from memory register 20 of
the memory register (20-29) containing that
character's printer code.  If the string length
is less than 10, then index/digit 0 always
represents a blank character.  Store the
character indices number in the first entry on
the stack:

<1-10 digits> STO 08

For each index, 0-9, store the corresponding
character's printer code in memory registers
20-29.  If the string length is less than 10,
then index 0 always represents a blank character
and printer code 00 must be stored in memory
register 20.

CLR STO 20              // If string length < 10
<2-digit code> STO 21   // First distinct char
<2-digit code> STO 22   // Second distinct char
...

-------------------------------------------------

Running the Program:

R/S

The program will print out the permutations at
irregular intervals.

=================================================

Example:
--------

The "permutations_orig_01.wri" file has the
memory registers preset for generating and
printing all the permutations of "TRY IT", a
6-character string with 4 distinct characters
plus the blank.

The memory registers were initialized as follows:

CLR STO 00     // Permutation count = 0

5 STO 06       // Loop index = N - 1 = 5
6 STO 19       // String length N = 6

8 STO 07       // Stack pointer points to R8
123041 STO 08  // Indices for initial string:
               // 1 = T, 2 = R, 3 = Y, 4 = I

CLR STO 20     // ' ' printer code = 00
37 STO 21      // 'T' printer code = 37
35 STO 22      // 'R' printer code = 35
45 STO 23      // 'Y' printer code = 45
24 STO 24      // 'I' printer code = 24

Press R/S to run the program.  A 6-character
string always generates 720 permutations.  The
program does not prune duplicate permutations.
Because "TRY IT" has two Ts, there will be
720/2 = 360 duplicate permutations.

=================================================
