RosettaCodeData/Task/Juggler-sequence/11l/juggler-sequence-2.11l

38 lines
916 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
F isqrt(BigInt x)
assert(x >= 0)
V q = BigInt(1)
L q <= x
q *= 4
V z = x
V r = BigInt(0)
L q > 1
q I/= 4
V t = z - r - q
r I/= 2
I t >= 0
z = t
r += q
R r
F juggler(k, countdig = 1B, maxiters = 1000)
V (m, maxj, maxjpos) = (BigInt(k), BigInt(k), 0)
L(i) 1 .< maxiters
m = I m % 2 == 0 {isqrt(m)} E isqrt(m * m * m)
I m >= maxj
(maxj, maxjpos) = (m, i)
I m == 1
print(f:{k:9}{commatize(i):6}{maxjpos:6}{commatize(I countdig {String(maxj).len} E maxj):20}{I countdig { digits} E })
R i
print(ERROR: Juggler series starting with k did not converge in maxiters iterations)
print(" n l(n) i(n) h(n) or d(n)\n-------------------------------------------")
L(k) 20..39
juggler(k, 0B)
L(k) [113, 173, 193, 2183, 11229, 15065]
juggler(k)