aboutsummaryrefslogtreecommitdiff
path: root/challenge-329/luca-ferrari/python
diff options
context:
space:
mode:
authorLuca Ferrari <fluca1978@gmail.com>2025-07-10 12:38:23 +0200
committerLuca Ferrari <fluca1978@gmail.com>2025-07-10 14:26:28 +0200
commit4bdf01fc828095304e3d85ddd3c2af8d2e7ade08 (patch)
treeaeb2de9c23a0e6c0dfeeee86805e480c80c319ac /challenge-329/luca-ferrari/python
parent6a1bc860b02b7d2b0b1806cb9aa6a1e00a2d966e (diff)
downloadperlweeklychallenge-club-4bdf01fc828095304e3d85ddd3c2af8d2e7ade08.tar.gz
perlweeklychallenge-club-4bdf01fc828095304e3d85ddd3c2af8d2e7ade08.tar.bz2
perlweeklychallenge-club-4bdf01fc828095304e3d85ddd3c2af8d2e7ade08.zip
PWC 329
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 PL/Java done Task 2 PL/Java done Task 1 Python done Task 2 Python done
Diffstat (limited to 'challenge-329/luca-ferrari/python')
-rw-r--r--challenge-329/luca-ferrari/python/ch-1.py28
-rw-r--r--challenge-329/luca-ferrari/python/ch-2.py38
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-329/luca-ferrari/python/ch-1.py b/challenge-329/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..41d2e6a1d8
--- /dev/null
+++ b/challenge-329/luca-ferrari/python/ch-1.py
@@ -0,0 +1,28 @@
+#!python
+
+#
+# Perl Weekly Challenge 329
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-329>
+#
+
+import sys
+import re
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ string = args[ 0 ]
+
+ numbers = []
+ pattern = re.compile( r'\d+' )
+ for i in pattern.findall( string ) :
+ if not i in numbers :
+ numbers.append( i )
+
+ return numbers
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )
diff --git a/challenge-329/luca-ferrari/python/ch-2.py b/challenge-329/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..bdfc275a82
--- /dev/null
+++ b/challenge-329/luca-ferrari/python/ch-2.py
@@ -0,0 +1,38 @@
+#!python
+
+#
+# Perl Weekly Challenge 329
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-329>
+#
+
+import sys
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ string = args[ 0 ]
+
+ begin = 0
+ end = 0
+
+ for i in range( 0, len( string ) - 1 ) :
+ current = string[ i ]
+ needle = current.upper()
+ if current.isupper() :
+ needle = current.lower()
+
+ for j in range( i + 1, len( string ) ) :
+ print( " => ", string[ j ] )
+ if string[ j ] == needle :
+ if ( end - begin ) < ( j - i ) :
+ begin = i
+ end = j
+
+ return string[ begin : end + 1 ]
+
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )