Created
February 25, 2019 06:29
-
-
Save lqqyt2423/dfee27dcdd138c18155844bfd707b4f9 to your computer and use it in GitHub Desktop.
js py rb 斐波那契
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fibonacci(n) { | |
if (n == 0 || n == 1) return n; | |
return fibonacci(n - 1) + fibonacci(n - 2); | |
} | |
const now = Date.now(); | |
const i = fibonacci(40); | |
console.log(i); | |
console.log(String(Date.now() - now), 'ms'); | |
===== | |
import time | |
def fibonacci(n): | |
if n == 0 or n == 1: | |
return n | |
return fibonacci(n-1) + fibonacci(n-2) | |
start_time = time.time() | |
print(fibonacci(40)) | |
print("%s s" % (time.time() - start_time)) | |
===== | |
def fibonacci n | |
if n == 0 || n == 1 | |
return n | |
end | |
return fibonacci(n-1) + fibonacci(n-2) | |
end | |
start = Time.now | |
p fibonacci(40) | |
p Time.now - start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment