Created
October 30, 2013 17:19
-
-
Save reynir/7236502 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env python | |
import time | |
import sys | |
def fib(n): | |
return n if n <= 1 else fib(n-1) + fib(n-2) | |
def get_time(): | |
return int(round(time.time() * 1000)) | |
if __name__ == '__main__': | |
start = get_time() | |
N = int(sys.argv[1]) | |
print("Fibonacci from 0 to %d:" % N) | |
for (i, fi) in map(lambda i: (i, fib(i)), range(N+1)): | |
print("%d: %d" % (i, fi)) | |
stop = get_time() | |
print("time: %d ms" % (stop-start)) |
This file contains 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
$ python2 fib.py 32 # Nothing happens for a few secs and then the fibonacci numbers are printed | |
$ python3 fib.py 32 # The fibonacci numbers are printed one by one with a greater and greater interval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment