aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Grannan2022-10-28 19:15:41 +0000
committerZack Grannan2022-10-28 21:01:46 +0000
commitf8975eb89a01287d4f4f3e236fb4bc7153d31325 (patch)
tree59d52be05f3e7149d3c94354a45a9acf466c45c4
parente66315e5db9679072e601d376edcc940c559703c (diff)
Add another fib
-rw-r--r--entries/zgrannan/fib2.py22
-rw-r--r--people.json4
2 files changed, 26 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}")
diff --git a/people.json b/people.json
index 983861b..0b36c6d 100644
--- a/people.json
+++ b/people.json
@@ -421,6 +421,10 @@
{
"name": "human in the loop",
"link": "./entries/zgrannan/fib.py"
+ },
+ {
+ "name": "sleep",
+ "link": "./entries/zgrannan/fib2.py"
}
]
},