aboutsummaryrefslogtreecommitdiff
path: root/challenge-149
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-29 19:06:42 +0000
committerGitHub <noreply@github.com>2022-01-29 19:06:42 +0000
commit08aca04ee727fe420299eee41d1b59c4913becfa (patch)
treed5c427fbe0f991e276db6bfbeba53b20e98d1133 /challenge-149
parenta251cba67eef5e53ada003cec62f7de40ad4017c (diff)
parenta5cabf991ffa58f81f84cb02d7dbca8826e25f5c (diff)
downloadperlweeklychallenge-club-08aca04ee727fe420299eee41d1b59c4913becfa.tar.gz
perlweeklychallenge-club-08aca04ee727fe420299eee41d1b59c4913becfa.tar.bz2
perlweeklychallenge-club-08aca04ee727fe420299eee41d1b59c4913becfa.zip
Merge pull request #5581 from LubosKolouch/master
Challenge 149 Task 1 LK Python
Diffstat (limited to 'challenge-149')
-rw-r--r--challenge-149/lubos-kolouch/python/ch-1.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-149/lubos-kolouch/python/ch-1.py b/challenge-149/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..74fb3990be
--- /dev/null
+++ b/challenge-149/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,40 @@
+""" Challenge 149 Task 1"""
+fibs = []
+fib_hash = {}
+
+fibs.append(0)
+fibs.append(1)
+
+fib_hash[0] = 1
+fib_hash[1] = 1
+
+def gen_more_fibs(limit:int):
+ """ Generate more Fibonacci numbers if needed"""
+
+ while fibs[-1] < limit:
+ new_fib =fibs[-1] + fibs[-2]
+ fibs.append(new_fib)
+ fib_hash[new_fib] = 1
+
+
+def get_numbers(what: int):
+ """Get the list as required"""
+
+ count = 0
+ pos = 0
+
+ output = []
+
+ while count < what:
+ gen_more_fibs(pos)
+ try:
+ fib_hash[sum(list(map(int, str(pos))))]
+ output.append(pos)
+ count += 1
+ except KeyError:
+ pass
+ pos += 1
+
+ return output
+
+assert get_numbers(20) == [0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44]