aboutsummaryrefslogtreecommitdiff
path: root/challenge-149/abigail/python/ch-1.py
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2022-02-10 17:28:53 +0800
committer冯昶 <seaker@qq.com>2022-02-10 17:28:53 +0800
commit24d07638f45f70838ba3721106c5c4f6d992f69e (patch)
tree618c14fbb4615765f95353129863d3ad85a88867 /challenge-149/abigail/python/ch-1.py
parent1ff224c623b04c549b24ec402ea43131cd910588 (diff)
parentaf7e6f300ff3d68b38412f2be2a4fc845ae19a79 (diff)
downloadperlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.tar.gz
perlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.tar.bz2
perlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-149/abigail/python/ch-1.py')
-rw-r--r--challenge-149/abigail/python/ch-1.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-149/abigail/python/ch-1.py b/challenge-149/abigail/python/ch-1.py
new file mode 100644
index 0000000000..1a7f8d33ac
--- /dev/null
+++ b/challenge-149/abigail/python/ch-1.py
@@ -0,0 +1,45 @@
+#!/usr/local/bin/python3
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-149
+#
+
+#
+# Run as: python ch-1.py < input-file
+#
+
+
+def digit_sum (number):
+ sum = 0
+ base = 10
+ while number > 0:
+ sum = sum + number % base
+ number = number // base
+ return sum
+
+fib = {}
+fib_prev = 0
+fib_last = 1
+fib [fib_prev] = True;
+fib [fib_last] = True;
+
+def is_fib (n):
+ global fib, fib_prev, fib_last
+ while fib_last < n:
+ t = fib_last
+ fib_last = fib_last + fib_prev
+ fib_prev = t
+ fib [fib_last] = True;
+ return n in fib
+
+import fileinput, sys
+
+for n in fileinput . input ():
+ n = int (n)
+ k = 0
+ while n > 0:
+ if is_fib (digit_sum (k)):
+ sys . stdout . write (str (k) + " ")
+ n = n - 1
+ k = k + 1
+ print ("")