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/luca-ferrari/python | |
| 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/luca-ferrari/python')
| -rw-r--r-- | challenge-242/luca-ferrari/python/ch-1.py | 45 | ||||
| -rw-r--r-- | challenge-242/luca-ferrari/python/ch-2.py | 51 |
2 files changed, 96 insertions, 0 deletions
diff --git a/challenge-242/luca-ferrari/python/ch-1.py b/challenge-242/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..0b5a70cf7c --- /dev/null +++ b/challenge-242/luca-ferrari/python/ch-1.py @@ -0,0 +1,45 @@ +#!python + +# +# Perl Weekly Challenge 242 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-242/> +# + +import sys + +# task implementation +def main( argv ): + left = [] + right = [] + is_left = True + for current in argv: + if current != '|': + if ( is_left ): + left.append( int( current ) ) + else: + right.append( int( current ) ) + else: + is_left = False + + missing_left = [] + missing_right = [] + + for current in left: + if not current in right: + missing_left.append( current ) + + for current in right: + if not current in left: + missing_right.append( current ) + + print( ",".join( map( str, missing_left ) ) ) + print( ",".join( map( str, missing_right ) ) ) + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + diff --git a/challenge-242/luca-ferrari/python/ch-2.py b/challenge-242/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..12778d1821 --- /dev/null +++ b/challenge-242/luca-ferrari/python/ch-2.py @@ -0,0 +1,51 @@ +#!python + +# +# Perl Weekly Challenge 242 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-242/> +# +# $ python3 ch-2.py 1 0 0 '|' 0 0 1 '|' 1 1 1 +# 1,1,0 +# 0,1,1 +# 0,0,0 + + +import sys + + + +# task implementation +def main( argv ): + matrix = [] + current_row = 0 + + matrix.append( [] ) + for current in argv: + if current != '|': + matrix[ current_row ].append( int( current ) ) + else: + current_row += 1 + matrix.append( [] ) + + # inner function to use with map + # returns a string to make join happy! + def task2(n): + if n == 1: + return "0" + else: + return "1" + + + for current_row in matrix: + print( ",".join( map( task2, reversed( current_row ) ) ) ) + + + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + |
