diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-04 15:45:48 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-04 15:45:48 +0000 |
| commit | eea272843353377e3256b5767a01f01cda874cb3 (patch) | |
| tree | 172ad238c792d972970267d57377cfa1101e09c7 | |
| parent | d28b7664077930151308cba0f601a274dec0fe77 (diff) | |
| parent | ca4013a626cda8490425132219502b50b66dcb6a (diff) | |
| download | perlweeklychallenge-club-eea272843353377e3256b5767a01f01cda874cb3.tar.gz perlweeklychallenge-club-eea272843353377e3256b5767a01f01cda874cb3.tar.bz2 perlweeklychallenge-club-eea272843353377e3256b5767a01f01cda874cb3.zip | |
Merge pull request #9347 from fluca1978/PWC250
PWC 250
| -rw-r--r-- | challenge-250/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-3.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-4.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-5.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-6.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-7.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/blog-8.txt | 1 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/postgresql/ch-1.plperl | 21 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/postgresql/ch-1.sql | 24 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/postgresql/ch-2.plperl | 32 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/postgresql/ch-2.sql | 36 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/python/ch-1.py | 23 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/python/ch-2.py | 33 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/raku/ch-1.p6 | 13 | ||||
| -rw-r--r-- | challenge-250/luca-ferrari/raku/ch-2.p6 | 12 |
16 files changed, 202 insertions, 0 deletions
diff --git a/challenge-250/luca-ferrari/blog-1.txt b/challenge-250/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..725ae843e9 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task1 diff --git a/challenge-250/luca-ferrari/blog-2.txt b/challenge-250/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..2c2216e46b --- /dev/null +++ b/challenge-250/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task2 diff --git a/challenge-250/luca-ferrari/blog-3.txt b/challenge-250/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..1802d72df9 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task1plperl diff --git a/challenge-250/luca-ferrari/blog-4.txt b/challenge-250/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..860bdd6fc2 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task2plperl diff --git a/challenge-250/luca-ferrari/blog-5.txt b/challenge-250/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..18a2120675 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task1plpgsql diff --git a/challenge-250/luca-ferrari/blog-6.txt b/challenge-250/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..fb1cec459f --- /dev/null +++ b/challenge-250/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task2plpgsql diff --git a/challenge-250/luca-ferrari/blog-7.txt b/challenge-250/luca-ferrari/blog-7.txt new file mode 100644 index 0000000000..03b56cd791 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-7.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task1python diff --git a/challenge-250/luca-ferrari/blog-8.txt b/challenge-250/luca-ferrari/blog-8.txt new file mode 100644 index 0000000000..f3cc974337 --- /dev/null +++ b/challenge-250/luca-ferrari/blog-8.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2024/01/04/PerlWeeklyChallenge250.html#task2python diff --git a/challenge-250/luca-ferrari/postgresql/ch-1.plperl b/challenge-250/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..218a6c3964 --- /dev/null +++ b/challenge-250/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,21 @@ +-- +-- Perl Weekly Challenge 250 +-- Task 1 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc250; + +CREATE OR REPLACE FUNCTION +pwc250.task1_plperl( int[] ) +RETURNS int +AS $CODE$ + my ( $nums ) = @_; + + for ( 0 .. $nums->@* - 1 ) { + return $_ if ( ( $_ % 10 ) == $nums->@[ $_ ] ); + } + + return -1; +$CODE$ +LANGUAGE plperl; diff --git a/challenge-250/luca-ferrari/postgresql/ch-1.sql b/challenge-250/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..664869545b --- /dev/null +++ b/challenge-250/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,24 @@ +-- +-- Perl Weekly Challenge 250 +-- Task 1 +-- +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc250; + +CREATE OR REPLACE FUNCTION +pwc250.task1_plpgsql( nums int[] ) +RETURNS int +AS $CODE$ +BEGIN + FOR i IN 1 .. array_length( nums, 1 ) LOOP + IF mod( i, 10 ) = nums[ i ] THEN + RETURN i; + END IF; + END LOOP; + + RETURN -1; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-250/luca-ferrari/postgresql/ch-2.plperl b/challenge-250/luca-ferrari/postgresql/ch-2.plperl new file mode 100644 index 0000000000..22da300c62 --- /dev/null +++ b/challenge-250/luca-ferrari/postgresql/ch-2.plperl @@ -0,0 +1,32 @@ +-- +-- Perl Weekly Challenge 250 +-- Task 2 +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc250; + +CREATE OR REPLACE FUNCTION +pwc250.task2_plperl( text[] ) +RETURNS int +AS $CODE$ + my ( $words ) = @_; + my $max = 0; + + for ( $words->@* ) { + my $value = 0; + + if ( $_ =~ / ^ \d+ $ /x ) { + $value = int( $_ ); + } + else { + $value = length( $_ ); + } + + $max = $value if ( $value > $max ); + + } + + return $max; +$CODE$ +LANGUAGE plperl; diff --git a/challenge-250/luca-ferrari/postgresql/ch-2.sql b/challenge-250/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..fd1828d93b --- /dev/null +++ b/challenge-250/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,36 @@ +-- +-- Perl Weekly Challenge 250 +-- Task 2 +-- +-- See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +-- + +CREATE SCHEMA IF NOT EXISTS pwc250; + +CREATE OR REPLACE FUNCTION +pwc250.task2_plpgsql( words text[] ) +RETURNS int +AS $CODE$ +DECLARE + final int; +BEGIN + CREATE TEMPORARY TABLE IF NOT EXISTS t_values( w text, l int, v int DEFAULT 0 ); + TRUNCATE t_values; + + INSERT INTO t_values( w, l, v ) + SELECT vv, length( vv ), length( vv ) + FROM unnest( words ) vv; + + UPDATE t_values + SET v = w::int + WHERE w IN ( SELECT w FROM t_values + WHERE regexp_match( w, '^\d+$' ) IS NOT NULL ); + + SELECT max( v ) + INTO final + FROM t_values; + + RETURN final; +END +$CODE$ +LANGUAGE plpgsql; diff --git a/challenge-250/luca-ferrari/python/ch-1.py b/challenge-250/luca-ferrari/python/ch-1.py new file mode 100644 index 0000000000..ba6e744b4c --- /dev/null +++ b/challenge-250/luca-ferrari/python/ch-1.py @@ -0,0 +1,23 @@ +#!python + +# +# Perl Weekly Challenge 250 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +# + +import sys + +# task implementation +def main( argv ): + for i in range(0,len(argv)): + if int(i) % 10 == int( argv[ i ] ): + return i + + return -1 + + +# invoke the main without the command itself +if __name__ == '__main__': + print( main( sys.argv[ 1: ] ) ) diff --git a/challenge-250/luca-ferrari/python/ch-2.py b/challenge-250/luca-ferrari/python/ch-2.py new file mode 100644 index 0000000000..3725f6765a --- /dev/null +++ b/challenge-250/luca-ferrari/python/ch-2.py @@ -0,0 +1,33 @@ +#!python + +# +# Perl Weekly Challenge 250 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +# + +import sys +import re + +# task implementation +def main( argv ): + max = 0 + is_num = re.compile( '^\d+$' ) + for current in argv: + v = 0 + + if is_num.match( current ) is None: + v = len( current ) + else: + v = int( current ) + + if v > max: + max = v + + return max + + +# invoke the main without the command itself +if __name__ == '__main__': + print( main( sys.argv[ 1: ] ) ) diff --git a/challenge-250/luca-ferrari/raku/ch-1.p6 b/challenge-250/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..d6f3d1420d --- /dev/null +++ b/challenge-250/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,13 @@ +#!raku + +# +# Perl Weekly Challenge 250 +# Task 1 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +# + +sub MAIN( *@nums where { @nums.elems == @nums.grep( * ~~ Int ).elems } ) { + $_.say and exit if ( @nums[ $_ ] == ( $_ % 10 ) ) for 0 ..^ @nums.elems; + '-1'.say; +} diff --git a/challenge-250/luca-ferrari/raku/ch-2.p6 b/challenge-250/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..2efba1eabe --- /dev/null +++ b/challenge-250/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,12 @@ +#!raku + +# +# Perl Weekly Challenge 250 +# Task 2 +# +# See <https://perlweeklychallenge.org/blog/perl-weekly-challenge-250/> +# + +sub MAIN( *@words ) { + @words.map( { $_ ~~ / ^ <[0..9]>+ $ / ?? $_.Int !! $_.chars } ).max.say; +} |
