From 14cf3d91e9869dbe9f8072fbffce6b5103936011 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 18:35:20 +0200 Subject: Task 1 done --- challenge-234/luca-ferrari/raku/ch-1.p6 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 challenge-234/luca-ferrari/raku/ch-1.p6 diff --git a/challenge-234/luca-ferrari/raku/ch-1.p6 b/challenge-234/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..057b34229a --- /dev/null +++ b/challenge-234/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!raku + +# +# Perl Weekly Challenge 234 +# Task 1 +# +# See +# + +sub MAIN( *@words ) { + my %chars; + for @words -> $current_word { + for $current_word.comb.unique.sort { + %chars{ $_ }.push: $current_word; + } + } + + for %chars.kv -> $char, $list { + say $char if $list.elems == @words.elems; + } + +} -- cgit From 3eeb198e7d789360e0c7f8e88566593b17f519c6 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 18:40:45 +0200 Subject: Task 2 done --- challenge-234/luca-ferrari/raku/ch-2.p6 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-234/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-234/luca-ferrari/raku/ch-2.p6 b/challenge-234/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..9a82b56cc1 --- /dev/null +++ b/challenge-234/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,25 @@ +#!raku + +# +# Perl Weekly Challenge 234 +# Task 2 +# +# See +# + +sub MAIN( *@nums where { @nums.grep( * ~~ Int ).elems == @nums.elems } ) { + my @triples; + + #(i, j, k) that satisfies num[i] != num[j], num[j] != num[k] and num[k] != num[i]. + for 0 ..^ @nums.elems - 2 -> $i { + for $i ^..^ @nums.elems - 1 -> $j { + for $j ^..^ @nums.elems -> $k { + @triples.push: [ $i, $j, $k ] if ( @nums[ $i ] != @nums[ $j ] + && @nums[ $j ] != @nums[ $k ] + && @nums[ $k ] != @nums[ $i ] ); + } + } + } + + @triples.join( "\n" ).say; +} -- cgit From 60080f94b1cd0ff7dd6eb0dc3df3fd62feb3ae6a Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 18:49:26 +0200 Subject: Task 1 plperl done --- challenge-234/luca-ferrari/postgresql/ch-1.plperl | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-234/luca-ferrari/postgresql/ch-1.plperl diff --git a/challenge-234/luca-ferrari/postgresql/ch-1.plperl b/challenge-234/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..6edef0543c --- /dev/null +++ b/challenge-234/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,31 @@ +-- +-- Perl Weekly Challenge 234 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc234; + +CREATE OR REPLACE FUNCTION +pwc234.task1_plperl( text[] ) +RETURNS SETOF char +AS $CODE$ + my ( $words ) = @_; + + my $chars = {}; + + for my $current_word ( $words->@* ) { + for my $current_char ( sort split //, $current_word ) { + if ( ! grep { $_ eq $current_word } $chars->{ $current_char }->@* ) { + push $chars->{ $current_char }->@*, $current_word; + } + } + } + + for my $current_char ( keys $chars->%* ) { + return_next( $current_char ) if ( $chars->{ $current_char }->@* == scalar $words->@* ); + } + + return undef; +$CODE$ +LANGUAGE plperl; -- cgit From 15ac125d275f03abcdaff4a7b821fa23800987ef Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 18:57:09 +0200 Subject: Task 2 plperl --- challenge-234/luca-ferrari/postgresql/ch-2.plperl | 28 +++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-234/luca-ferrari/postgresql/ch-2.plperl diff --git a/challenge-234/luca-ferrari/postgresql/ch-2.plperl b/challenge-234/luca-ferrari/postgresql/ch-2.plperl new file mode 100644 index 0000000000..ac85075a2a --- /dev/null +++ b/challenge-234/luca-ferrari/postgresql/ch-2.plperl @@ -0,0 +1,28 @@ +-- +-- Perl Weekly Challenge 234 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc234; + +CREATE OR REPLACE FUNCTION +pwc234.task2_plperl( int[] ) +RETURNS TABLE( i int, j int, k int ) +AS $CODE$ + my ( $nums ) = @_; + + for my $i ( 0 .. $nums->@* - 3 ) { + for my $j ( $i + 1 .. $nums->@* - 2 ) { + for my $k ( $j + 1 .. $nums->@* - 1 ) { + return_next( { i => $i, j => $j, k => $k } ) + if ( $nums->[ $i ] != $nums->[ $j ] + && $nums->[ $j ] != $nums->[ $k ] + && $nums->[ $k ] != $nums->[ $i ] ); + } + } + } + + return undef; +$CODE$ +LANGUAGE plperl; -- cgit From aa35267ac114608c6612eaa63676c9b68b2dc24d Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 19:10:30 +0200 Subject: Task 1 and 2 plpgsql done --- challenge-234/luca-ferrari/postgresql/ch-1.sql | 33 ++++++++++++++++++++++++++ challenge-234/luca-ferrari/postgresql/ch-2.sql | 30 +++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 challenge-234/luca-ferrari/postgresql/ch-1.sql create mode 100644 challenge-234/luca-ferrari/postgresql/ch-2.sql diff --git a/challenge-234/luca-ferrari/postgresql/ch-1.sql b/challenge-234/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..14e45492f1 --- /dev/null +++ b/challenge-234/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,33 @@ +-- +-- Perl Weekly Challenge 234 +-- Task 1 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc234; + +CREATE OR REPLACE FUNCTION +pwc234.task1_plpgsql( words text[] ) +RETURNS SETOF char +AS $CODE$ +DECLARE + w text; +BEGIN + CREATE TEMPORARY TABLE IF NOT EXISTS chars( c char, word text ); + TRUNCATE chars; + + FOREACH w IN ARRAY words LOOP + INSERT INTO chars + SELECT c, w + FROM regexp_split_to_table( w, '' ) c; + END LOOP; + + RETURN QUERY + SELECT c + FROM chars + GROUP BY c + HAVING count( word ) >= array_length( words, 1 ); +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-234/luca-ferrari/postgresql/ch-2.sql b/challenge-234/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..1279f673ce --- /dev/null +++ b/challenge-234/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,30 @@ +-- +-- Perl Weekly Challenge 234 +-- Task 2 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc234; + +CREATE OR REPLACE FUNCTION +pwc234.task2_plpgsql( nums int[] ) +RETURNS TABLE (ii int, jj int, kk int ) +AS $CODE$ +BEGIN + FOR i IN 1 .. array_length( nums, 1 ) - 2 LOOP + FOR j IN i + 1 .. array_length( nums, 1 ) - 1 LOOP + FOR k IN j + 1 .. array_length( nums, 1 ) LOOP + IF nums[i] <> nums[j] AND nums[j] <> nums[k] AND nums[k] <> nums[i] THEN + raise info '% % %', i, j, k; + ii := i; + jj := j; + kk := k; + RETURN NEXT; + END IF; + END LOOP; + END LOOP; + END LOOP; +END +$CODE$ +LANGUAGE plpgsql; -- cgit From 8258b67ae7a11a66fc2f8ef4a70696e45da4211c Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Sun, 17 Sep 2023 19:17:13 +0200 Subject: Blog references --- challenge-234/luca-ferrari/blog-1.txt | 1 + challenge-234/luca-ferrari/blog-2.txt | 1 + challenge-234/luca-ferrari/blog-3.txt | 1 + challenge-234/luca-ferrari/blog-4.txt | 1 + challenge-234/luca-ferrari/blog-5.txt | 1 + challenge-234/luca-ferrari/blog-6.txt | 1 + 6 files changed, 6 insertions(+) create mode 100644 challenge-234/luca-ferrari/blog-1.txt create mode 100644 challenge-234/luca-ferrari/blog-2.txt create mode 100644 challenge-234/luca-ferrari/blog-3.txt create mode 100644 challenge-234/luca-ferrari/blog-4.txt create mode 100644 challenge-234/luca-ferrari/blog-5.txt create mode 100644 challenge-234/luca-ferrari/blog-6.txt diff --git a/challenge-234/luca-ferrari/blog-1.txt b/challenge-234/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..ba8c92a58c --- /dev/null +++ b/challenge-234/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task1 diff --git a/challenge-234/luca-ferrari/blog-2.txt b/challenge-234/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..96f227c475 --- /dev/null +++ b/challenge-234/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task2 diff --git a/challenge-234/luca-ferrari/blog-3.txt b/challenge-234/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..a445252265 --- /dev/null +++ b/challenge-234/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task1plperl diff --git a/challenge-234/luca-ferrari/blog-4.txt b/challenge-234/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..2b8aa27b83 --- /dev/null +++ b/challenge-234/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task2plperl diff --git a/challenge-234/luca-ferrari/blog-5.txt b/challenge-234/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..e3dbf7d267 --- /dev/null +++ b/challenge-234/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task1plpgsql diff --git a/challenge-234/luca-ferrari/blog-6.txt b/challenge-234/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..7b5b4a2ef4 --- /dev/null +++ b/challenge-234/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/09/17/PerlWeeklyChallenge234.html#task2plpgsql -- cgit