aboutsummaryrefslogtreecommitdiff
path: root/challenge-253/luca-ferrari/python/ch-2.python
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2024-01-22 08:54:32 +0100
committerLuca Ferrari <fluca1978@gmail.com>2024-01-22 13:21:10 +0100
commit52e2018af75d08a9b77b8e3bb56a7b2fffc6f42b (patch)
tree63b205906393dabcfbf3422ee6dc8ae48a3a61e7 /challenge-253/luca-ferrari/python/ch-2.python
parent9d7dc816f7775abfee7d90f0a2a969611902be54 (diff)
downloadperlweeklychallenge-club-52e2018af75d08a9b77b8e3bb56a7b2fffc6f42b.tar.gz
perlweeklychallenge-club-52e2018af75d08a9b77b8e3bb56a7b2fffc6f42b.tar.bz2
perlweeklychallenge-club-52e2018af75d08a9b77b8e3bb56a7b2fffc6f42b.zip
PWC 253
Task 1 Raku done Task 2 Raku done Task 1 PL/Perl done Task 2 PL/Perl done Task 1 PL/PgSQL done Task 2 PL/PgSQL done Task 1 Python done Task 2 Python done Task 1 PL/Java done Task 2 PL/Java done
Diffstat (limited to 'challenge-253/luca-ferrari/python/ch-2.python')
-rw-r--r--challenge-253/luca-ferrari/python/ch-2.python49
1 files changed, 49 insertions, 0 deletions
diff --git a/challenge-253/luca-ferrari/python/ch-2.python b/challenge-253/luca-ferrari/python/ch-2.python
new file mode 100644
index 0000000000..2e4abff0e5
--- /dev/null
+++ b/challenge-253/luca-ferrari/python/ch-2.python
@@ -0,0 +1,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 ) )