Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Stern-Brocot-sequence/Julia/stern-brocot-sequence.julia
Normal file
26
Task/Stern-Brocot-sequence/Julia/stern-brocot-sequence.julia
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using Printf
|
||||
|
||||
function sternbrocot(f::Function=(x) -> length(x) ≥ 20)::Vector{Int}
|
||||
rst = Int[1, 1]
|
||||
i = 2
|
||||
while !f(rst)
|
||||
append!(rst, Int[rst[i] + rst[i-1], rst[i]])
|
||||
i += 1
|
||||
end
|
||||
return rst
|
||||
end
|
||||
|
||||
println("First 15 elements of Stern-Brocot series:\n", sternbrocot(x -> length(x) ≥ 15)[1:15], "\n")
|
||||
|
||||
for i in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100)
|
||||
occurr = findfirst(x -> x == i, sternbrocot(x -> i ∈ x))
|
||||
@printf("Index of first occurrence of %3i in the series: %4i\n", i, occurr)
|
||||
end
|
||||
|
||||
print("\nAssertion: the greatest common divisor of all the two\nconsecutive members of the series up to the 1000th member, is always one: ")
|
||||
sb = sternbrocot(x -> length(x) > 1000)
|
||||
if all(gcd(prev, this) == 1 for (prev, this) in zip(sb[1:1000], sb[2:1000]))
|
||||
println("Confirmed.")
|
||||
else
|
||||
println("Rejected.")
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue