diff options
21 files changed, 339 insertions, 3 deletions
diff --git a/challenge-330/luca-ferrari/blog-1.txt b/challenge-330/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..9877d42a99 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task1 diff --git a/challenge-330/luca-ferrari/blog-10.txt b/challenge-330/luca-ferrari/blog-10.txt new file mode 100644 index 0000000000..f8db258dd8 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-10.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task2pljava diff --git a/challenge-330/luca-ferrari/blog-2.txt b/challenge-330/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..95e0f38722 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task2 diff --git a/challenge-330/luca-ferrari/blog-3.txt b/challenge-330/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..5f4c147494 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task1plperl diff --git a/challenge-330/luca-ferrari/blog-4.txt b/challenge-330/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..afa2ec9ff8 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task2plperl diff --git a/challenge-330/luca-ferrari/blog-5.txt b/challenge-330/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..8e7d69f9ad --- /dev/null +++ b/challenge-330/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task1plpgsql diff --git a/challenge-330/luca-ferrari/blog-6.txt b/challenge-330/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..be7d5f4814 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task2plpgsql diff --git a/challenge-330/luca-ferrari/blog-7.txt b/challenge-330/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..c57b38e73f --- /dev/null +++ b/challenge-330/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task1python diff --git a/challenge-330/luca-ferrari/blog-8.txt b/challenge-330/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..0329b90f34 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task2python diff --git a/challenge-330/luca-ferrari/blog-9.txt b/challenge-330/luca-ferrari/blog-9.txt new file mode 100644 index 0000000000..23e0e0e7a7 --- /dev/null +++ b/challenge-330/luca-ferrari/blog-9.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2025/07/14/PerlWeeklyChallenge330.html#task1pljava diff --git a/challenge-330/luca-ferrari/pljava/pom.xml b/challenge-330/luca-ferrari/pljava/pom.xml index 1397948409..a5e9d8f5ff 100644 --- a/challenge-330/luca-ferrari/pljava/pom.xml +++ b/challenge-330/luca-ferrari/pljava/pom.xml @@ -7,14 +7,14 @@ <groupId>PWC</groupId> <artifactId> - PWC329 + PWC330 </artifactId> <version> 1 </version> - <name>Perl Weekly Challenge 329 with package PWC329</name> - <description>Implementation of the tasks in PL/Java for PWC 329</description> + <name>Perl Weekly Challenge 330 with package PWC330</name> + <description>Implementation of the tasks in PL/Java for PWC 330</description> <properties> <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding> diff --git a/challenge-330/luca-ferrari/pljava/src/main/java/Task1.java b/challenge-330/luca-ferrari/pljava/src/main/java/Task1.java new file mode 100644 index 0000000000..9de6bbcdac --- /dev/null +++ b/challenge-330/luca-ferrari/pljava/src/main/java/Task1.java @@ -0,0 +1,66 @@ + + + +package PWC330; + +/** + * PL/Java implementation for PWC 330 + * Task 1 + * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC330-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC330-1.jar', 'PWC330', true ); + select sqlj.set_classpath( 'public', 'PWC330' ); + + select pwc330.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC330-1.jar', 'PWC330', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.util.stream.*; +import java.sql.SQLException; +import java.util.logging.*; +import java.sql.ResultSet; +import java.sql.Date; +import java.util.regex.*; + +public class Task1 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( schema = "pwc330", + onNullInput = RETURNS_NULL, + effects = IMMUTABLE ) + public static final String task1_pljava( String string ) throws SQLException { + logger.log( Level.INFO, "Entering pwc330.task1_pljava" ); + + Pattern regexp = Pattern.compile( "([a-z])([0-9])" ); + Matcher engine = regexp.matcher( string ); + + while ( engine.find() ) { + string = string.replaceAll( engine.group( 1 ) + engine.group( 2 ), "" ); + engine = regexp.matcher( string ); + } + + return string; + + } +} diff --git a/challenge-330/luca-ferrari/pljava/src/main/java/Task2.java b/challenge-330/luca-ferrari/pljava/src/main/java/Task2.java new file mode 100644 index 0000000000..7d6431ce4c --- /dev/null +++ b/challenge-330/luca-ferrari/pljava/src/main/java/Task2.java @@ -0,0 +1,64 @@ + + + +package PWC330; + +/** + * PL/Java implementation for PWC 330 + * Task 2 + * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> + * + * + * To compile on the local machine: + + $ export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64/ # if not already set + $ mvn clean build + $ scp target/PWC330-1.jar luca@rachel:/tmp + + + * To install into PostgreSQL execute: + + select sqlj.install_jar( 'file:///tmp/PWC330-1.jar', 'PWC330', true ); + select sqlj.set_classpath( 'public', 'PWC330' ); + + select pwc330.task2_pljava(); + + and then to redeploy: + + select sqlj.replace_jar( 'file:///tmp/PWC330-1.jar', 'PWC330', true ); + +*/ + +import org.postgresql.pljava.*; +import org.postgresql.pljava.annotation.Function; +import static org.postgresql.pljava.annotation.Function.Effects.IMMUTABLE; +import static org.postgresql.pljava.annotation.Function.OnNullInput.RETURNS_NULL; + +import java.util.*; +import java.util.stream.*; +import java.sql.SQLException; +import java.util.logging.*; +import java.sql.ResultSet; +import java.sql.Date; +import java.util.regex.*; + +public class Task2 { + + private final static Logger logger = Logger.getAnonymousLogger(); + + @Function( schema = "pwc330", + onNullInput = RETURNS_NULL, + effects = IMMUTABLE ) + public static final String task2_pljava( String string ) throws SQLException { + logger.log( Level.INFO, "Entering pwc330.task2_pljava" ); + + + return Arrays + .stream( string.split( " " ) ) + .map( word -> word.length() <= 2 + ? word.toLowerCase() + : Character.toTitleCase( word.charAt(0) ) + word.substring( 1 ).toLowerCase() ) + .collect( Collectors.joining( " " ) ); + + } +} diff --git a/challenge-330/luca-ferrari/plperl/ch-1.plperl b/challenge-330/luca-ferrari/plperl/ch-1.plperl new file mode 100644 index 0000000000..ea750eb263 --- /dev/null +++ b/challenge-330/luca-ferrari/plperl/ch-1.plperl @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 330 +-- Task 1 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +-- + +CREATE SCHEMA IF NOT EXISTS pwc330; + +CREATE OR REPLACE FUNCTION +pwc330.task1_plperl( text ) +RETURNS text +AS $CODE$ + + my ( $string ) = @_; + die "Invalid string" unless( $string =~ / ^ [a-z0-9]+ $ /x ); + + while ( $string =~ / [a-z] [0-9] /x ) { + $string =~ s/ ([a-z]) ([0-9]) //x; + } + return $string; + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-330/luca-ferrari/plperl/ch-2.plperl b/challenge-330/luca-ferrari/plperl/ch-2.plperl new file mode 100644 index 0000000000..0930a6c748 --- /dev/null +++ b/challenge-330/luca-ferrari/plperl/ch-2.plperl @@ -0,0 +1,26 @@ +-- +-- Perl Weekly Challenge 330 +-- Task 2 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +-- + +CREATE SCHEMA IF NOT EXISTS pwc330; + +CREATE OR REPLACE FUNCTION +pwc330.task2_plperl( text ) +RETURNS text +AS $CODE$ + + my ( $text ) = @_; + die "Invalid argument" unless( length( $text ) > 2 ); + + my @parts; + + for ( split( ' ', $text ) ) { + push @parts, length( $_ ) >= 3 ? ucfirst( $_ ) : lc( $_ ); + } + + return join( ' ', @parts ); + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-330/luca-ferrari/plpgsql/ch-1.sql b/challenge-330/luca-ferrari/plpgsql/ch-1.sql new file mode 100644 index 0000000000..cabe422842 --- /dev/null +++ b/challenge-330/luca-ferrari/plpgsql/ch-1.sql @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 330 +-- Task 1 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +-- + +CREATE SCHEMA IF NOT EXISTS pwc330; + +CREATE OR REPLACE FUNCTION +pwc330.task1_plpgsql( s text ) +RETURNS text +AS $CODE$ +DECLARE + +BEGIN + WHILE regexp_match( s, '[a-z][0-9]' ) IS NOT NULL LOOP + s := regexp_replace( s, '([a-z])([0-9])', '' ); + END LOOP; + + RETURN s; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-330/luca-ferrari/plpgsql/ch-2.sql b/challenge-330/luca-ferrari/plpgsql/ch-2.sql new file mode 100644 index 0000000000..58ac1de379 --- /dev/null +++ b/challenge-330/luca-ferrari/plpgsql/ch-2.sql @@ -0,0 +1,30 @@ +-- +-- Perl Weekly Challenge 330 +-- Task 2 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +-- + +CREATE SCHEMA IF NOT EXISTS pwc330; + +CREATE OR REPLACE FUNCTION +pwc330.task2_plpgsql( s text ) +RETURNS SETOF text +AS $CODE$ +DECLARE + current text; +BEGIN + FOR current IN SELECT v FROM regexp_split_to_table( s, ' ' ) v LOOP + IF length( current ) >= 3 THEN + current := upper( current ); + ELSE + current := lower( current ); + END IF; + + RETURN NEXT current; + END LOOP; + +RETURN; + +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-330/luca-ferrari/python/ch-1.py b/challenge-330/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..9829e5b6f1 --- /dev/null +++ b/challenge-330/luca-ferrari/python/ch-1.py @@ -0,0 +1,28 @@ +#!python + +# +# Perl Weekly Challenge 330 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +# + +import sys +import re + +# task implementation +# the return value will be printed +def task_1( args ): + string = args[ 0 ] + + regexp = re.compile( r'[a-z][0-9]' ) + + + while regexp.search( string ) is not None: + string = re.sub( r'[a-z][0-9]', '', string ) + + return string + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_1( sys.argv[ 1: ] ) ) diff --git a/challenge-330/luca-ferrari/python/ch-2.py b/challenge-330/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..23f26726b5 --- /dev/null +++ b/challenge-330/luca-ferrari/python/ch-2.py @@ -0,0 +1,31 @@ +#!python + +# +# Perl Weekly Challenge 330 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +# + +import sys + +# task implementation +# the return value will be printed +def task_2( args ): + parts = [] + + for current in args : + if len( current ) >= 3 : + current = current.title() + else: + current = current.lower() + + parts.append( current ) + + return ' '.join( parts ) + + + +# invoke the main without the command itself +if __name__ == '__main__': + print( task_2( sys.argv[ 1: ] ) ) diff --git a/challenge-330/luca-ferrari/raku/ch-1.raku b/challenge-330/luca-ferrari/raku/ch-1.raku new file mode 100644 index 0000000000..720b39e996 --- /dev/null +++ b/challenge-330/luca-ferrari/raku/ch-1.raku @@ -0,0 +1,18 @@ +#!raku + +# +# Perl Weekly Challenge 330 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +# + +sub MAIN( Str $string is copy + where { $string ~~ / ^ <[a .. z 0 .. 9 ]>+ $ / } ) { + + while ( $string ~~ / (<[a .. z]>) (<[ 0 .. 9 ]>) / ) { + $string .= subst( / (<[a .. z]>) (<[ 0 .. 9 ]>) /, '' ); + } + + $string.say; +} diff --git a/challenge-330/luca-ferrari/raku/ch-2.raku b/challenge-330/luca-ferrari/raku/ch-2.raku new file mode 100644 index 0000000000..adacf9065d --- /dev/null +++ b/challenge-330/luca-ferrari/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!raku + +# +# Perl Weekly Challenge 330 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-330> +# + +sub MAIN( Str $sentence is copy ) { + my @parts; + for $sentence.split( ' ' ) { + @parts.push: $_.Str.chars >= 3 ?? $_.tc !! $_.lc; + } + + @parts.join( ' ' ).say; +} |
