aboutsummaryrefslogtreecommitdiff
path: root/challenge-261/luca-ferrari/python
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2024-03-19 22:04:16 +0100
committerLuca Ferrari <fluca1978@gmail.com>2024-03-20 17:36:10 +0100
commitea04e6cf64f251e8f44356166c055ece51be7aa5 (patch)
tree4bf0b0d3316ad9a9342d31bab44afe8e9dddcbb6 /challenge-261/luca-ferrari/python
parent5395f01802fbf21afed5c5e25a44e46361431be1 (diff)
downloadperlweeklychallenge-club-ea04e6cf64f251e8f44356166c055ece51be7aa5.tar.gz
perlweeklychallenge-club-ea04e6cf64f251e8f44356166c055ece51be7aa5.tar.bz2
perlweeklychallenge-club-ea04e6cf64f251e8f44356166c055ece51be7aa5.zip
PWC 261
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-261/luca-ferrari/python')
-rw-r--r--challenge-261/luca-ferrari/python/ch-1.py30
-rw-r--r--challenge-261/luca-ferrari/python/ch-2.py25
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-261/luca-ferrari/python/ch-1.py b/challenge-261/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..5e1927a010
--- /dev/null
+++ b/challenge-261/luca-ferrari/python/ch-1.py
@@ -0,0 +1,30 @@
+#!python
+
+#
+# Perl Weekly Challenge 261
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-261>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ sum_numbers = sum( list( map( int, args ) ) )
+ sum_digits = 0
+ for num in args:
+ for d in num:
+ sum_digits += int( d )
+
+ result = sum_numbers - sum_digits
+ if result < 0:
+ return result * -1
+
+ return result
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )
diff --git a/challenge-261/luca-ferrari/python/ch-2.py b/challenge-261/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..a9e1b1472d
--- /dev/null
+++ b/challenge-261/luca-ferrari/python/ch-2.py
@@ -0,0 +1,25 @@
+#!python
+
+#
+# Perl Weekly Challenge 261
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-261>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ start = int( args[ 0 ] )
+ nums = args[ 1: ]
+ while len( list( filter( lambda x: x == str( start ), nums ) ) ) > 0:
+ start *= 2
+
+ return start
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )