Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,30 @@
include c:\cxpl\codes; \intrinsic 'code' declarations
int Seq(1000); \more than enough for longest sequence
func Hailstone(N); \Return length of Hailstone sequence starting at N
int N; \ also fills Seq array with sequence
int I;
[I:= 0;
loop [Seq(I):= N; I:= I+1;
if N=1 then return I;
N:= if N&1 then N*3+1 else N/2;
];
];
int N, SN, Len, MaxLen;
[Len:= Hailstone(27);
Text(0, "27's Hailstone length = "); IntOut(0, Len); CrLf(0);
Text(0, "Sequence = ");
for N:= 0 to 3 do [IntOut(0, Seq(N)); ChOut(0, ^ )];
Text(0, "... ");
for N:= Len-4 to Len-1 do [IntOut(0, Seq(N)); ChOut(0, ^ )];
CrLf(0);
MaxLen:= 0;
for N:= 1 to 100_000-1 do
[Len:= Hailstone(N);
if Len > MaxLen then [MaxLen:= Len; SN:= N]; \save N with max length
];
IntOut(0, SN); Text(0, "'s Hailstone length = "); IntOut(0, MaxLen);
]