From 5cb059a0cf75ac987d5d9e69431eac6c94845462 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 08:48:43 +0100 Subject: Task 1 done --- challenge-190/luca-ferrari/raku/ch-1.p6 | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 challenge-190/luca-ferrari/raku/ch-1.p6 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; +} -- cgit From 90b8d5cd73152fce7d07c79d25d87d608e0517e0 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 08:54:34 +0100 Subject: Task 2 done --- challenge-190/luca-ferrari/raku/ch-2.p6 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 challenge-190/luca-ferrari/raku/ch-2.p6 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; +} -- cgit From 7007b83fc7d0ce47f2a97aeb20f80c23b6741756 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 09:17:17 +0100 Subject: Task 1 PL/Perl done --- challenge-190/luca-ferrari/postgresql/ch-1.plperl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 challenge-190/luca-ferrari/postgresql/ch-1.plperl 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..4c725c0c7e --- /dev/null +++ b/challenge-190/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,18 @@ +-- 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 ) = @_; + elog( INFO, "Word $word "); + return 1 if ( $word =~ / ^ [A-Z] [a-z]+ $ /x + || $word =~ / ^ [a-z]+ $ /x + || $word =~ / ^ [A-Z]+ $ /x ); + + return 0; +$CODE$ +LANGUAGE plperl; -- cgit From 5a1fe5f3c64d47cedfe37333625c27b5d0bb3f8f Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 09:20:21 +0100 Subject: Task 2 PL/Perl done --- challenge-190/luca-ferrari/postgresql/ch-2.plperl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-190/luca-ferrari/postgresql/ch-2.plperl 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; -- cgit From a93046f1eb7f97a01f8298cc956da6f2214aa884 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 09:26:02 +0100 Subject: Task1 PL/PgSQL done --- challenge-190/luca-ferrari/postgresql/ch-1.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-190/luca-ferrari/postgresql/ch-1.sql 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; -- cgit From 07a532a4a6660519af257438a044592df8164452 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 09:49:29 +0100 Subject: Task 2 PL/PgSQL done --- challenge-190/luca-ferrari/postgresql/ch-2.sql | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 challenge-190/luca-ferrari/postgresql/ch-2.sql 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; -- cgit From 5afb554c5b66a80bd83e307099565a7d86eb87da Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 10:03:04 +0100 Subject: Remove debug output. --- challenge-190/luca-ferrari/postgresql/ch-1.plperl | 1 - 1 file changed, 1 deletion(-) diff --git a/challenge-190/luca-ferrari/postgresql/ch-1.plperl b/challenge-190/luca-ferrari/postgresql/ch-1.plperl index 4c725c0c7e..45686303b3 100644 --- a/challenge-190/luca-ferrari/postgresql/ch-1.plperl +++ b/challenge-190/luca-ferrari/postgresql/ch-1.plperl @@ -8,7 +8,6 @@ pwc190.task1_plperl( text ) RETURNS int AS $CODE$ my ( $word ) = @_; - elog( INFO, "Word $word "); return 1 if ( $word =~ / ^ [A-Z] [a-z]+ $ /x || $word =~ / ^ [a-z]+ $ /x || $word =~ / ^ [A-Z]+ $ /x ); -- cgit From 6f51ed46a5f71a4ef50c4d8a431d918d52842b39 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 7 Nov 2022 10:18:55 +0100 Subject: Blog references --- challenge-190/luca-ferrari/blog-1.txt | 1 + challenge-190/luca-ferrari/blog-2.txt | 1 + challenge-190/luca-ferrari/blog-3.txt | 1 + challenge-190/luca-ferrari/blog-4.txt | 1 + challenge-190/luca-ferrari/blog-5.txt | 1 + challenge-190/luca-ferrari/blog-6.txt | 1 + 6 files changed, 6 insertions(+) create mode 100644 challenge-190/luca-ferrari/blog-1.txt create mode 100644 challenge-190/luca-ferrari/blog-2.txt create mode 100644 challenge-190/luca-ferrari/blog-3.txt create mode 100644 challenge-190/luca-ferrari/blog-4.txt create mode 100644 challenge-190/luca-ferrari/blog-5.txt create mode 100644 challenge-190/luca-ferrari/blog-6.txt 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 -- cgit