From 65a2d0d671dfe4c0ce3e2664b6ac7abce8f0856c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 15 Jan 2024 09:12:38 +0100 Subject: PWC 252 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 Java done Task 2 Java done --- challenge-252/luca-ferrari/python/ch-1.py | 27 +++++++++++++++++++++ challenge-252/luca-ferrari/python/ch-2.py | 39 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 challenge-252/luca-ferrari/python/ch-1.py create mode 100644 challenge-252/luca-ferrari/python/ch-2.py (limited to 'challenge-252/luca-ferrari/python') 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 +# + +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 +# + +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: ] ) ) + -- cgit