|
|
|
|
|
by jessaustin
1918 days ago
|
|
TFA would seem more reliable if it didn't have such a needlessly obscurantist Fortran-python code comparison. Nothing about the two languages calls for different base case logic! That is, in order to prevent confusion, the "Python3" code should have been this: def fibonacci(n):
if n < 2:
return n
else:
return fibonacci(n-1) + fibonacci(n-2)
|
|
I haven't written Fortran in a while, but I was pretty sure that for illustrative examples like this, you could dispense with the entire MODULE declaration, the use of END FUNCTION Fibonacci instead of just END, and the usually-optional :: separator between the variable's type and name.
Something like this? Again, no recent experience:
(The IMPLICIT NONE has to stay because of the now-regrettable Fortran convention that without it, the type of a variable is determined by the first character of the name (n would be integer because variables starting with m, n, i, etc. are integer, while fib would be floating point).)