From af8d0436ba764c6683c3dc1810c0012d4f81a4eb Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 10:06:21 +0200 Subject: Task 1 done --- challenge-185/luca-ferrari/raku/ch-1.p6 | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 challenge-185/luca-ferrari/raku/ch-1.p6 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; + +} -- cgit From 47ee5bdb4bafb5d4134182bbce243a6cde566cb9 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 10:18:27 +0200 Subject: Task 2 done --- challenge-185/luca-ferrari/raku/ch-2.p6 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 challenge-185/luca-ferrari/raku/ch-2.p6 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; +} -- cgit From 9e9bb92d4b8dca13c73b28ea23d861e32d975839 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 10:56:21 +0200 Subject: Task 1 plperl done --- challenge-185/luca-ferrari/postgresql/ch-1.plperl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-185/luca-ferrari/postgresql/ch-1.plperl 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; -- cgit From dd79f10dfd7f9915b173787349fcb22b3639f81a Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 10:59:37 +0200 Subject: Task 2 plperl done --- challenge-185/luca-ferrari/postgresql/ch-2.plperl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-185/luca-ferrari/postgresql/ch-2.plperl 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; -- cgit From e248b2f4fefeed28f09546e24fb6d7dc9b935d6e Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 11:04:39 +0200 Subject: Task 1 plpgsql done --- challenge-185/luca-ferrari/postgresql/ch-1.sql | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-185/luca-ferrari/postgresql/ch-1.sql 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; -- cgit From a929164a89fc5f92c85da52d800b90b1215025f2 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 11:12:32 +0200 Subject: Task 2 ppgsql done --- challenge-185/luca-ferrari/postgresql/ch-2.sql | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-185/luca-ferrari/postgresql/ch-2.sql 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; -- cgit From 31856ed94b0166d9da7b90a0853ccc2c7689caec Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 3 Oct 2022 12:14:37 +0200 Subject: Blog references --- challenge-185/luca-ferrari/blog-1.txt | 1 + challenge-185/luca-ferrari/blog-2.txt | 1 + challenge-185/luca-ferrari/blog-3.txt | 1 + challenge-185/luca-ferrari/blog-4.txt | 1 + challenge-185/luca-ferrari/blog-5.txt | 1 + challenge-185/luca-ferrari/blog-6.txt | 1 + 6 files changed, 6 insertions(+) create mode 100644 challenge-185/luca-ferrari/blog-1.txt create mode 100644 challenge-185/luca-ferrari/blog-2.txt create mode 100644 challenge-185/luca-ferrari/blog-3.txt create mode 100644 challenge-185/luca-ferrari/blog-4.txt create mode 100644 challenge-185/luca-ferrari/blog-5.txt create mode 100644 challenge-185/luca-ferrari/blog-6.txt 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 -- cgit