{ Start of file Juggler0.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 Juggler0; { Repeat Pickover's origional results on x <= 200 } { Juggler Sequence defined in Nov 1990 issue of Algorithm in PERSONAL PROGRAMS by Clifford A. Pickover. } uses Crt, { Turbo Pascal 5.5 interface } MultiID; { Multiple-precision integer decimal algorithms unit } const Name = 'Juggler0 - Investigates all Juggler Sequences with starting x <= 200'; Version = 'Version 1.00, last revised: 90/12/27, 0700 hours'; Author = 'Copyright (c) 1981-1990 by author: Harry J. Smith,'; Address = '19628 Via Monte Dr., Saratoga, CA 95070. All rights reserved.'; {***************************************************************************} { Developed in TURBO Pascal 5.5 } { 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 by Harry Smith outputs each sequence starting from 1 through 200. It also outputs the sequence length, and the number of digits in max x for each sequence. Format of output to disk: 9 -> 27 -> 140 -> 11 -> 36 -> 6 -> 2 -> 1; L=8, DM=3, New max L, New max DM Format of output to screen: n=9 UUDUDDD L=8 DM=3, New max L, New max DM } const Limit = 200; { Limit of run } var Ch : Char; { Character input by ReadKey } 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 } Down : LongInt; { Number of times x was even } n : ^MultiSI; { Starting x, x zero } x : ^MultiSI; { Current value of x } x2 : ^MultiSI; { Current x squared } x3 : ^MultiSI; { Current x cubed } One : ^MultiSI; { One in MultiSI format } Lim : ^MultiSI; { Limit of run, set to Limit } LSD : LongInt; { Least significant super digit } Di : LongInt; { Decimal digits in x } DM : LongInt; { Number of decimal digits in max x for this x zero } MDM : LongInt; { Number of decimal digits in max x so far } L : LongInt; { Length of sequence } ML : LongInt; { Max length of sequence so far } NewMDM: Boolean; { True if new max DM this time } NewML : Boolean; { True if new max L this time } {--------------------------------------} procedure Init; { Initialize program } begin TextBackground( Blue); TextColor( Yellow); ClrScr; WriteLn; WriteLn( Name); WriteLn( Version); WriteLn( Author); WriteLn( Address); WriteLn; FileSt:= 'Juggler0.Out'; WriteLn( 'Will write file: ', FileSt, ' to show results'); MultiIDV.Init( 1); { Init Multiple-precision integer decimal algorithms } MuLenD:= 21; MuErrRep:= True; New( One, Init(1)); One^.SetTo1( 1); { Create new objects } New( Lim, Init(1)); Lim^.SetTo1( Limit); Size:= 1 + (271 div MuDMax); { Allow up to 271 decimal digit numbers } New( n, Init( 2 * Size div 3)); n^.SetTo1(1); 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 } {--------------------------------------} function Digits(x : MultiUI) : LongInt; { Compute number of digits in x } var Q : LongInt; I : Integer; begin Q:= Round( x.V^[ x.N - 1]); I:= 0; repeat Q:= Q div 10; Inc(I); until Q = 0; Digits:= I + MuDMax * LongInt( x.N - 1); end; { Digits } {--------------------------------------} begin { Main program, Juggler0 } Init; Assign( Disk, FileSt); Rewrite( Disk); WriteLn; WriteLn( Disk, 'Juggler Sequences with initial x <= ', Limit, ' (Juggler0)'); WriteLn( Disk, '(L=Sequence length, DM=Number of digits in max x for this sequence)'); WriteLn( Disk); MDM:= 0; ML:= 0; n^.RAdd1( -1); repeat n^.RAdd1( 1); x^.SetTo( n^); Up:= 0; Down:= 0; DM:= Digits(x^); NewMDM:= False; NewML:= False; n^.Writ( Disk); Write('n='); n^.Writ( Output); Write(' '); 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^); Di:= Digits(x^); if Di > DM then begin DM:= Di; end; end else begin Inc( Down); Write('D'); Tracn:= Down; Trace:= Up; x^.SqRtRem( x^, x3^); end; Write(Disk, ' -> '); x^.Writ(Disk); until (x^.Comp( One^) = 0) or MuErr or MuAbort; Write(Disk, '; '); L:= Up + Down + 1; if (x^.Comp( n^) = 0) then L:= 1; if L > ML then begin ML:= L; NewML:= True; end; if DM > MDM then begin MDM:= DM; NewMDM:= True; end; Write( Disk, 'L=', L, ', DM=', DM); Write(' L=', L, ' DM=', DM); if NewML then Write( Disk, ', New max L'); if NewML then Write( ', New max L'); if NewMDM then Write( Disk, ', New max DM'); if NewMDM then Write( ', New max DM'); WriteLn( Disk); WriteLn; until (n^.Comp(Lim^) >= 0) or MuErr or MuAbort; if MuErr then WriteLn( Disk, 'Numbers got too big for memory') else if MuAbort then WriteLn( Disk, 'Run aborted by operator'); Close( Disk); Ch:= ReadKey; end. { Juggler0 } { End of file Juggler0.PAS *************************************************}