aboutsummaryrefslogtreecommitdiff
path: root/challenge-041/paulo-custodio/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-041/paulo-custodio/python/ch-2.py')
-rw-r--r--challenge-041/paulo-custodio/python/ch-2.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-041/paulo-custodio/python/ch-2.py b/challenge-041/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..cc11c93b79
--- /dev/null
+++ b/challenge-041/paulo-custodio/python/ch-2.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+# Challenge 041
+#
+# TASK #2
+# Write a script to display first 20 Leonardo Numbers. Please checkout wiki
+# page for more information.
+# For example:
+#
+# L(0) = 1
+# L(1) = 1
+# L(2) = L(0) + L(1) + 1 = 3
+# L(3) = L(1) + L(2) + 1 = 5
+# and so on.
+
+def leonardo(n):
+ if n < 2:
+ return 1
+ else:
+ return leonardo(n-1)+leonardo(n-2)+1
+
+out = []
+for n in range(20):
+ out.append(leonardo(n))
+print(", ".join([str(x) for x in out]))