Goodstein Sequence: Difference between revisions
m
→{{header|Julia}}: Using a generic vector instead of an inheritance tree of elements is faster here, for once.
(typo) |
m (→{{header|Julia}}: Using a generic vector instead of an inheritance tree of elements is faster here, for once.) |
||
Line 54:
=={{header|Julia}}==
<syntaxhighlight lang="julia">
b::T▼
"""
decomp = Vector{Union{typeof(n), Vector}}[]
e = typeof(n)(0)
▲""" given integer n and base b, return tuples (j, k) so sum of all (j * base^(evaluate(k)) = n. """
▲function decompose(n::T, bas::GBase) where T <: Integer
▲ e = T(0)
while n != 0
n, r = divrem(n,
if r
▲ else
end
e += 1
Line 90 ⟶ 73:
end
""" Evaluate hereditary representation d under base b """
evaluate(d, b) = d isa Integer ? d : sum(j * b ^ evaluate(k, b) for (j, k) in d)
""" Return a vector of up to limitlength values of the Goodstein sequence for n """
function goodstein(n
while
push!(
d = decompose(n, b)
n = evaluate(d, b) - 1
end
return
end
"""
A266201(n) = last(goodstein(BigInt(n),
println("Goodstein(n) sequence (first 10) for values of n from 0 through 7:")
for i in
println("Goodstein of $i:
end
println("\nThe Nth term of Goodstein(N) sequence counting from 0, for values of N from 0 through 16:")
for i in big"
println("Term $i of Goodstein($i}):
end
</syntaxhighlight>{{out}}
|