diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-11-20 15:40:49 +0800 |
| commit | 72dc5412e640e26601ffdebc4f0247db4c4bc7fe (patch) | |
| tree | d405aa98925dfed0b745e5ec331e9498005b1de7 /challenge-243/luca-ferrari/python | |
| parent | 35d79358f3d12607da66ffefefed5e93c469d396 (diff) | |
| parent | fda51162ad0e1e8b4489fd2c73ef7dfdc8f0df5e (diff) | |
| download | perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.gz perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.tar.bz2 perlweeklychallenge-club-72dc5412e640e26601ffdebc4f0247db4c4bc7fe.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-243/luca-ferrari/python')
| -rw-r--r-- | challenge-243/luca-ferrari/python/ch-1.py | 29 | ||||
| -rw-r--r-- | challenge-243/luca-ferrari/python/ch-2.py | 28 |
2 files changed, 57 insertions, 0 deletions
diff --git a/challenge-243/luca-ferrari/python/ch-1.py b/challenge-243/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..559582ffa4 --- /dev/null +++ b/challenge-243/luca-ferrari/python/ch-1.py @@ -0,0 +1,29 @@ +#!python + +# +# Perl Weekly Challenge 243 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-243/> +# + +import sys + +# task implementation +def main( argv ): + nums = list( map( int, argv ) ) + counter = 0 + + for i in range( 0, len( nums ) ): + for j in range( i + 1, len( nums ) ): + if nums[ i ] > 2 * nums[ j ]: + counter = counter + 1; + + print( counter ) + + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + diff --git a/challenge-243/luca-ferrari/python/ch-2.py b/challenge-243/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..0e5f2c5863 --- /dev/null +++ b/challenge-243/luca-ferrari/python/ch-2.py @@ -0,0 +1,28 @@ +#!python + +# +# Perl Weekly Challenge 243 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-243/> +# + +import sys +from functools import reduce + +# task implementation +def main( argv ): + nums = list( map( int, argv ) ) + sum = 0 + + + for current in nums: + sum = sum + reduce( lambda a,b: a + b, list( map( lambda x: int( current /x ), nums ) ) ) + + print( sum ) + +# invoke the main without the command itself +if __name__ == '__main__': + main( sys.argv[ 1: ] ) + + |
