aboutsummaryrefslogtreecommitdiff
path: root/challenge-150/paulo-custodio/python/ch-1.py
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-09-27 11:59:06 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-09-27 11:59:06 +0100
commit23bc575e1d957ae33105c1508dd8b6721a9f5331 (patch)
tree87ef6a4ba84591f90c974bb2ab089bfdd64bd9a9 /challenge-150/paulo-custodio/python/ch-1.py
parent7de6f2107b0b6852a3210340e7e4d31de11df7a6 (diff)
downloadperlweeklychallenge-club-23bc575e1d957ae33105c1508dd8b6721a9f5331.tar.gz
perlweeklychallenge-club-23bc575e1d957ae33105c1508dd8b6721a9f5331.tar.bz2
perlweeklychallenge-club-23bc575e1d957ae33105c1508dd8b6721a9f5331.zip
Add Python solution to challenge 150
Diffstat (limited to 'challenge-150/paulo-custodio/python/ch-1.py')
-rw-r--r--challenge-150/paulo-custodio/python/ch-1.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-150/paulo-custodio/python/ch-1.py b/challenge-150/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..b3b832d0a2
--- /dev/null
+++ b/challenge-150/paulo-custodio/python/ch-1.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env perl
+
+# Challenge 150
+#
+# TASK #1 > Fibonacci Words
+# Submitted by: Mohammad S Anwar
+#
+# You are given two strings having same number of digits, $a and $b.
+#
+# Write a script to generate Fibonacci Words by concatenation of the previous
+# two strings. Finally print 51st digit of the first term having at least
+# 51 digits.
+# Example:
+#
+# Input: $a = '1234' $b = '5678'
+# Output: 7
+#
+# Fibonacci Words:
+#
+# '1234'
+# '5678'
+# '12345678'
+# '567812345678'
+# '12345678567812345678'
+# '56781234567812345678567812345678'
+# '1234567856781234567856781234567812345678567812345678'
+#
+# The 51st digit in the first term having at least 51 digits
+# '1234567856781234567856781234567812345678567812345678' is 7.
+
+import sys
+
+pos = 51
+
+def fib_word(a, b, length):
+ seq = [a, b]
+ while len(seq[-1]) <= length:
+ seq.append(seq[-2] + seq[-1])
+ seq.pop(0)
+ return seq[-1]
+
+words = sys.argv[1:3]
+fib_word_result = fib_word(words[0], words[1], pos)
+print(fib_word_result[pos - 1])