aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Firkins <michael@firkins>2023-11-07 14:36:55 +1100
committerMichael Firkins <michael@firkins>2023-11-07 14:36:55 +1100
commitfc617cb1d972620a289435540faa93c6f5f956e1 (patch)
tree9b43f74fb32121c41be38538f5e9e56eae4e5c27
parenta82dd587d3773d2a36a1fcc4b3c525c031433a4a (diff)
downloadperlweeklychallenge-club-fc617cb1d972620a289435540faa93c6f5f956e1.tar.gz
perlweeklychallenge-club-fc617cb1d972620a289435540faa93c6f5f956e1.tar.bz2
perlweeklychallenge-club-fc617cb1d972620a289435540faa93c6f5f956e1.zip
pwc242 solution in python
-rw-r--r--challenge-242/pokgopun/python/ch-1.py55
-rw-r--r--challenge-242/pokgopun/python/ch-2.py57
2 files changed, 112 insertions, 0 deletions
diff --git a/challenge-242/pokgopun/python/ch-1.py b/challenge-242/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..bafb16347a
--- /dev/null
+++ b/challenge-242/pokgopun/python/ch-1.py
@@ -0,0 +1,55 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-242/
+"""
+
+Task 1: Missing Members
+
+Submitted by: [42]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given two arrays of integers.
+
+ Write a script to find out the missing members in each other arrays.
+
+Example 1
+
+Input: @arr1 = (1, 2, 3)
+ @arr2 = (2, 4, 6)
+Output: ([1, 3], [4, 6])
+
+(1, 2, 3) has 2 members (1, 3) missing in the array (2, 4, 6).
+(2, 4, 6) has 2 members (4, 6) missing in the array (1, 2, 3).
+
+Example 2
+
+Input: @arr1 = (1, 2, 3, 3)
+ @arr2 = (1, 1, 2, 2)
+Output: ([3])
+
+(1, 2, 3, 3) has 2 members (3, 3) missing in the array (1, 1, 2, 2). Since they
+are same, keep just one.
+(1, 1, 2, 2) has 0 member missing in the array (1, 2, 3, 3).
+
+Task 2: Flip Matrix
+"""
+### solution by pokgopun@gmail.com
+
+def findMissing(tup1, tup2):
+ return tuple(
+ filter(lambda x: len(x) > 0,
+ (
+ set(tup1).difference(set(tup2)),
+ set(tup2).difference(set(tup1)),
+ )
+ )
+ )
+
+
+
+for (inpt1,inpt2),otpt in {
+ ((1, 2, 3),(2, 4, 6)): ({1, 3}, {4, 6}),
+ ((1, 2, 3, 3),(1, 1, 2, 2)): ({3},),
+ }.items():
+ print(findMissing(inpt1,inpt2)==otpt)
+
+
+
diff --git a/challenge-242/pokgopun/python/ch-2.py b/challenge-242/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..71bacae9e1
--- /dev/null
+++ b/challenge-242/pokgopun/python/ch-2.py
@@ -0,0 +1,57 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-242/
+"""
+
+Task 2: Flip Matrix
+
+Submitted by: [43]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given n x n binary matrix.
+
+ Write a script to flip the given matrix as below.
+1 1 0
+0 1 1
+0 0 1
+
+a) Reverse each row
+
+0 1 1
+1 1 0
+1 0 0
+
+b) Invert each member
+
+1 0 0
+0 0 1
+0 1 1
+
+Example 1
+
+Input: @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0])
+Output: ([1, 0, 0], [0, 1, 0], [1, 1, 1])
+
+Example 2
+
+Input: @matrix = ([1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0])
+Output: ([1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0])
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 12th November
+ 2023.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+def flipMatrix(tup):
+ return tuple(
+ map(lambda x: tuple( i ^ 1 for i in reversed(x)) , tup)
+ )
+
+
+for inpt,otpt in {
+ ((1, 1, 0), (1, 0, 1), (0, 0, 0)): ((1, 0, 0), (0, 1, 0), (1, 1, 1)),
+ ((1, 1, 0, 0), (1, 0, 0, 1), (0, 1, 1, 1), (1, 0, 1, 0)): ((1, 1, 0, 0), (0, 1, 1, 0), (0, 0, 0, 1), (1, 0, 1, 0)),
+ }.items():
+ print(flipMatrix(inpt)==otpt)