From 080fde56fb9825f48e63c97840234fbde25fedaa Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 8 Jan 2024 10:17:22 +0100 Subject: PWC 251 Task 1 Raku done Task 2 Raku done Task 1 PL/Perl done Task 2 PL/perl done Task 1 PL/PgSQL done Task 2 PL/PgSQL done Task 1 Python done Task 2 Python done --- challenge-251/luca-ferrari/python/ch-1.py | 25 +++++++++++++ challenge-251/luca-ferrari/python/ch-2.py | 59 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 challenge-251/luca-ferrari/python/ch-1.py create mode 100644 challenge-251/luca-ferrari/python/ch-2.py (limited to 'challenge-251/luca-ferrari/python') diff --git a/challenge-251/luca-ferrari/python/ch-1.py b/challenge-251/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..e72f979066 --- /dev/null +++ b/challenge-251/luca-ferrari/python/ch-1.py @@ -0,0 +1,25 @@ +#!python + +# +# Perl Weekly Challenge 251 +# Task 1 +# +# See +# + +import sys + +# task implementation +def main( argv ): + sum = 0 + for i in range( 0, len( argv ) - 1 ): + if i % 2 != 0: + continue + sum += int( argv[ i ] + argv[ i + 1 ] ) + + return sum + + +# invoke the main without the command itself +if __name__ == '__main__': + print( main( sys.argv[ 1: ] ) ) diff --git a/challenge-251/luca-ferrari/python/ch-2.py b/challenge-251/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..a06c706b28 --- /dev/null +++ b/challenge-251/luca-ferrari/python/ch-2.py @@ -0,0 +1,59 @@ +#!python + +# +# Perl Weekly Challenge 251 +# Task 2 +# +# See +# + +import sys + +# task implementation +def main( argv ): + matrix = [] + row = 0 + matrix.append( [] ) + + for x in argv[ 0 ]: + if x == ' ': + continue + + # change row + if x == '|': + row += 1 + matrix.append( [] ) + continue + + matrix[ row ].append( int( x ) ) + + # make indexes of max columns + max_cols = [] + for col in range( 0, len( matrix ) ): + current_max = None + for row in range( 0, len( matrix[ 0 ] ) ): + if not current_max or current_max < matrix[ row ][ col ] : + current_max = matrix[ row ][ col ] + + max_cols.append( current_max ) + + for row in range( 0, len( matrix ) ): + current_min = None + current_min_col = None + + for col in range( 0, len( matrix[ row ] ) ): + if not current_min or current_min > matrix[ row ][ col ]: + current_min = matrix[ row ][ col ] + current_min_col = col + + if current_min == max_cols[ current_min_col ]: + return current_min + + return -1 + + + + +# invoke the main without the command itself +if __name__ == '__main__': + print( main( sys.argv[ 1: ] ) ) -- cgit