aboutsummaryrefslogtreecommitdiff
path: root/challenge-270/luca-ferrari/python/ch-1.py
blob: bb4786c9bbbb17397deed27ae8cddc39f253c9b1 (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
45
46
#!python

#
# Perl Weekly Challenge 270
# Task 1
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-270>
#

import sys

# task implementation
# the return value will be printed
def task_1( args ):
    row_size = int( args[ 0 ] )
    matrix   = []

    # build the matrix
    current_row = 0
    matrix.append( [] )
    for x in args[ 1: ]:

        if len( matrix[ current_row ] ) >= row_size:
            current_row += 1
            matrix.append( [] )

        matrix[ current_row ].append( int( x ) )


    ones = []
    for r in range( 0, len( matrix ) ):
        for c in range( 0, len( matrix[ r ] ) ):
            if matrix[ r ][ c ] == 1:
                ones.append( [ r, c ] )

    for current in ones:
        found = list( filter( lambda x: x[ 0 ] == current[ 0 ] or x[ 1 ] == current[ 1 ], ones ) )
        if len( found ) == 1:
            print( current )


    return ""

# invoke the main without the command itself
if __name__ == '__main__':
    print( task_1( sys.argv[ 1: ] ) )