aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/luca-ferrari/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-252/luca-ferrari/python')
-rw-r--r--challenge-252/luca-ferrari/python/ch-1.py27
-rw-r--r--challenge-252/luca-ferrari/python/ch-2.py39
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-252/luca-ferrari/python/ch-1.py b/challenge-252/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..cae2cc2c1c
--- /dev/null
+++ b/challenge-252/luca-ferrari/python/ch-1.py
@@ -0,0 +1,27 @@
+#!python
+
+#
+# Perl Weekly Challenge 252
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-252/>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def main( argv ):
+ nums = list( map( int, argv ) )
+ sum = 0
+ for i in range( 0, len( nums ) ):
+ if len( nums ) % ( i + 1 ) == 0:
+ sum += nums[ i ] ** 2;
+
+ return sum
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( main( sys.argv[ 1: ] ) )
+
diff --git a/challenge-252/luca-ferrari/python/ch-2.py b/challenge-252/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..4862800e92
--- /dev/null
+++ b/challenge-252/luca-ferrari/python/ch-2.py
@@ -0,0 +1,39 @@
+#!python
+
+#
+# Perl Weekly Challenge 252
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-252/>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def main( argv ):
+ size = int( argv[ 0 ] )
+ nums = []
+
+ if size % 2 == 0:
+ for i in range( 1, size / 2 ):
+ nums.append( i )
+ nums.append( i * -1 )
+ else:
+ for i in range( 1, int( ( size - 1 ) / 2 ) ):
+ nums.append( i )
+ nums.append( i * -1 )
+
+ next = max( nums ) + 1
+ nums.append( next )
+ nums.append( next + 1 )
+ nums.append( ( next + next + 1 ) * -1 )
+
+ return nums
+
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( main( sys.argv[ 1: ] ) )
+