aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-20 21:42:31 +0100
committerGitHub <noreply@github.com>2024-09-20 21:42:31 +0100
commitf61718cb98344348e8fdc9ac0c88a9197f716581 (patch)
tree92db8441ac3ef403bc8571be9b6a1f7669ed71fd
parent9f64c025e5477b6ef8ad11def6dcc127dff8db29 (diff)
parentab26905beb70d890b8e43bbb1ae0e06a00a22491 (diff)
downloadperlweeklychallenge-club-f61718cb98344348e8fdc9ac0c88a9197f716581.tar.gz
perlweeklychallenge-club-f61718cb98344348e8fdc9ac0c88a9197f716581.tar.bz2
perlweeklychallenge-club-f61718cb98344348e8fdc9ac0c88a9197f716581.zip
Merge pull request #10878 from fluca1978/PWC287
PWC 287
-rw-r--r--challenge-287/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-10.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-7.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-8.txt1
-rw-r--r--challenge-287/luca-ferrari/blog-9.txt1
-rw-r--r--challenge-287/luca-ferrari/pljava/pom.xml72
-rw-r--r--challenge-287/luca-ferrari/pljava/src/main/java/Task1.java67
-rw-r--r--challenge-287/luca-ferrari/pljava/src/main/java/Task2.java58
-rw-r--r--challenge-287/luca-ferrari/plperl/ch-1.plperl24
-rw-r--r--challenge-287/luca-ferrari/plperl/ch-2.plperl20
-rw-r--r--challenge-287/luca-ferrari/plpgsql/ch-1.sql58
-rw-r--r--challenge-287/luca-ferrari/plpgsql/ch-2.sql28
-rw-r--r--challenge-287/luca-ferrari/python/ch-1.py25
-rw-r--r--challenge-287/luca-ferrari/python/ch-2.py22
-rw-r--r--challenge-287/luca-ferrari/raku/ch-1.raku26
-rw-r--r--challenge-287/luca-ferrari/raku/ch-2.raku18
21 files changed, 428 insertions, 0 deletions
diff --git a/challenge-287/luca-ferrari/blog-1.txt b/challenge-287/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..177d8ad1bb
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task1
diff --git a/challenge-287/luca-ferrari/blog-10.txt b/challenge-287/luca-ferrari/blog-10.txt
new file mode 100644
index 0000000000..9045d03914
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-10.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task2pljava
diff --git a/challenge-287/luca-ferrari/blog-2.txt b/challenge-287/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..62ef4b21a1
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task2
diff --git a/challenge-287/luca-ferrari/blog-3.txt b/challenge-287/luca-ferrari/blog-3.txt
new file mode 100644
index 0000000000..5e0da9daab
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-3.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task1plperl
diff --git a/challenge-287/luca-ferrari/blog-4.txt b/challenge-287/luca-ferrari/blog-4.txt
new file mode 100644
index 0000000000..935fd661a7
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-4.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task2plperl
diff --git a/challenge-287/luca-ferrari/blog-5.txt b/challenge-287/luca-ferrari/blog-5.txt
new file mode 100644
index 0000000000..79287d10a4
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-5.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task1plpgsql
diff --git a/challenge-287/luca-ferrari/blog-6.txt b/challenge-287/luca-ferrari/blog-6.txt
new file mode 100644
index 0000000000..48482f6491
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-6.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task2plpgsql
diff --git a/challenge-287/luca-ferrari/blog-7.txt b/challenge-287/luca-ferrari/blog-7.txt
new file mode 100644
index 0000000000..65e3ad7cd5
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-7.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task1python
diff --git a/challenge-287/luca-ferrari/blog-8.txt b/challenge-287/luca-ferrari/blog-8.txt
new file mode 100644
index 0000000000..fe1cb2f2bd
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-8.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task2python
diff --git a/challenge-287/luca-ferrari/blog-9.txt b/challenge-287/luca-ferrari/blog-9.txt
new file mode 100644
index 0000000000..4653f51056
--- /dev/null
+++ b/challenge-287/luca-ferrari/blog-9.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2024/09/20/PerlWeeklyChallenge287.html#task1pljava
diff --git a/challenge-287/luca-ferrari/pljava/pom.xml b/challenge-287/luca-ferrari/pljava/pom.xml
new file mode 100644
index 0000000000..47fa2f66a2
--- /dev/null
+++ b/challenge-287/luca-ferrari/pljava/pom.xml
@@ -0,0 +1,72 @@
+
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>PWC</groupId>
+ <artifactId>
+ PWC287
+ </artifactId>
+ <version>
+ 1
+ </version>
+
+ <name>Perl Weekly Challenge 287 with package PWC287</name>
+ <description>Implementation of the tasks in PL/Java for PWC 287</description>
+
+ <properties>
+ <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.postgresql</groupId>
+ <artifactId>pljava-api</artifactId>
+ <version>1.6.6</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <release>9</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.6</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <!-- This identifies and version-stamps the jar.
+ Not essential, but easy and useful. -->
+ <addDefaultImplementationEntries>
+ true
+ </addDefaultImplementationEntries>
+ </manifest>
+
+ <manifestSections>
+ <!-- This identifies a file in the jar named
+ pljava.ddr as an SQLJDeploymentDescriptor. -->
+ <manifestSection>
+ <name>pljava.ddr</name>
+ <manifestEntries>
+ <SQLJDeploymentDescriptor>
+ true
+ </SQLJDeploymentDescriptor>
+ </manifestEntries>
+ </manifestSection>
+ </manifestSections>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/challenge-287/luca-ferrari/pljava/src/main/java/Task1.java b/challenge-287/luca-ferrari/pljava/src/main/java/Task1.java
new file mode 100644
index 0000000000..8990641a74
--- /dev/null
+++ b/challenge-287/luca-ferrari/pljava/src/main/java/Task1.java
@@ -0,0 +1,67 @@
+
+
+
+package PWC287;
+
+/**
+ * PL/Java implementation for PWC 287
+ * Task 1
+ * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+ *
+ *
+ * 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/PWC287-1.jar luca@rachel:/tmp
+
+
+ * To install into PostgreSQL execute:
+
+ select sqlj.install_jar( 'file:///tmp/PWC287-1.jar', 'PWC287', true );
+ select sqlj.set_classpath( 'public', 'PWC287' );
+
+ select pwc287.task2_pljava();
+
+ and then to redeploy:
+
+ select sqlj.replace_jar( 'file:///tmp/PWC287-1.jar', 'PWC287', 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.Matcher;
+import java.util.regex.Pattern;
+
+public class Task1 {
+
+ private final static Logger logger = Logger.getAnonymousLogger();
+
+ @Function( schema = "pwc287",
+ onNullInput = RETURNS_NULL,
+ effects = IMMUTABLE )
+ public static final boolean task1_pljava( String password ) throws SQLException {
+ if ( password.length() < 6 )
+ return false;
+
+ Pattern lowerCase = Pattern.compile( "[a-z]" );
+ Pattern upperCase = Pattern.compile( "[A-Z]" );
+ Pattern digit = Pattern.compile( "[0-9]" );
+ Pattern repetitions = Pattern.compile( "(.)\\1\\1" );
+
+ return lowerCase.matcher( password ).find()
+ && upperCase.matcher( password ).find()
+ && digit.matcher( password ).find()
+ && ! repetitions.matcher( password ).find();
+ }
+}
diff --git a/challenge-287/luca-ferrari/pljava/src/main/java/Task2.java b/challenge-287/luca-ferrari/pljava/src/main/java/Task2.java
new file mode 100644
index 0000000000..0c3a926c16
--- /dev/null
+++ b/challenge-287/luca-ferrari/pljava/src/main/java/Task2.java
@@ -0,0 +1,58 @@
+
+
+
+package PWC287;
+
+/**
+ * PL/Java implementation for PWC 287
+ * Task 2
+ * See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+ *
+ *
+ * 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/PWC287-1.jar luca@rachel:/tmp
+
+
+ * To install into PostgreSQL execute:
+
+ select sqlj.install_jar( 'file:///tmp/PWC287-1.jar', 'PWC287', true );
+ select sqlj.set_classpath( 'public', 'PWC287' );
+
+ select pwc287.task2_pljava();
+
+ and then to redeploy:
+
+ select sqlj.replace_jar( 'file:///tmp/PWC287-1.jar', 'PWC287', 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.Matcher;
+import java.util.regex.Pattern;
+
+
+public class Task2 {
+
+ private final static Logger logger = Logger.getAnonymousLogger();
+
+ @Function( schema = "pwc287",
+ onNullInput = RETURNS_NULL,
+ effects = IMMUTABLE )
+ public static final boolean task2_pljava( String number ) throws SQLException {
+ Pattern numberRegexp = Pattern.compile( "^[+-]?\\d+([.]\\d+)?(E[+-]?\\d+)?$" );
+ return numberRegexp.matcher( number ).find();
+ }
+}
diff --git a/challenge-287/luca-ferrari/plperl/ch-1.plperl b/challenge-287/luca-ferrari/plperl/ch-1.plperl
new file mode 100644
index 0000000000..8b8395a7d7
--- /dev/null
+++ b/challenge-287/luca-ferrari/plperl/ch-1.plperl
@@ -0,0 +1,24 @@
+--
+-- Perl Weekly Challenge 287
+-- Task 1
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc287;
+
+CREATE OR REPLACE FUNCTION
+pwc287.task1_plperl( text )
+RETURNS bool
+AS $CODE$
+
+ my ( $password ) = @_;
+ return 0 if ( length( $password ) < 6 );
+ return 0 if ( $password !~ / [a-z] /x );
+ return 0 if ( $password !~ / [A-Z] /x );
+ return 0 if ( $password !~ / [0-9] /x );
+ return 0 if ( $password ~~ / (.)\1\1 /x );
+
+ return 1;
+
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-287/luca-ferrari/plperl/ch-2.plperl b/challenge-287/luca-ferrari/plperl/ch-2.plperl
new file mode 100644
index 0000000000..bd36941088
--- /dev/null
+++ b/challenge-287/luca-ferrari/plperl/ch-2.plperl
@@ -0,0 +1,20 @@
+--
+-- Perl Weekly Challenge 287
+-- Task 2
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc287;
+
+CREATE OR REPLACE FUNCTION
+pwc287.task2_plperl( text )
+RETURNS bool
+AS $CODE$
+
+ my ( $number ) = @_;
+
+ return 1 if ( $number =~ / ^ [+-]? \d+ (.\d+)? (E[+-]?\d+)? $/x );
+ return 0;
+
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-287/luca-ferrari/plpgsql/ch-1.sql b/challenge-287/luca-ferrari/plpgsql/ch-1.sql
new file mode 100644
index 0000000000..2df3b950cc
--- /dev/null
+++ b/challenge-287/luca-ferrari/plpgsql/ch-1.sql
@@ -0,0 +1,58 @@
+--
+-- Perl Weekly Challenge 287
+-- Task 1
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc287;
+
+CREATE OR REPLACE FUNCTION
+pwc287.task1_plpgsql( pwd text )
+RETURNS bool
+AS $CODE$
+DECLARE
+ counter int := 0;
+BEGIN
+
+ IF length( pwd ) < 6 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[a-z]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[A-Z]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '[0-9]', 'g' ) x;
+
+ IF counter <= 0 THEN
+ RETURN false;
+ END IF;
+
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( pwd, '(.)\1\1', 'g' ) x;
+
+ IF counter > 0 THEN
+ RETURN false;
+ END IF;
+
+
+ RETURN true;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-287/luca-ferrari/plpgsql/ch-2.sql b/challenge-287/luca-ferrari/plpgsql/ch-2.sql
new file mode 100644
index 0000000000..73ce87787d
--- /dev/null
+++ b/challenge-287/luca-ferrari/plpgsql/ch-2.sql
@@ -0,0 +1,28 @@
+--
+-- Perl Weekly Challenge 287
+-- Task 2
+-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+--
+
+CREATE SCHEMA IF NOT EXISTS pwc287;
+
+CREATE OR REPLACE FUNCTION
+pwc287.task2_plpgsql( n text )
+RETURNS bool
+AS $CODE$
+DECLARE
+ counter int := 0;
+BEGIN
+
+ SELECT count( x )
+ INTO counter
+ FROM regexp_matches( n, '^[+-]?\d+(.\d+)?(E[+-]?\d+)?$' ) x;
+
+ IF counter > 0 THEN
+ RETURN true;
+ ELSE
+ RETURN false;
+ END IF;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-287/luca-ferrari/python/ch-1.py b/challenge-287/luca-ferrari/python/ch-1.py
new file mode 100644
index 0000000000..2fbe66f7b9
--- /dev/null
+++ b/challenge-287/luca-ferrari/python/ch-1.py
@@ -0,0 +1,25 @@
+#!python
+
+#
+# Perl Weekly Challenge 287
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+#
+
+import sys
+import re
+
+# task implementation
+# the return value will be printed
+def task_1( args ):
+ password = args[ 0 ]
+ lc = re.compile( '[a-z]' )
+ uc = re.compile( '[A-Z]' )
+ dg = re.compile( '[0-9]' )
+ wrong = re.compile( '(.)\\1\\1' )
+ return lc.search( password ) and uc.search( password ) and dg.search( password ) and wrong.search( password ) is None
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_1( sys.argv[ 1: ] ) )
diff --git a/challenge-287/luca-ferrari/python/ch-2.py b/challenge-287/luca-ferrari/python/ch-2.py
new file mode 100644
index 0000000000..d76523ff39
--- /dev/null
+++ b/challenge-287/luca-ferrari/python/ch-2.py
@@ -0,0 +1,22 @@
+#!python
+
+#
+# Perl Weekly Challenge 287
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+#
+
+import sys
+import re
+
+# task implementation
+# the return value will be printed
+def task_2( args ):
+ number = args[ 0 ]
+ good = re.compile( '^[+-]?\\d+([.]\\d+)?(E[+-]?\\d+)?$' )
+ return good.match( number ) is not None
+
+# invoke the main without the command itself
+if __name__ == '__main__':
+ print( task_2( sys.argv[ 1: ] ) )
diff --git a/challenge-287/luca-ferrari/raku/ch-1.raku b/challenge-287/luca-ferrari/raku/ch-1.raku
new file mode 100644
index 0000000000..0fecbc01c3
--- /dev/null
+++ b/challenge-287/luca-ferrari/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!raku
+
+#
+# Perl Weekly Challenge 287
+# Task 1
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+#
+
+sub MAIN( Str :$password ) {
+# - It must have at least 6 characters.
+# - It must contains at least one lowercase letter, at least one upper case letter and at least one digit.
+ # - It shouldn't contain 3 repeating characters in a row.
+
+ my $ok = True;
+ 'Too short'.say and $ok = False if ( $password.chars < 6 );
+ 'At least one lowercase char'.say and $ok = False if ( $password !~~ / <[a .. z]> / );
+ 'At least one uppercase char'.say and $ok = False if ( $password !~~ / <[A .. Z]> / );
+ 'At least one digit char'.say and $ok = False if ( $password !~~ / <[0 .. 9]> / );
+ 'No three repetitions in a row'.say and $ok = False if ( $password ~~ / (<[a..zA..Z0..9]>)$0$0 / );
+
+
+ 'Strong enough'.say if ( $ok );
+ 'Weak!'.say if ( ! $ok );
+ exit( $ok ?? 0 !! 1 );
+}
diff --git a/challenge-287/luca-ferrari/raku/ch-2.raku b/challenge-287/luca-ferrari/raku/ch-2.raku
new file mode 100644
index 0000000000..458e0965ca
--- /dev/null
+++ b/challenge-287/luca-ferrari/raku/ch-2.raku
@@ -0,0 +1,18 @@
+#!raku
+
+#
+# Perl Weekly Challenge 287
+# Task 2
+#
+# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-287>
+#
+
+sub MAIN( Str $number ) {
+# - An integer number followed by an optional exponent.
+# - A decimal number followed by an optional exponent.
+ # - An integer number is defined with an optional sign '-' or '+' followed by digits.
+
+ 'False'.say and exit( 1 ) if ( $number !~~ / ^ <[+-]>? \d+ (.\d+)? (E<[+-]>?\d+)? $ / );
+ 'True'.say;
+
+}