aboutsummaryrefslogtreecommitdiff
path: root/entries/zgrannan/fib2.py
diff options
context:
space:
mode:
authorBraxton Hall2022-10-28 21:11:49 +0000
committerGitHub2022-10-28 21:11:49 +0000
commit828acba3e4c208b82f6336c7d963ec1250490185 (patch)
tree35af093163c30053b2849f53be7003994143155d /entries/zgrannan/fib2.py
parent655b211bef28aff53605783ab4dcce70579b1eed (diff)
parentf8975eb89a01287d4f4f3e236fb4bc7153d31325 (diff)
Merge pull request #67 from zgrannan/main
Sleep fib
Diffstat (limited to 'entries/zgrannan/fib2.py')
-rw-r--r--entries/zgrannan/fib2.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/entries/zgrannan/fib2.py b/entries/zgrannan/fib2.py
new file mode 100644
index 0000000..64672ef
--- /dev/null
+++ b/entries/zgrannan/fib2.py
@@ -0,0 +1,22 @@
+#!/usr/bin/env python3
+
+import sys
+import time
+
+def fib(n):
+ if n <= 1:
+ time.sleep(n)
+ else:
+ fib(n - 1)
+ fib(n - 2)
+
+
+start = time.time_ns()
+try:
+ n = int(sys.argv[-1])
+except ValueError:
+ n = 5
+fib(n)
+now = time.time_ns()
+result = round((now - start) / 1000000000)
+print(f"fib({n}) = {result}")