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
47
48
49
|
#!python
#
# Perl Weekly Challenge 253
# Task 2
#
# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-253>
#
import sys
import collections
# task implementation
# the return value will be printed
def task_2( args ):
ones = {}
for row_index in range( 0, len( args ) ):
sum = 0
for x in args[ row_index ]:
sum += x
if not sum in ones:
ones[ str( sum ) ] = []
ones[ str( sum ) ].append( row_index )
keys = list( ones.keys() )
keys.sort()
result = ""
for k in keys:
ones[ k ].sort()
for v in ones[ k ]:
result += str( v ) + ','
return result
# invoke the main without the command itself
if __name__ == '__main__':
matrix = [
[1, 1, 0, 0, 0],
[1, 1, 1, 1, 0],
[1, 0, 0, 0, 0],
[1, 1, 0, 0, 0],
[1, 1, 1, 1, 1]
]
print( task_2( matrix ) )
|