aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-190/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-190/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-190/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-190/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-190/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-190/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-190/luca-ferrari/postgresql/ch-1.plperl17
-rw-r--r--challenge-190/luca-ferrari/postgresql/ch-1.sql22
-rw-r--r--challenge-190/luca-ferrari/postgresql/ch-2.plperl19
-rw-r--r--challenge-190/luca-ferrari/postgresql/ch-2.sql43
-rw-r--r--challenge-190/luca-ferrari/raku/ch-1.p612
-rw-r--r--challenge-190/luca-ferrari/raku/ch-2.p613
12 files changed, 132 insertions, 0 deletions
diff --git a/challenge-190/luca-ferrari/blog-1.txt b/challenge-190/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..23e84a81ab
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task1
diff --git a/challenge-190/luca-ferrari/blog-2.txt b/challenge-190/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..6435a1f714
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task2
diff --git a/challenge-190/luca-ferrari/blog-3.txt b/challenge-190/luca-ferrari/blog-3.txt
new file mode 100644
index 0000000000..0c019f06de
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-3.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task1plperl
diff --git a/challenge-190/luca-ferrari/blog-4.txt b/challenge-190/luca-ferrari/blog-4.txt
new file mode 100644
index 0000000000..4a33fc14f1
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-4.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task2plperl
diff --git a/challenge-190/luca-ferrari/blog-5.txt b/challenge-190/luca-ferrari/blog-5.txt
new file mode 100644
index 0000000000..a3ef9bd126
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-5.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task1plpgsql
diff --git a/challenge-190/luca-ferrari/blog-6.txt b/challenge-190/luca-ferrari/blog-6.txt
new file mode 100644
index 0000000000..b296f60d50
--- /dev/null
+++ b/challenge-190/luca-ferrari/blog-6.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/11/07/PerlWeeklyChallenge190.html#task2plpgsql
diff --git a/challenge-190/luca-ferrari/postgresql/ch-1.plperl b/challenge-190/luca-ferrari/postgresql/ch-1.plperl
new file mode 100644
index 0000000000..45686303b3
--- /dev/null
+++ b/challenge-190/luca-ferrari/postgresql/ch-1.plperl
@@ -0,0 +1,17 @@
+-- Perl Weekly Challenge 190
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc190;
+
+CREATE OR REPLACE FUNCTION
+pwc190.task1_plperl( text )
+RETURNS int
+AS $CODE$
+ my ( $word ) = @_;
+ return 1 if ( $word =~ / ^ [A-Z] [a-z]+ $ /x
+ || $word =~ / ^ [a-z]+ $ /x
+ || $word =~ / ^ [A-Z]+ $ /x );
+
+ return 0;
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-190/luca-ferrari/postgresql/ch-1.sql b/challenge-190/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..05bf96d51e
--- /dev/null
+++ b/challenge-190/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,22 @@
+-- Perl Weekly Challenge 190
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc190;
+
+CREATE OR REPLACE FUNCTION
+pwc190.task1_plpgsql( word text )
+RETURNS int
+AS $CODE$
+BEGIN
+ IF word ~ '^[A-Z][a-z]+$' THEN
+ RETURN 1;
+ ELSIF word ~ '^[a-z]+$' THEN
+ RETURN 1;
+ ELSIF word ~ '^[A-Z]+$' THEN
+ RETURN 1;
+ ELSE
+ RETURN 0;
+ END IF;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-190/luca-ferrari/postgresql/ch-2.plperl b/challenge-190/luca-ferrari/postgresql/ch-2.plperl
new file mode 100644
index 0000000000..7cc37be286
--- /dev/null
+++ b/challenge-190/luca-ferrari/postgresql/ch-2.plperl
@@ -0,0 +1,19 @@
+-- Perl Weekly Challenge 190
+-- Task 2
+
+CREATE SCHEMA IF NOT EXISTS pwc190;
+
+CREATE OR REPLACE FUNCTION
+pwc190.task2_plperl( text )
+RETURNS text
+AS $CODE$
+ my ( $number ) = @_;
+ my @decoded;
+ my %decode_table = map { ( $_ + 1 ) => ( 'A' .. 'Z' )[ $_ ] } ( 0 .. 9 );
+ for my $current ( split '', $number ) {
+ push @decoded, $decode_table{ $current };
+ }
+
+return join( '', @decoded );
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-190/luca-ferrari/postgresql/ch-2.sql b/challenge-190/luca-ferrari/postgresql/ch-2.sql
new file mode 100644
index 0000000000..cf0444db6b
--- /dev/null
+++ b/challenge-190/luca-ferrari/postgresql/ch-2.sql
@@ -0,0 +1,43 @@
+-- Perl Weekly Challenge 190
+-- Task 2
+
+CREATE SCHEMA IF NOT EXISTS pwc190;
+
+CREATE OR REPLACE FUNCTION
+pwc190.task2_plpgsql( num text)
+RETURNS SETOF text
+AS $CODE$
+DECLARE
+ decoded text := '';
+BEGIN
+ CREATE TEMP TABLE IF NOT EXISTS decode_table ( c char, i int );
+ TRUNCATE TABLE decode_table;
+ INSERT INTO decode_table
+ VALUES
+ ( 'A', 0 )
+ , ( 'B', 1 )
+ , ( 'C', 2 )
+ , ( 'D', 3 )
+ , ( 'E', 4 )
+ , ( 'F', 5 )
+ , ( 'G', 6 )
+ , ( 'H', 7 )
+ , ( 'I', 8 )
+ , ( 'M', 9 );
+
+ RETURN QUERY
+ WITH w AS ( SELECT n::int, row_number() over () as r FROM regexp_split_to_table( num, '' ) n )
+ , dec AS (
+ SELECT d.c
+ FROM decode_table d
+ JOIN w ON w.n = d.i
+ ORDER BY w.r
+ )
+ SELECT string_agg( dec.c, '' )
+ FROM dec;
+
+
+
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-190/luca-ferrari/raku/ch-1.p6 b/challenge-190/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..79a99a23e5
--- /dev/null
+++ b/challenge-190/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,12 @@
+#!raku
+
+# Perl Weekly Challenge 190
+
+sub MAIN( Str $word ) {
+
+ '1'.say and exit if ( $word ~~ /
+ | ^ <[A .. Z]> <[a .. z]>+ $
+ | ^ <[a..z]>+ $
+ | ^ <[A..Z]>+ $ / );
+ '0'.say;
+}
diff --git a/challenge-190/luca-ferrari/raku/ch-2.p6 b/challenge-190/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..e166a7dd99
--- /dev/null
+++ b/challenge-190/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,13 @@
+#!raku
+
+# Perl Weekly Challenge 190
+
+sub MAIN( Str $number where { $number ~~ / ^ \d+ $ / } ) {
+ my %decode-table = ( 0 .. 9 ).map: { ( $_ + 1 ) => ( 'A' .. 'Z' )[ $_ ] };
+ my @decoded;
+ for $number.comb -> $current {
+ @decoded.push: %decode-table{ $current };
+ }
+
+ @decoded.join( '' ).say;
+}