我对 Julia 非常陌生,并尝试实现/重写我以前的一些 Python 代码作为练习。我使用 Project Euler Problem 25 作为练习
在Python中我有
def fibonacci(N):
"""Returns the Nth Fibonacci Number"""
F = [0, 1]
i = 0
while i <= N-2:
F_new = F[i] + F[i+1]
F.append(F_new)
i += 1
return F[N]
N = 0
x = 1000
while len(str(fibonacci(N))) <= x:
if len(str(fibonacci(N))) == x:
print(N)
break
N = N + 1
Run Code Online (Sandbox Code Playgroud)
它运行并在大约 6.5 秒内给我正确的答案。当尝试在下面的 Julia 中执行此操作时
function fib(N)
F = [0, 1]
global i = 1
while i <= N-2 …Run Code Online (Sandbox Code Playgroud)