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,9 @@
/*REXX program returns the hailstone (Collatz) sequence for any integer.*/
numeric digits 20 /*ensure enough digits for mult. */
parse arg n 1 s /*N & S assigned to the first arg*/
do while n\==1 /*loop while N isn't unity. */
if n//2 then n=n*3+1 /*if N is odd, calc: 3*n +1 */
else n=n%2 /* " " " even, perform fast ÷ */
s=s n /*build a sequence list (append).*/
end /*while*/
return s

View file

@ -0,0 +1,16 @@
/*REXX pgm tests a number and a range for hailstone (Collatz) sequences.*/
parse arg x .; if x=='' then x=27 /*get the optional first argument*/
$=hailstone(x) /*═════════════task 2════════════*/
#=words($) /*number of numbers in sequence. */
say x 'has a hailstone sequence of' # 'and starts with: ' subword($,1,4),
' and ends with:' subword($,#-3)
say
w=0; do j=1 for 99999 /*═════════════task 3════════════*/
$=hailstone(j); #=words($) /*obtain the hailstone sequence. */
if #<=w then iterate /*Not big 'nuff? Then keep going.*/
bigJ=j; w=# /*remember what # has biggest HS.*/
end /*j*/
say '(between 199,999) ' bigJ 'has the longest hailstone sequence:' w
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,15 @@
/*REXX pgm finds the most common (popular) hailstone sequence length. */
parse arg z .; if z=='' then z=99999 /*get the optional first argument*/
!.=0
w=0; do j=1 for z /*═════════════task 4════════════*/
#=words(hailstone(j)) /*obtain hailstone sequence count*/
!.# = !.# + 1 /*add unity to popularity count. */
end /*j*/
occ=0; p=0
do k=1 for z
if !.k>occ then do; occ=!.k; p=k; end
end /*p*/
say '(between 1'z") " p,
' is the most common hailstone sequence length (with' occ "occurrences)."
/*stick a fork in it, we're done.*/