Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,23 @@
BEGIN # Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even #
# = floor(sqrt(a[k]))*a[k] otherwise #
# find the number of terms required to reach a[n] = 1, the maximum value of the sequence #
# before it reaches 1 and the index at which the maximum was first reached #
print( ( " n l[n] h[n] i[n]", newline ) );
print( ( "=============================", newline ) );
FOR a0 FROM 20 TO 39 DO
INT ak := a0, amax := 0, aindex := 0, mindex := 0;
WHILE ak /= 1 DO
IF amax < ak THEN
amax := ak;
mindex := aindex
FI;
aindex +:= 1;
REAL root ak = sqrt( ak );
ak := ENTIER IF ODD ak THEN root ak * ak ELSE root ak FI
OD;
print( ( whole( a0, -2 ), whole( aindex, -5 ), whole( amax, -16 ), whole( mindex, -5 ), newline ) )
OD
END

View file

@ -0,0 +1,78 @@
with Ada.Text_IO;
with Ada.Numerics.Generic_Elementary_Functions;
procedure Juggler is
subtype Number is Long_Long_Integer;
type Index_Type is new Natural;
subtype Initial_Values is Number range 20 .. 39;
generic
Initial : Number;
package Generic_Juggler is
procedure Next (Value : out Number; Index : out Index_Type);
end Generic_Juggler;
package body Generic_Juggler is
type Real is new Long_Long_Float;
package Real_Math is
new Ada.Numerics.Generic_Elementary_Functions (Real);
K : Index_Type := 0;
A_K : Real := Real (Initial);
procedure Next (Value : out Number; Index : out Index_Type) is
use Real_Math;
begin
Value := Number (A_K);
Index := K;
A_K := (if Number (A_K) mod 2 = 0
then Real'Floor (A_K ** 0.5)
else Real'Floor (A_K ** 1.5));
K := K + 1;
end Next;
end Generic_Juggler;
procedure Statistics (N : Number; L_N : out Index_Type;
H_N : out Number; I_N : out Index_Type)
is
package Juggler_Generator is new Generic_Juggler (Initial => N);
use Juggler_Generator;
Value : Number;
begin
H_N := 0;
I_N := 0;
loop
Next (Value, L_N);
if Value > H_N then
H_N := Value;
I_N := L_N;
end if;
exit when Value = 1;
end loop;
end Statistics;
procedure Put_Table is
package Number_IO is new Ada.Text_IO.Integer_IO (Number);
package Index_IO is new Ada.Text_IO.Integer_IO (Index_Type);
use Ada.Text_IO, Number_IO, Index_IO;
L_N : Index_Type;
H_N : Number;
I_N : Index_Type;
begin
Put_Line (" N L(N) H(N) I(N)");
Put_Line ("---------------------------------");
for N in Initial_Values loop
Statistics (N, L_N, H_N, I_N);
Put (N, Width => 3); Put (L_N, Width => 7);
Put (H_N, Width => 16); Put (I_N, Width => 7); New_Line;
end loop;
end Put_Table;
begin
Put_Table;
end Juggler;

View file

@ -0,0 +1,58 @@
scope # Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even
# = floor(sqrt(a[k]))*a[k] otherwise
import mapm; # explicit import needed for: Linux, Mac OS X, Windows and Solaris
mapm.xdigits( 10_000 ); # enough digits for the first few stretch sequences
local constant b0, constant b1 := mapm.xnumber( 0 ), mapm.xnumber( 1 );
# for a[0] = a0, returns the number of terms required to reach a[n] = 1,
# the maximum value of the sequence before it reaches 1
# and the index at which the maximum was first reached
local proc jugglarStatistics( a0 :: number ) :: table
local ak, amax, aindex, mindex := mapm.xnumber( a0 ), b0, 0, 0;
while ak <> b1 do
if amax < ak then
amax, mindex := ak, aindex
fi;
aindex +:= 1;
local constant rootAk := mapm.xsqrt( ak );
ak := mapm.xfloor( if mapm.xisodd( ak ) then rootAk * ak else rootAk fi )
od;
return [ "a0" ~ a0, "length" ~ aindex, "max" ~ amax, "maxIndex" ~ mindex ]
end;
# returns a string representation of the integer portion of n if it is an xnumber,
# or n if it is a string or tostring( n ) otherwise
local proc bToIntegerString( n ) :: string
if typeof n = "string" then
return n
elif typeof n = "xnumber" then
local constant str := mapm.xtostring( n )
local constant point := "." in str
return if point <> null then str[ 1 to point - 1 ] else str fi
else
return tostring( n )
fi
end;
local proc printJugglarStatistics( jStats :: table )
local maxString := bToIntegerString( jStats.max );
if size maxString > 32 then
maxString := tostring( size maxString ) & " digits"
fi;
printf( "%6.0f%10.0f%10.0f %s\n", jStats.a0, jStats.length, jStats.maxIndex, maxString );
end;
scope
print( " n l[n] i[n] h[n]" );
print( "=====================================================================" );
for a0 from 20 to 39 do
printJugglarStatistics( jugglarStatistics( a0 ) )
od;
for a0 in seq( 113, 173, 193, 2183 ) do
printJugglarStatistics( jugglarStatistics( a0 ) )
od
end
end

View file

@ -0,0 +1,29 @@
proc juggler a &cnt &max &maxidx .
max = a
maxidx = 0
cnt = 0
while a <> 1
if a mod 2 = 0
a = floor sqrt a
else
a = floor (a * sqrt a)
.
cnt += 1
if a > max
max = a
maxidx = cnt
.
.
.
numfmt 6 0
print " n l[n] h[n] i[n]"
print "-----------------------------"
for n = 20 to 39
juggler n cnt max maxidx
numfmt 3 0
write n & cnt
numfmt 16 0
write max
numfmt 5 0
print maxidx
.

View file

@ -0,0 +1,28 @@
(do ;;; Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even
;;; = floor(sqrt(a[k]))*a[k] otherwise
; find the number of terms required to reach a[n] = 1, the maximum value of the sequence
; before it reaches 1 and the index at which the maximum was first reached
(print " n l[n] h[n] i[n]")
(print "=============================")
(for [a0 20 39]
(var (ak amax aindex mindex) (values a0 0 0 0))
(while (not= ak 1)
(when (< amax ak)
(set (amax mindex) (values ak aindex))
)
(set aindex (+ aindex 1))
(local root-ak (math.sqrt ak))
(set ak (math.floor (if (= 1 (% ak 2))
(* root-ak ak)
;else
root-ak
)
)
)
)
(print (string.format "%2d%5d%16d%5d" a0 aindex amax mindex))
)
)

View file

@ -0,0 +1,164 @@
// ------------------------------------------------------------
// Juggler Sequences
//
// Using FutureBasic 7.0.37
// November 2025, R.W.
// ------------------------------------------------------------
include "gmp.incl"
CFTimeInterval tim
// Global mpz_t bigints reused for speed
mpz_t js // current term in sequence
mpz_t ln // temp for powers
mpz_t hn // current maximum value in sequence
UInt64 res(2) // res(0)=l[n], res(1)=i[n], res(2)=d[n] (digit count)
// Rosetta task part 2 + extra huge
long rs(14) = {113, 173, 193, 2183, 11229, 15065, 15845, ¬
30817, 48443, 275485, 1267909, 2264915, 5812827, 7110201, 604398963}
// -----------------------------------------------------------
// Helper: Convert mpz_t to CFString
// -----------------------------------------------------------
local fn mpz_to_CFString( m as mpz_t ) as CFStringRef
CFStringRef result = @""
result = fn mpz_cf2( m ) // FB wrapper mpz_t → CFString base 10
end fn = result
// ------------------------------------------------------------
// JugglerSequence
// calculate juggler sequence for n
// results in globals:
// res(0) = l[n] (steps to reach 1)
// res(1) = i[n] (index of first maximum, 0-based)
// res(2) = d[n] (decimal digit count of maximum)
// ------------------------------------------------------------
void local fn JugglerSequence( n as Int )
UInt64 steps, idx, maxIdx, digits
steps = 0: idx = 0: maxIdx = 0
fn mpz_set_ui( js, n ) // js = current term (n)
fn mpz_set( hn, js ) // hn = current maximum
// iterate until we reach 1
while ( fn mpz_cmp_ui( js, 1 ) != 0 )
// even vs odd
if ( fn mpz_tstbit( js, 0 ) == 0 ) //test bit zero
fn mpz_sqrt( js, js ) // even: a_{k+1} = floor( sqrt(a_k) )
else
// odd: a_{k+1} = floor( a_k^(3/2) ) = floor( sqrt(a_k^3) )
fn mpz_mul( ln, js, js ) // ln = js^2
fn mpz_mul( ln, ln, js ) // ln = js^3
fn mpz_sqrt( js, ln ) // js = floor( sqrt(js^3) )
end if
steps ++
idx ++
// update maximum and its first index
if ( fn mpz_cmp( js, hn ) > 0 )
fn mpz_set( hn, js )
maxIdx = idx
end if
wend
// compute decimal digit count d[n] of hn
digits = fn mpz_sizeinbase( hn, 10 )
// mpz_sizeinbase can overestimate by 1 digit; adjust if needed
// (see GMP 6.3.0 manual page 45)
if digits > 0
fn mpz_ui_pow_ui( ln, 10, digits - 1 )
if ( fn mpz_cmp( ln, hn ) > 0 )
digits -- // decrement
end if
end if
res(0) = steps
res(1) = maxIdx
res(2) = digits
end fn
// ------------------------------------------------------------
// More_JS
// show the next specific juggler sequences up to 604,398,963
// ------------------------------------------------------------
void local fn More_JS
CFStringRef pline
CFTimeInterval elapsed
Int i, n
for i = 0 to 14
if i = 0
print @" n l[n] i[n] d[n]"
print @"-----------------------------------"
end if
tim = fn CACurrentMediaTime
n = rs(i)
fn JugglerSequence( n )
pline = fn StringWithFormat( @"%l9d %l5d %l5d %l9d ", n, res(0), res(1), res(2) )
print @pline;
elapsed = fn CACurrentMediaTime - tim
if elapsed < 1
printf @"(%.3f ms)", elapsed * 1000
else
printf @"(%.3f secs)", elapsed
end if
next i
button 2, NO
end fn
// ------------------------------------------------------------
// Main — compute juggler sequences for n = 20..39
// ------------------------------------------------------------
local fn Main
CFStringRef pline = @""
CFStringRef hStr
Int n
// init mpz globals once
mpz_init( js )
mpz_init( ln )
mpz_init( hn )
tim = fn CACurrentMediaTime
print @" n l[n] i[n] d[n]"
print @"-----------------------------------"
for n = 20 to 39 // Rosetta task
fn JugglerSequence( n )
// hn holds the maximum; convert to CFString for display
hStr = fn mpz_to_CFString( hn )
pline = fn StringWithFormat( @"%l9d %5d %5d %@", n, res(0), res(1), hStr )
print @pline
next n
printf @"\nElapsed time: %.3f secs", (fn CACurrentMediaTime - tim)
print @"Click [Next] for the next juggler sequences.\n"
end fn
// ------------------------------------------------------------
// Dialog handler
// ------------------------------------------------------------
void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef )
select ( ev )
case _btnClick
select ( tag )
case 2
fn More_JS
end select
case _windowShouldClose
// clear any mpz before quitting
mpz_clear( js )
mpz_clear( ln )
mpz_clear( hn )
end
end select
end fn
on dialog fn DoDialog
// ------------------------------------------------------------
// Main
// ------------------------------------------------------------
window 1, @"Juggler Sequences", (0,0,500,640)
button 2, YES,, @"Next", (380,20,100,20),,, 1
fn Main
HandleEvents

View file

@ -0,0 +1,22 @@
do -- Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even
-- = floor(sqrt(a[k]))*a[k] otherwise
-- find the number of terms required to reach a[n] = 1, the maximum value of the sequence
-- before it reaches 1 and the index at which the maximum was first reached
print( " n l[n] h[n] i[n]" )
print( "=============================" )
for a0 = 20, 39 do
local ak, amax, aindex, mindex = a0, 0, 0, 0
while ak ~= 1 do
if amax < ak then
amax, mindex = ak, aindex
end
aindex = aindex + 1
local rootAk <const> = math.sqrt( ak )
ak = math.floor( ak % 2 == 1 and rootAk * ak or rootAk )
end
print( string.format( "%2d%5d%16d%5d", a0, aindex, amax, mindex ) )
end
end

View file

@ -0,0 +1,22 @@
do -- Jugglar sequences - starting with a[0] = n, a[k+1] = floor(sqrt(a[k])) if a[k] is even
-- = floor(sqrt(a[k]))*a[k] otherwise
-- find the number of terms required to reach a[n] = 1, the maximum value of the sequence
-- before it reaches 1 and the index at which the maximum was first reached
print( " n l[n] h[n] i[n]" )
print( "=============================" )
for a0 = 20, 39 do
local ak, amax, aindex, mindex = a0, 0, 0, 0
while ak != 1 do
if amax < ak then
amax, mindex = ak, aindex
end
++ aindex
local rootAk <const> = math.sqrt( ak )
ak = math.floor( if ak % 2 == 1 then rootAk * ak else rootAk end )
end
print( string.format( "%2d%5d%16d%5d", a0, aindex, amax, mindex ) )
end
end

View file

@ -0,0 +1,36 @@
import math
struct JugglerResult {
mut:
cnt i64
max i64
maxidx i64
}
fn juggler(pir i64) JugglerResult {
mut ir := pir
mut res := JugglerResult{
cnt: 0
max: ir
maxidx: 0
}
for ir != 1 {
if ir % 2 == 0 { ir = i64(math.floor(math.sqrt(f64(ir)))) }
else { ir = i64(math.floor(f64(ir) * math.sqrt(f64(ir)))) }
res.cnt += 1
if ir > res.max {
res.max = ir
res.maxidx = res.cnt
}
}
return res
}
fn main() {
println(" n l[n] h[n] i[n]")
println("-------------------------------------")
for nir := i64(20); nir <= i64(39); nir++ {
res := juggler(nir)
println("${nir:3} ${res.cnt:3} ${res.max:16} ${res.maxidx:5}")
}
}