From f8975eb89a01287d4f4f3e236fb4bc7153d31325 Mon Sep 17 00:00:00 2001 From: Zack Grannan Date: Fri, 28 Oct 2022 12:15:41 -0700 Subject: Add another fib --- entries/zgrannan/fib2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 entries/zgrannan/fib2.py (limited to 'entries/zgrannan/fib2.py') 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}") -- cgit v1.2.3-70-g09d2