diff options
| author | Packy Anderson <packy@cpan.org> | 2023-11-06 09:29:12 -0500 |
|---|---|---|
| committer | Packy Anderson <packy@cpan.org> | 2023-11-06 09:31:49 -0500 |
| commit | 52d9817d77c3d699702e36868234ff8d34ab2437 (patch) | |
| tree | ab3b5ac6f224578242890f3443f62c1addace600 /challenge-242/packy-anderson/python/ch-2.py | |
| parent | a82dd587d3773d2a36a1fcc4b3c525c031433a4a (diff) | |
| download | perlweeklychallenge-club-52d9817d77c3d699702e36868234ff8d34ab2437.tar.gz perlweeklychallenge-club-52d9817d77c3d699702e36868234ff8d34ab2437.tar.bz2 perlweeklychallenge-club-52d9817d77c3d699702e36868234ff8d34ab2437.zip | |
Challenge 242 solutions by Packy Anderson
* Raku
* Perl
* Python
1 Blog post
Diffstat (limited to 'challenge-242/packy-anderson/python/ch-2.py')
| -rwxr-xr-x | challenge-242/packy-anderson/python/ch-2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-242/packy-anderson/python/ch-2.py b/challenge-242/packy-anderson/python/ch-2.py new file mode 100755 index 0000000000..dd5dc075ab --- /dev/null +++ b/challenge-242/packy-anderson/python/ch-2.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +def flipMatrix(matrix): + for index in range(0, len(matrix)): + matrix[index] = map( + lambda i: abs(i - 1), reversed(matrix[index]) + ) + return matrix + +def comma_join(arr): + return ', '.join(map(lambda i: str(i), arr)) + +def formatArray(matrix): + formatted = [] + for subarray in matrix: + formatted.append('[' + comma_join(subarray) + ']') + return '(' + comma_join(formatted) + ')' + +def solution(matrix): + print(f'Input: @matrix = {formatArray(matrix)}') + output = flipMatrix(matrix) + print(f'Output: {formatArray(output)}') + +print('Example 1:') +solution([[1, 1, 0], [1, 0, 1], [0, 0, 0]]) + +print('\nExample 2:') +solution([[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]])
\ No newline at end of file |
