diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-08 19:37:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 19:37:34 +0000 |
| commit | 181cc0ba08cf9dc76b39d6bd10f5bab63e5253c4 (patch) | |
| tree | 310b9518b34cec2382ff17b747252be8cd5748bd | |
| parent | ef4059d9cef5bbe1cb14e4a0e2c0b6937fb7c8d0 (diff) | |
| parent | 879d890fe3656f7394a5f15e7b61747a73444f18 (diff) | |
| download | perlweeklychallenge-club-181cc0ba08cf9dc76b39d6bd10f5bab63e5253c4.tar.gz perlweeklychallenge-club-181cc0ba08cf9dc76b39d6bd10f5bab63e5253c4.tar.bz2 perlweeklychallenge-club-181cc0ba08cf9dc76b39d6bd10f5bab63e5253c4.zip | |
Merge pull request #7678 from fluca1978/PWC207
Pwc207
| -rw-r--r-- | challenge-207/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/blog-3.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/blog-4.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/blog-5.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/blog-6.txt | 1 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/postgresql/ch-1.plperl | 34 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/postgresql/ch-1.sql | 45 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/postgresql/ch-2.plperl | 23 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/postgresql/ch-2.sql | 26 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/raku/ch-1.p6 | 24 | ||||
| -rw-r--r-- | challenge-207/luca-ferrari/raku/ch-2.p6 | 20 |
12 files changed, 178 insertions, 0 deletions
diff --git a/challenge-207/luca-ferrari/blog-1.txt b/challenge-207/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..198c9de319 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1 diff --git a/challenge-207/luca-ferrari/blog-2.txt b/challenge-207/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..2bdda598ec --- /dev/null +++ b/challenge-207/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2 diff --git a/challenge-207/luca-ferrari/blog-3.txt b/challenge-207/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..8c2bdc218e --- /dev/null +++ b/challenge-207/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1plperl diff --git a/challenge-207/luca-ferrari/blog-4.txt b/challenge-207/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..e310a1b0b6 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2plperl diff --git a/challenge-207/luca-ferrari/blog-5.txt b/challenge-207/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..589e0e9013 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1plpgsql diff --git a/challenge-207/luca-ferrari/blog-6.txt b/challenge-207/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..f66ba42c5e --- /dev/null +++ b/challenge-207/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2plpgsql diff --git a/challenge-207/luca-ferrari/postgresql/ch-1.plperl b/challenge-207/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..f40c97ae1e --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,34 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 1 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task1_plperl( text[] ) +RETURNS SETOF text +AS $CODE$ + + my ( $words ) = @_; + my ( @keyboard ) = qw/ qwertyuiop asdfghjkl zxcvbnm /; + + for my $current_word ( $words->@* ) { + for my $current_row ( @keyboard ) { + my $found = 0; + for my $current_letter ( split( '', lc( $current_word ) ) ) { + $found++ if ( $current_row =~ /$current_letter/ ); + } + + if ( scalar( split( '', $current_word ) ) == $found ) { + return_next( $current_word ); + last; + } + } + } + + return undef; + +$CODE$ +LANGUAGE plperl; diff --git a/challenge-207/luca-ferrari/postgresql/ch-1.sql b/challenge-207/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..477bf9703f --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,45 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 1 +-- +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task1_plpgsql( w text[] ) +RETURNS SETOF text +AS $CODE$ +DECLARE + current_word text; + current_row text; + letters_found int; +BEGIN + + CREATE TEMPORARY TABLE IF NOT EXISTS keyboard( k text ); + TRUNCATE keyboard; + INSERT INTO keyboard( k ) + VALUES( 'qwertyuiop' ), ( 'asdfghjkl' ), ( 'zxcvbnm' ); + + FOREACH current_word IN ARRAY w LOOP + FOR current_row IN SELECT k FROM keyboard LOOP + letters_found := 0; + + SELECT count(*) + INTO letters_found + FROM regexp_split_to_table( current_word, '' ) ww + JOIN regexp_split_to_table( current_row, '' ) kk + ON ww = kk; + + IF letters_found = length( current_word ) THEN + RETURN NEXT current_word; + EXIT; + END IF; + END LOOP; + END LOOP; + +RETURN; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.plperl b/challenge-207/luca-ferrari/postgresql/ch-2.plperl new file mode 100644 index 0000000000..6794b73618 --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-2.plperl @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 2 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task2_plperl( int[] ) +RETURNS int +AS $CODE$ + + my ( $citations ) = @_; + my @cits = reverse sort $citations->@*; + my @data; + while ( my ( $key, $value ) = each( @cits ) ) { + push @data, $key if ( $key >= $value ); + } + + return ( sort( @data ) )[ 0 ]; +$CODE$ +LANGUAGE plperl; diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.sql b/challenge-207/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..a0daf6681a --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,26 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 2 +-- +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task2_plpgsql( citations int[] ) +RETURNS SETOF int +AS $CODE$ +DECLARE +BEGIN + RETURN QUERY WITH d AS ( + SELECT c, row_number() OVER ( ORDER BY c desc ) r + FROM unnest( citations ) c + ) + SELECT MIN( r ) + FROM d + WHERE r >= c + ; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-207/luca-ferrari/raku/ch-1.p6 b/challenge-207/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..129b1111bc --- /dev/null +++ b/challenge-207/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,24 @@ +#!raku + +# +# Perl Weekly Challenge 207 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +# + +sub MAIN( *@words ) { + my @keyboard = qw/ qwertyuiop asdfghjkl zxcvbnm /; + + for @words -> $current-word { + for @keyboard -> $current-row { + my $found = 0; + for $current-word.lc.comb -> $current-letter { + $found++ if ( $current-row ~~ /$current-letter/ ); + } + + $current-word.say if $current-word.chars == $found; + } + } + +} diff --git a/challenge-207/luca-ferrari/raku/ch-2.p6 b/challenge-207/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..9fe10ca663 --- /dev/null +++ b/challenge-207/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,20 @@ +#!raku + +# +# Perl Weekly Challenge 207 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/> +# + + +# The H-Index is the largest number h such that h articles have at least h citations each. +# For example, if an author has five publications, with 9, 7, 6, 2, and 1 citations +# (ordered from greatest to least), +# then the author’s h-index is 3, because the author has three publications +# with 3 or more citations. +# However, the author does not have four publications with 4 or more citations. + +sub MAIN( *@citations where { @citations.grep( * ~~ Int ).elems == @citations.elems } ) { + @citations.sort.reverse.pairs.first( { $_.key >= $_.value } ).key.say; +} |
