Juggler sequence: Difference between revisions

julia example
m (→‎{{header|Factor}}: remove unused vocab)
(julia example)
Line 223:
5,812,827 135 67 7,996,276
7,110,201 205 119 89,981,517
</pre>
 
=={{header|Julia}}==
<lang julia>using Formatting
 
function juggler(k, countdig=true, maxiters=20000)
series, m, maxj, maxjpos = [BigInt(k)], BigInt(k), BigInt(k), BigInt(0)
for i in 1:maxiters
m = iseven(m) ? isqrt(m) : isqrt(m*m*m)
if m >= maxj
maxj, maxjpos = m, i
end
if m == 1
println(lpad(k, 9), lpad(i, 6), lpad(maxjpos, 6), lpad(format(countdig ?
ndigits(maxj) : Int(maxj), commas=true), 20), countdig ? " digits" : "")
return i
end
end
error("Juggler series starting with $k did not converge in $maxiters iterations")
end
 
println(" n l(n) i(n) h(n) or d(n)\n------------------------------------------")
foreach(k -> juggler(k, false), 20:39)
foreach(juggler,
[113, 173, 193, 2183, 11229, 15065, 15845, 30917, 48443, 275485, 1267909,
2264915, 5812827])
@time juggler(7110201)
</lang>{{out}}
<pre>
n l(n) i(n) h(n) or d(n)
------------------------------------------
20 3 0 20
21 9 4 140
22 3 0 22
23 9 1 110
24 3 0 24
25 11 3 52,214
26 6 3 36
27 6 1 140
28 6 3 36
29 9 1 156
30 6 3 36
31 6 1 172
32 6 3 36
33 8 2 2,598
34 6 3 36
35 8 2 2,978
36 3 0 36
37 17 8 24,906,114,455,136
38 3 0 38
39 14 3 233,046
113 16 9 27 digits
173 32 17 82 digits
193 73 47 271 digits
2183 72 32 5,929 digits
11229 101 54 8,201 digits
15065 66 25 11,723 digits
15845 139 43 23,889 digits
30917 33 12 22 digits
48443 157 60 972,463 digits
275485 225 148 1,909,410 digits
1267909 151 99 1,952,329 digits
2264915 149 89 2,855,584 digits
5812827 135 67 7,996,276 digits
7110201 205 119 89,981,517 digits
89.493898 seconds (1.11 M allocations: 27.713 GiB, 1.19% gc time)
</pre>
 
4,102

edits