
JosephusCS is a program that solves the Josephus Permutation problem:

  Challenge given in REC Jan/Feb/Mar 1991 on page 24.
  "The Thousand Roman Slaves" suggested by Steve Wagler

  Original Problem: 1000 slaves in a circle, numbered 1 to 1000, are all to
  be shot except one lucky survivor. The order of shooting is 1, 3, 5, etc.,
  always alternating, and always immediately removing the fallen bodies. Once
  a body has fallen, it is no longer considered part of the circle for
  purposes of future counting and alternation. Example, n=6: Shoot 1,3,5,2,6;
  4 survives.

  The General Problem: There is an ordered set of n objects arranged in a
  circle with object i (1 <= i <= n) in position i. All n objects are
  selected and removed in a certain order and placed in a new circle with
  the new position number k beings the order of selection. Object f is
  selected first. After each selection, m minus 1 of the remaining objects
  following the one removed are skipped and the next object is then
  selected. We are interested in the nature of the permutation generated by
  this process, its fixed elements, and in particular the original position
  L of the last object selected. Note that m and f can be as low as 1 and
  can be larger than n.

  n = The number of objects in the circle
  f = index of first object to be selected [1, n]
  m = difference in index of items selected, m = 2 => every other

  "Max Pointed Plotted" can be set to a value from 1 to 1000000. The
  nominal starting value is 200 and it can only be changed on the Startup
  form. Large values of this parameter can cause the Plot form to take a
  very long time before the plot appears and the program may have to be
  terminated manually by clicking the X in the upper right hand corner of
  the Plot form or the Run form. If n is greater than Max Points Plotted,
  only the first Max Points Plotted points will be plotted.

  See Knuth, The Art of Computer Programming, Vol. 1, Pages 158-159, 181,
  516, 521 and Vol. 3, Pages 18-19, 579.

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

            +------------Function Keys on Run form------------+
            |   F1  => Display Help form                      |
            |   F2  => Quit and go back to the Startup form   |
            |   F5  => Get Status of calculation              |
            |   F6  => Display Configuration form             |
            |   F7  => Outputs a simple permutation report    |
            |   F8  => Outputs a detailed permutation report  |
            |   F9  => Toggle Logging to Log file on/off      |
            |   F11 => Clear output text box                  |
            |   F12 => Brings up the Plot form and plots      |
            |   Ctrl+F9 => Clear Log File                     |
            |   ESC => Interrupt/Abort a long calculation     |
            +-------------------------------------------------+
--------------------------------------------------------------------------------

  Example output:
--------------------
  n = 1000,  f = 1,  m = 2:  Object 976 was selected last!
  There is 1 fixed element:  1.
--------------------
  n = 1000,  f = 32767 => 767,  m = 32767:  Object 481 was selected last!
  There are 5 fixed elements:  41, 178, 619, 710, 718.
--------------------
  n = 1000,  f = 1,  m = 1:  Object 1000 was selected last!
  There are 1000 fixed elements:  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... .
--------------------
  Execution order, when object i was selected:
  5 4 6 1 3 8 7 2 

  Order of execution, object # selected on k'th selection:
  4 8 5 2 1 3 7 6 

  The resulting permutation expressed in cyclic notation:
  (1, 5, 3, 6, 8, 2, 4)(7)

  The fixed element in this Josephus permutation is:
  7 

  n = 8,  f = 4,  m = 4:  Object 6 was selected last!
  There is 1 fixed element:  7.
--------------------

-Harry
