diff options
Diffstat (limited to 'challenge-333/luca-ferrari/python/ch-1.py')
| -rw-r--r-- | challenge-333/luca-ferrari/python/ch-1.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/challenge-333/luca-ferrari/python/ch-1.py b/challenge-333/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..7f647fdbec --- /dev/null +++ b/challenge-333/luca-ferrari/python/ch-1.py @@ -0,0 +1,44 @@ +#!python + +# +# Perl Weekly Challenge 333 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-333> +# + +import sys + +# task implementation +# the return value will be printed +def task_1( args ): + coords = [] + for i in range( 0, len( args ) - 1 ): + if i % 2 != 0: + continue + + x = int( args[ i ] ) + y = int( args[ i + 1 ] ) + + current = {} + current[ 'x' ] = x + current[ 'y' ] = y + + coords.append( current ) + + first = coords[ 0 ] + second = coords[ 1 ] + + + for i in range( 2, len( coords ) ): + current = coords[ i ] + if ( ( current[ 'x' ] - first[ 'x' ] ) * ( first[ 'y' ] - second[ 'y' ] ) ) != ( ( current[ 'y' ] - second[ 'y' ] ) * ( first[ 'x' ] - second[ 'x' ] ) ): + return False + + return True + + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) |
