JugglerA.Pas Program Listing




{ Start of file JugglerA.PAS ***********************************************}

{$A+,B-,D+,E+,F-,I+,L+,N+,O-,R-,S+,V+}  { Turbo Pascal Default options }

{$I+} {System i/o error checks}
{$N+} {Uses numeric coprocessor}
{$R+} {index Range checking}
{$V-} {no string length checking}
{$M 65520, 0, 655360} {16384, 0, 655360 are defaults; $M 65520 max stack}

program JugglerA; { Generate data for 50 dollar award. }

uses
  Crt,     { Turbo Pascal interface }
  MultiID; { Multiple-precision integer decimal algorithms unit}

const
  Name    = 'JugglerA - Generate data for 50 dollar award.';
  Version = 'Version 1.00, last revised: 92/02/09, 1000 hours';
  Author  = 'Copyright (c) 1981-1992 by author: Harry J. Smith,';
  Address = '19628 Via Monte Dr., Saratoga, CA 95070.  All rights reserved.';

{***************************************************************************}

{ Developed in TURBO Pascal 6.0 }

{ Juggler Sequence defined in Dr. Clifford A. Pickover's new book "Computers
  and the Imagination." This book has scores of educational and recreational
  experiments that can be done on a personal computer.

  At the end of Appendix C in this book you will find:

  ". . . An award of 50 dollars is offered by the publisher for a printout of
  the largest Juggler number computed by readers. The award will be given on
  or about September, 1993, and the sequence will also be published in the
  Juggernaut. Currently, the largest juggler number computed is a 45,391-digit
  giant for the starting number 30817. It was computed by Harry J. Smith using
  his own software package to perform multiple precision integer arithmetic.
  His package is written in the object-oriented programming language Turbo
  Pascal 5.5 by Borland International, Inc. His juggler package is a subset of
  his super-precision calculator software which computes transcendental
  functions to thousands of decimal places. Write him to obtain the software:
  Harry J. Smith, 19628 Via Monte Drive, Saratoga, CA 95070. . . ."

  Juggler Sequence also defined in Nov 1990 issue of Algorithm in PERSONAL
  PROGRAMS by Clifford A. Pickover.

  Pickover's definition of a juggler sequence:

  input positive integer, x
  repeat
    if x is even
      then x <-- [x^(1/2)]
      else x <-- [x^(3/2)]
  until x=1

  This program uses the results of my earlier program JuggerM.Pas which found
  the 45391 digit Juggler number 11705,...,77326 from a starting number of
  30817, and outputs to disk the entire sequence from this starting number.

  Format of output to disk:

  Juggler Sequence starting with x(0) = 30817 (JugglerA)
  Computed by: 
  Harry J. Smith, 19628 Via Monte Dr., Saratoga, CA 95070

  x(i) =
  x (digits in x)

  x(0) =
  30817 (5)

  x(1) =
  54,09853 (7)

  x(2) =
  1,25828,26157 (11)

  ...

  x(93) =
  1 (1)

  Length = 94


  Format of output to screen:

  n=30817 UUUDUDUUUDUUUDUUUUDUUDUUUUUUUUUUUUUUUUUDDUDDUDDDDUDUUUDDDUDDDDUUUUUU
  UDUUDDUDDDDUDDUUUDUUDDDDD L=94
}

var
  I     : Integer;    { Utility index }
  Ch    : Char;       { Character input by ReadKey }
  St    : String[128];{ String for starting number input from keyboard }
  FileSt: String[12]; { Output file name }
  Disk  : Text;       { Text file }
  Size  : LongInt;    { Size of max x in MultiID super digits }
  Up    : LongInt;    { Number of times x was odd except x zero }
  Down  : LongInt;    { Number of times x was even except last x }
  n     : ^MultiSI;   { Starting x, x zero }
  x     : ^MultiSI;   { Current value of x }
  x2    : ^MultiSI;   { Current x squared }
  x3    : ^MultiSI;   { Current x cubed }
  P     : ^MultiSI;   { Power used to input large n = b ^ P }
  One   : ^MultiSI;   { One in MultiSI format }
  L     : LongInt;    { Length of sequence }
  LSD   : LongInt;    { Least significant super digit }

{--------------------------------------}
procedure Init; { Initialize program }
begin
  TextBackground( Blue);
  TextColor( Yellow);
  ClrScr;
  WriteLn;
  WriteLn( Name);
  WriteLn( Version);
  WriteLn( Author);
  WriteLn( Address);
  WriteLn;
  FileSt:= 'JugglerA.Out';
  WriteLn( 'Will write file: ', FileSt,
           ' containing the entire sequence from this starting number 30817');
  WriteLn;
  MultiIDV.Init( 1);  { Init Multiple-precision integer decimal algorithms }
  MuMaxW:= 65;  MuLenD:= 21;  MuErrRep:= True;
  New( One, Init(1));  One^.SetTo1( 1);
  New( P, Init(1));
  Size:= (3 * (Memavail - 175)) div (20 * 4); { Use all but 100 bytes, heap }
  if (2 * Size > MuNMax) then  Size:= MuNMax div 2;  { MuNMax = 16379 }
  WriteLn( 'MemAvail=', MemAvail);
  WriteLn;
  WriteLn( 'Max_x limited to ', MuDMax * Size,
          ' decimal digits, (57323 digits is max)');
  New( n, Init( 2 * Size div 3));
  WriteLn;
  WriteLn( 'Input starting number, x zero (Try 10^255, ENTER => 30817):');
  ReadLn( St);
  While (Length( St) > 0) and (St[1] = ' ') do  Delete( St, 1, 1);
  if Length( St) = 0 then  St:= '30817';
  n^.Value( St, I);  { Convert String to n, returns I = # of character used }
  Delete( St, 1, I);
  While (Length( St) > 0) and (St[1] = ' ') do  Delete( St, 1, 1);
  if (Length( St) > 1) and (St[1] = '^') then begin
    Delete( St, 1, 1);
    While (Length( St) > 0) and (St[1] = ' ') do  Delete( St, 1, 1);
    P^.Value( St, I);
    n^.RPowMB( P^);
  end;
  if (n^.Comp( One^) < 0) then  n^.SetTo1(1);
  MuErr:= False;  MuAbort:= False;
  Write( 'Input = ');  n^.WritLn( Output);
  New( x,  Init( Size));
  New( x2, Init( 4 * Size div 3));
  New( x3, Init( 2 * Size));
  WriteLn;
  WriteLn( 'MemAvail=', MemAvail);
  WriteLn( 'Type any key to continue...  (or Esc to quit)');
  Ch:= ReadKey;
  if Ord( Ch) = 27 then  Halt(0);
end; { Init }

{--------------------------------------}
procedure Quit; { Terminate program }
begin
  Close( Disk);
  WriteLn('Type any key to exit...');
  Ch:= ReadKey;
  Halt(0);
end; { Quit }

{--------------------------------------}
begin { Main program, JugglerA }
  Init;
  Assign( Disk, FileSt);
  Rewrite( Disk);
  WriteLn;
  WriteLn( Disk);
  Write( Disk, 'Juggler Sequence starting with x(0) = ');
  n^.Writ( Disk);  WriteLn(Disk, ' (JugglerA)');
  WriteLn( Disk, 'Computed by:');
  WriteLn( Disk, 'Harry J. Smith, 19628 Via Monte Dr., Saratoga, CA 95070');
  WriteLn( Disk);
  WriteLn( Disk, 'x(i) =');
  WriteLn( Disk, 'x (digits in x)');
  WriteLn( Disk);
  if (n^.Comp( One^) = 0) then begin
    WriteLn('n=1 U L=1');
    WriteLn( Disk, '0 1 (1)');  WriteLn( Disk);  Quit;
  end;
  x^.SetTo1( 3);
  if (n^.Comp( x^) < 0) then begin
    WriteLn('n=2 D L=2');
    WriteLn( Disk, '0 2 (1)');  WriteLn( Disk, '1 1 (1)');
    WriteLn( Disk);  Quit;
  end;
  x^.SetTo( n^);  Up:= 0;  Down:= 0;
  Write( 'n=');  n^.Writ( Output);  Write(' ');
  MuLenD:= 0;
  WriteLn( Disk, 'x(0) =');
  n^.WritLn( Disk);  WriteLn( Disk);
  repeat
    LSD:= Round( x^.V^[0]);
    if (LSD mod 2) = 1 then begin
      Inc( Up);  Write('U');
      Tracn:= Down;  Trace:= Up;
      x2^.Sq( x^);  x3^.Mul( x^, x2^);  x^.SqRtRem( x3^, x3^);
    end
    else begin
      Inc( Down);  Write('D');
      Tracn:= Down;  Trace:= Up;
      x^.SqRtRem( x^, x3^);
    end;
    WriteLn( Disk, 'x(', Down + Up, ') =');
    MuTot:= 0;  x^.WritLn( Disk);  WriteLn( Disk);
  until (x^.Comp( One^) = 0) or MuErr or MuAbort;
  L:= Up + Down + 1;
  WriteLn(' L=', L);  WriteLn( Disk, 'Length = ', L);
  if MuErr then  WriteLn( Disk, 'Numbers got too big for memory')
  else  if MuAbort then  WriteLn( Disk, 'Run aborted by operator');
  Quit;
end. { JugglerA }

{ End of file JugglerA.PAS *************************************************}

Return to Juggler Numbers
Return to Harry's Home Page


This page accessed times since October 20, 2004.
Page created by: hjsmithh@sbcglobal.net
Changes last made on Saturday, 14-May-05 12:49:14 PDT

1