aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Manfredi <manfredi@cpan.org>2023-04-12 08:00:43 +0000
committerLeo Manfredi <manfredi@cpan.org>2023-04-12 08:00:43 +0000
commit03b3de5ea0837a70ff825bc272a8e4ecec93d2ee (patch)
treef1697084edd4b9731f94a4e114f5fe2491307bb5
parent9902c096011711aa25a4fc118c96cc87411e3da4 (diff)
downloadperlweeklychallenge-club-03b3de5ea0837a70ff825bc272a8e4ecec93d2ee.tar.gz
perlweeklychallenge-club-03b3de5ea0837a70ff825bc272a8e4ecec93d2ee.tar.bz2
perlweeklychallenge-club-03b3de5ea0837a70ff825bc272a8e4ecec93d2ee.zip
Python Solution for Task #1
-rwxr-xr-xchallenge-212/manfredi/python/ch-1.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-212/manfredi/python/ch-1.py b/challenge-212/manfredi/python/ch-1.py
new file mode 100755
index 0000000000..2491158c2a
--- /dev/null
+++ b/challenge-212/manfredi/python/ch-1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+# Python 3.9.2 on Debian GNU/Linux 11 (bullseye)
+
+print('challenge-212-task1')
+
+# Task 1: Jumping Letters
+# You are given a word having alphabetic characters only, and a list of positive integers of the same length
+# Write a script to print the new word generated after jumping forward each letter in the given word by the integer in the list.
+# The given list would have exactly the number as the total alphabets in the given word.
+
+def jumping_letters(word: str, jump: list[int]) -> None:
+ lower = [ c.islower() for c in word ]
+ ascii = [ ord(c.upper()) for c in word ]
+ ascii_ord = [ (o + jump[i]) if (o + jump[i]) < ord('Z') else ((o + jump[i]) + ord('A') - 1 ) % (ord('Z')) for i, o in enumerate(ascii) ]
+ res = ''.join([ str(chr(c)).lower() if lower[i] else str(chr(c)) for i, c in enumerate(ascii_ord)])
+ print(f"{word}, '{jump}': {res}")
+
+def main():
+ word, jump = 'Perl', [2, 22, 19, 9]
+ jumping_letters(word, jump)
+ word, jump = 'Raku', [24, 4, 7, 17]
+ jumping_letters(word, jump)
+
+if __name__ == '__main__':
+ main()