diff options
| author | librasteve <40125330+librasteve@users.noreply.github.com> | 2023-11-07 20:11:22 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-07 20:11:22 +0000 |
| commit | 89f6be07a89a98d25f352f18850f24bf0ff7d985 (patch) | |
| tree | 032ab890354b0bc8b876ee9e0ba23cda7f244d1a /challenge-242/pokgopun/python/ch-2.py | |
| parent | c9d5f2834f979267d8d5db8fdaba52504a0c0b95 (diff) | |
| parent | db4d9fe6bf77ff58c31ec3e9d2f71d8acf7d58d4 (diff) | |
| download | perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.gz perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.bz2 perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-242/pokgopun/python/ch-2.py')
| -rw-r--r-- | challenge-242/pokgopun/python/ch-2.py | 57 |
1 files changed, 57 insertions, 0 deletions
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) |
