aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-10-03 12:48:31 +0100
committerGitHub <noreply@github.com>2022-10-03 12:48:31 +0100
commit13f41dc29b116de9fb0a0e92ddd9b4244afa8b91 (patch)
tree63c916f6ccbfc22102e847137c6b2b0053fa2eff
parentb1ae20f555b175106207a17e90a1de823cc36957 (diff)
parent31856ed94b0166d9da7b90a0853ccc2c7689caec (diff)
downloadperlweeklychallenge-club-13f41dc29b116de9fb0a0e92ddd9b4244afa8b91.tar.gz
perlweeklychallenge-club-13f41dc29b116de9fb0a0e92ddd9b4244afa8b91.tar.bz2
perlweeklychallenge-club-13f41dc29b116de9fb0a0e92ddd9b4244afa8b91.zip
Merge pull request #6835 from fluca1978/PWC185
Pwc185
-rw-r--r--challenge-185/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-185/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-185/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-185/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-185/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-185/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-185/luca-ferrari/postgresql/ch-1.plperl23
-rw-r--r--challenge-185/luca-ferrari/postgresql/ch-1.sql27
-rw-r--r--challenge-185/luca-ferrari/postgresql/ch-2.plperl21
-rw-r--r--challenge-185/luca-ferrari/postgresql/ch-2.sql31
-rwxr-xr-xchallenge-185/luca-ferrari/raku/ch-1.p611
-rwxr-xr-xchallenge-185/luca-ferrari/raku/ch-2.p619
12 files changed, 138 insertions, 0 deletions
diff --git a/challenge-185/luca-ferrari/blog-1.txt b/challenge-185/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..b97761361d
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task1
diff --git a/challenge-185/luca-ferrari/blog-2.txt b/challenge-185/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..b4b0de0628
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task2
diff --git a/challenge-185/luca-ferrari/blog-3.txt b/challenge-185/luca-ferrari/blog-3.txt
new file mode 100644
index 0000000000..b13591fb44
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-3.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task1plperl
diff --git a/challenge-185/luca-ferrari/blog-4.txt b/challenge-185/luca-ferrari/blog-4.txt
new file mode 100644
index 0000000000..66bdfdfaeb
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-4.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task2plperl
diff --git a/challenge-185/luca-ferrari/blog-5.txt b/challenge-185/luca-ferrari/blog-5.txt
new file mode 100644
index 0000000000..c866c6d614
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-5.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task1plpgsql
diff --git a/challenge-185/luca-ferrari/blog-6.txt b/challenge-185/luca-ferrari/blog-6.txt
new file mode 100644
index 0000000000..817a69dd76
--- /dev/null
+++ b/challenge-185/luca-ferrari/blog-6.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2022/10/03/PerlWeeklyChallenge185.html#task2plpgsql
diff --git a/challenge-185/luca-ferrari/postgresql/ch-1.plperl b/challenge-185/luca-ferrari/postgresql/ch-1.plperl
new file mode 100644
index 0000000000..9c4ca45b8e
--- /dev/null
+++ b/challenge-185/luca-ferrari/postgresql/ch-1.plperl
@@ -0,0 +1,23 @@
+-- Perl Weekly Challenge 185
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc185;
+
+CREATE OR REPLACE FUNCTION
+pwc185.task1_plperl( text )
+RETURNS text
+AS $CODE$
+my ( $input ) = @_;
+
+$input =~ s/\./g/;
+
+my ( $counter, $output ) = ( 1, '' );
+for ( split( //, $input ) ) {
+ $output .= $_;
+ $output .= ':' if $counter % 2 == 0;
+ $counter++;
+}
+
+return $output;
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-185/luca-ferrari/postgresql/ch-1.sql b/challenge-185/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..571e0ee4ae
--- /dev/null
+++ b/challenge-185/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,27 @@
+-- Perl Weekly Challenge 185
+-- Task 1
+
+CREATE SCHEMA IF NOT EXISTS pwc185;
+
+CREATE OR REPLACE FUNCTION
+pwc185.task1_plpgsql( mac_input text )
+RETURNS text
+AS $CODE$
+DECLARE
+ c int := 1;
+ d char;
+ mac_output text := '';
+BEGIN
+ mac_input := replace( mac_input, '.', '' );
+ FOREACH d IN ARRAY regexp_split_to_array( mac_input, '' ) LOOP
+ mac_output := mac_output || d;
+ IF c % 2 = 0 THEN
+ mac_output := mac_output || ':';
+ END IF;
+ c := c + 1;
+ END LOOP;
+
+ RETURN mac_output;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-185/luca-ferrari/postgresql/ch-2.plperl b/challenge-185/luca-ferrari/postgresql/ch-2.plperl
new file mode 100644
index 0000000000..162a7c9762
--- /dev/null
+++ b/challenge-185/luca-ferrari/postgresql/ch-2.plperl
@@ -0,0 +1,21 @@
+-- Perl Weekly Challenge 185
+-- Task 2
+
+CREATE SCHEMA IF NOT EXISTS pwc185;
+
+CREATE OR REPLACE FUNCTION
+pwc185.task2_plperl( text )
+RETURNS text
+AS $CODE$
+my ( $input ) = @_;
+my @output;
+my $counter = 4;
+
+for ( split( //, $input ) ) {
+ push @output, 'x' and $counter-- and next if ( /[a-z0-9]/i ) and $counter > 0;
+ push @output, $_;
+}
+
+return join( '', @output );
+$CODE$
+LANGUAGE plperl;
diff --git a/challenge-185/luca-ferrari/postgresql/ch-2.sql b/challenge-185/luca-ferrari/postgresql/ch-2.sql
new file mode 100644
index 0000000000..a18a7e73ab
--- /dev/null
+++ b/challenge-185/luca-ferrari/postgresql/ch-2.sql
@@ -0,0 +1,31 @@
+-- Perl Weekly Challenge 185
+-- Task 2
+
+CREATE SCHEMA IF NOT EXISTS pwc185;
+
+CREATE OR REPLACE FUNCTION
+pwc185.task2_plpgsql( code text )
+RETURNS text
+AS $CODE$
+DECLARE
+ how_many int := 4;
+ d char;
+ code_out text := '';
+BEGIN
+ FOREACH d IN ARRAY regexp_split_to_array( code, '' ) LOOP
+ IF how_many = 0 OR d !~ '\w' THEN
+ code_out := code_out || d;
+ CONTINUE;
+ ELSEIF how_many > 0 AND d ~ '\w' THEN
+ code_out := code_out || 'x';
+ how_many := how_many - 1;
+
+ ELSE
+ code_out := code_out || d;
+ END IF;
+ END LOOP;
+
+RETURN code_out;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-185/luca-ferrari/raku/ch-1.p6 b/challenge-185/luca-ferrari/raku/ch-1.p6
new file mode 100755
index 0000000000..aa73c5563a
--- /dev/null
+++ b/challenge-185/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,11 @@
+#!raku
+
+# Perl Weekly Challenge 185
+
+sub MAIN( Str $input-mac-address
+ where { $input-mac-address ~~ / ^ ( <[0..9a..f]> ** 4 <[.]> ) ** 2 <[0..9a..f]> ** 4 $ / } ) {
+
+ my $output-mac-address = $input-mac-address.subst( /<[.]>/, '', :g );
+ $output-mac-address.comb( :spit-empty ).rotor( 2 ).join( ':' ).subst( /\s+/, '', :g ).say;
+
+}
diff --git a/challenge-185/luca-ferrari/raku/ch-2.p6 b/challenge-185/luca-ferrari/raku/ch-2.p6
new file mode 100755
index 0000000000..a04eb12cc4
--- /dev/null
+++ b/challenge-185/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,19 @@
+#!raku
+
+# Perl Weekly Challenge 185
+
+sub MAIN( *@codes ) {
+ my @output-codes;
+ for @codes -> $current-code {
+ my @current-output;
+ my $counter = 4;
+ for $current-code.comb -> $current-char is copy {
+ $current-char = 'x' and $counter-- if $current-char ~~ / <[0..9a..z]> / && $counter > 0;
+ @current-output.push: $current-char;
+ }
+
+ @output-codes.push: @current-output.join;
+ }
+
+ @output-codes.join( "\n" ).say;
+}