diff options
| author | Luca Ferrari <fluca1978@gmail.com> | 2024-01-15 09:12:38 +0100 |
|---|---|---|
| committer | Luca Ferrari <fluca1978@gmail.com> | 2024-01-15 12:34:18 +0100 |
| commit | 65a2d0d671dfe4c0ce3e2664b6ac7abce8f0856c (patch) | |
| tree | 2b33fc29d14d8bc21b85fd0c2f77bb6589e094b3 /challenge-252/luca-ferrari/python | |
| parent | 7efb373bb9adffa79f84825217015835805298b5 (diff) | |
| download | perlweeklychallenge-club-65a2d0d671dfe4c0ce3e2664b6ac7abce8f0856c.tar.gz perlweeklychallenge-club-65a2d0d671dfe4c0ce3e2664b6ac7abce8f0856c.tar.bz2 perlweeklychallenge-club-65a2d0d671dfe4c0ce3e2664b6ac7abce8f0856c.zip | |
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
Diffstat (limited to 'challenge-252/luca-ferrari/python')
| -rw-r--r-- | challenge-252/luca-ferrari/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-252/luca-ferrari/python/ch-2.py | 39 |
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: ] ) ) + |
