aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-11-11 18:31:36 +0000
committerGitHub <noreply@github.com>2022-11-11 18:31:36 +0000
commit29d850a7abac58f80e576225032b8f0914bc2441 (patch)
tree0626af85eeaf4330cb6dad2207bc992f82a84e58
parent78a97ea8621c3fc04c65bc6f5104b247f5601095 (diff)
parent7de4d5a50e78a1eb9653981e9702d95893785e9e (diff)
downloadperlweeklychallenge-club-29d850a7abac58f80e576225032b8f0914bc2441.tar.gz
perlweeklychallenge-club-29d850a7abac58f80e576225032b8f0914bc2441.tar.bz2
perlweeklychallenge-club-29d850a7abac58f80e576225032b8f0914bc2441.zip
Merge pull request #7060 from ealvar3z/challenge-190
Python solutions for PWC 190
-rw-r--r--challenge-190/ealvar3z/blog.txt1
-rw-r--r--challenge-190/ealvar3z/python/ch-1.py16
-rw-r--r--challenge-190/ealvar3z/python/ch-2.py47
3 files changed, 64 insertions, 0 deletions
diff --git a/challenge-190/ealvar3z/blog.txt b/challenge-190/ealvar3z/blog.txt
new file mode 100644
index 0000000000..11812a5649
--- /dev/null
+++ b/challenge-190/ealvar3z/blog.txt
@@ -0,0 +1 @@
+https://alvar3z.com/posts/perl-weekly-challenge-190/
diff --git a/challenge-190/ealvar3z/python/ch-1.py b/challenge-190/ealvar3z/python/ch-1.py
new file mode 100644
index 0000000000..e489011232
--- /dev/null
+++ b/challenge-190/ealvar3z/python/ch-1.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+
+
+if __name__ == "__main__":
+
+ tests = ['Perl', 'TPF', 'PyThon', 'raku']
+
+ for w in tests:
+ match w:
+ case w if not w.isupper() and not w.istitle() and not w.islower():
+ print(f'Input: {w}')
+ print('Output: 0')
+ case _:
+ print(f'Input: {w}')
+ print('Output: 1')
+
diff --git a/challenge-190/ealvar3z/python/ch-2.py b/challenge-190/ealvar3z/python/ch-2.py
new file mode 100644
index 0000000000..f19628a486
--- /dev/null
+++ b/challenge-190/ealvar3z/python/ch-2.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python3
+from __future__ import annotations
+from unittest import main, TestCase
+from typing import List
+
+
+def runner(start: str, i: int, arg: str, result: List[str]) -> None:
+ l = len(arg)
+ if i == l:
+ result.append(start)
+ return
+ nums = [int(arg[i])]
+
+ if i + 1 < l:
+ nums.append(int(arg[i] + arg[i+1]))
+
+ diff = 1
+ for n in nums:
+ if 1 <= n and n <= 26:
+ c = chr(ord('A') + n - 1)
+ runner(start + c, i + diff, arg, result)
+ diff += 1
+
+
+def decode(arg: str) -> List[str]:
+ result = []
+ runner("", 0, arg, result)
+ return result
+
+
+class TestDecodeList(TestCase):
+
+
+ def test_example_one(self):
+ self.assertEqual(decode("11"), ["AA", "K"], 'Example 1')
+
+
+ def test_example_two(self):
+ self.assertEqual(decode("1115"), ["AAAE", "AAAO", "AKE", "KAE", "KO"], 'Example 2')
+
+
+ def test_example_three(self):
+ self.assertEqual(decode("127"), ["ABG", "LG"], 'Example 3')
+
+
+if __name__ == "__main__":
+ main(verbosity=2)