aboutsummaryrefslogtreecommitdiff
path: root/challenge-333/luca-ferrari/python/ch-1.py
blob: 7f647fdbec8a7fb4d8495debb3bc030ae8f3ee51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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: ] ) )