Stern-Brocot sequence: Difference between revisions

Content added Content deleted
m (fix a mistranslation of the Python version's indexing)
mNo edit summary
Line 3,040: Line 3,040:
function sternbrocot(f::Function=(x) -> length(x) ≥ 20)::Vector{Int}
function sternbrocot(f::Function=(x) -> length(x) ≥ 20)::Vector{Int}
rst = Int[1, 1]
rst = Int[1, 1]
i = 3
i = 2
while !f(rst)
while !f(rst)
append!(rst, Int[rst[i-1] + rst[i-2], rst[i-2]])
append!(rst, Int[rst[i] + rst[i-1], rst[i]])
i += 1
i += 1
end
end