diff options
Diffstat (limited to 'challenge-266/luca-ferrari/python')
| -rw-r--r-- | challenge-266/luca-ferrari/python/ch-1.py | 52 | ||||
| -rw-r--r-- | challenge-266/luca-ferrari/python/ch-2.py | 35 |
2 files changed, 87 insertions, 0 deletions
diff --git a/challenge-266/luca-ferrari/python/ch-1.py b/challenge-266/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..3d5f542714 --- /dev/null +++ b/challenge-266/luca-ferrari/python/ch-1.py @@ -0,0 +1,52 @@ +#!python + +# +# Perl Weekly Challenge 266 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266> +# + +import sys + +# task implementation +# the return value will be printed +def task_1( args ): + left = args[ 0 ] + right = args[ 1 ] + + bag_left = {} + bag_right = {} + + # classify + for w in left.split(): + c = 1 + w = w.lower() + if w in bag_left: + c += bag_left[ w ] + + bag_left[ w ] = c + + for w in right.split(): + c = 1 + w = w.lower() + if w in bag_right: + c += bag_right[ w ] + + bag_right[ w ] = c + + words = [] + for w in bag_left: + if bag_left[ w ] == 1 and not w in bag_right: + words.append( w ) + + for w in bag_right: + if bag_right[ w ] == 1 and not w in bag_left: + words.append( w ) + + return words + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-266/luca-ferrari/python/ch-2.py b/challenge-266/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..7b5ce0d896 --- /dev/null +++ b/challenge-266/luca-ferrari/python/ch-2.py @@ -0,0 +1,35 @@ +#!python + +# +# Perl Weekly Challenge 266 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-266> +# + +import sys + +# task implementation +# the return value will be printed +def task_2( matrix ): + size = len( matrix[ 0 ] ) + for row in range( 0, size ): + for col in range( 0, size ): + if row == col or col == size - row - 1: + if matrix[ row ][ col ] == 0: + return 'False' + elif matrix[ row ][ col ] != 0: + return 'False' + return 'True' + + + +# invoke the main without the command itself +if __name__ == '__main__': + matrix = [ + [1, 0, 0, 2], + [0, 3, 4, 0], + [0, 5, 6, 0], + [7, 0, 0, 1], + ] + print( task_2( matrix ) ) |
