aboutsummaryrefslogtreecommitdiff
path: root/challenge-112/abigail/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-112/abigail/python/ch-2.py')
-rw-r--r--challenge-112/abigail/python/ch-2.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-112/abigail/python/ch-2.py b/challenge-112/abigail/python/ch-2.py
new file mode 100644
index 0000000000..3e2a55750d
--- /dev/null
+++ b/challenge-112/abigail/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+import fileinput
+
+cache = {0: 1, 1: 1}
+
+def fib (n):
+ if not n in cache:
+ cache [n] = fib (n - 1) + fib (n - 2)
+ return (cache [n])
+
+for line in fileinput . input ():
+ print (fib (int (line)))