diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-11-08 18:25:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-08 18:25:15 +0000 |
| commit | d80a630519ed9508f5cd435e31ba718a30817fc5 (patch) | |
| tree | eebca8eb3c0979a4beb9b7685aefa414f5d94711 | |
| parent | 3ccc2eebc05174df0d4f7f80a9e0d17370d9cdc7 (diff) | |
| parent | 43a8879240a187a1ab1c90688463afff9ad33f36 (diff) | |
| download | perlweeklychallenge-club-d80a630519ed9508f5cd435e31ba718a30817fc5.tar.gz perlweeklychallenge-club-d80a630519ed9508f5cd435e31ba718a30817fc5.tar.bz2 perlweeklychallenge-club-d80a630519ed9508f5cd435e31ba718a30817fc5.zip | |
Merge pull request #5181 from fluca1978/pwc138
Pwc138
| -rw-r--r-- | challenge-136/luca-ferrari/postgresql/ch-1.sql | 1 | ||||
| -rw-r--r-- | challenge-136/luca-ferrari/postgresql/ch-2.sql | 1 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/blog-1.txt | 1 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/blog-2.txt | 1 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/blog-3.txt | 1 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/blog-4.txt | 1 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/postgresql/ch-1.sql | 12 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/postgresql/ch-2.sql | 34 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/raku/ch-1.p6 | 15 | ||||
| -rw-r--r-- | challenge-138/luca-ferrari/raku/ch-2.p6 | 16 |
10 files changed, 83 insertions, 0 deletions
diff --git a/challenge-136/luca-ferrari/postgresql/ch-1.sql b/challenge-136/luca-ferrari/postgresql/ch-1.sql index ed1f0c71a0..6dbee2b0af 100644 --- a/challenge-136/luca-ferrari/postgresql/ch-1.sql +++ b/challenge-136/luca-ferrari/postgresql/ch-1.sql @@ -22,3 +22,4 @@ AS $CODE$ END; $CODE$ LANGUAGE SQL; + diff --git a/challenge-136/luca-ferrari/postgresql/ch-2.sql b/challenge-136/luca-ferrari/postgresql/ch-2.sql index e1f6439ec0..f7d9e52fd0 100644 --- a/challenge-136/luca-ferrari/postgresql/ch-2.sql +++ b/challenge-136/luca-ferrari/postgresql/ch-2.sql @@ -31,3 +31,4 @@ WHERE total_sum = l $CODE$ LANGUAGE SQL; + diff --git a/challenge-138/luca-ferrari/blog-1.txt b/challenge-138/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..01ce5c7e32 --- /dev/null +++ b/challenge-138/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/11/08/PerlWeeklyChallenge138.html#task1 diff --git a/challenge-138/luca-ferrari/blog-2.txt b/challenge-138/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..b4547b6091 --- /dev/null +++ b/challenge-138/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/11/08/PerlWeeklyChallenge138.html#task2 diff --git a/challenge-138/luca-ferrari/blog-3.txt b/challenge-138/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..fb6f0f0202 --- /dev/null +++ b/challenge-138/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/11/08/PerlWeeklyChallenge138.html#task1pg diff --git a/challenge-138/luca-ferrari/blog-4.txt b/challenge-138/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..a0c37f0c45 --- /dev/null +++ b/challenge-138/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/11/08/PerlWeeklyChallenge138.html#task2pg diff --git a/challenge-138/luca-ferrari/postgresql/ch-1.sql b/challenge-138/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..53956e64cb --- /dev/null +++ b/challenge-138/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,12 @@ +CREATE OR REPLACE FUNCTION + f_working_days_per_year( yy int default extract( year from current_date ) ) + RETURNS int +AS $CODE$ + SELECT count( v ) + FROM generate_series( make_date( yy, 01, 01 ), + make_date( yy, 12, 31 ), + '1 days' ) v + WHERE + extract( dow from v ) NOT IN ( 0, 6 ); + $CODE$ + LANGUAGE sql; diff --git a/challenge-138/luca-ferrari/postgresql/ch-2.sql b/challenge-138/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..6b6c49cc89 --- /dev/null +++ b/challenge-138/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,34 @@ +CREATE OR REPLACE FUNCTION + f_split_numbers( n int default 9801 ) + RETURNS int +AS $CODE$ + DECLARE + sqrt int := sqrt( n ); + digits int[] := regexp_split_to_array( n::text, '' ); + aggregation int := 0; + sum_left int := 0; + sum_right int := 0; +BEGIN + RAISE DEBUG 'Operating for % (sqrt = %)', n, sqrt; + + FOR aggregation IN 1 .. length( n::text ) LOOP + RAISE DEBUG 'Aggregation index %', aggregation; + + SELECT array_to_string( digits[1:aggregation], '' )::int + , sum( r ) + FROM ( SELECT unnest( digits[ aggregation + 1: length( n::text ) ] ) AS r ) rr + INTO sum_left, sum_right; + + RAISE DEBUG '% + %', sum_left, sum_right; + + IF ( sum_left + sum_right ) = sqrt THEN + RETURN 1; + END IF; + END LOOP; + + RETURN 0; +END + $CODE$ + LANGUAGE plpgsql; + + diff --git a/challenge-138/luca-ferrari/raku/ch-1.p6 b/challenge-138/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..b238c21ff5 --- /dev/null +++ b/challenge-138/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,15 @@ +#!raku + +sub MAIN( Int $year where { $year ~~ / \d ** 4 / } && $year > 1900, + Bool :$verbose = False ) { + my Date $date .= new: year => $year, day => 1, month => 1; + my Date $stop .= new: year => $year, day => 31, month => 12; + my $work-days = 0; + while ( $date <= $stop ) { + $work-days += 1 if $date.day-of-week != any( 6, 7 ); + $date = $date + 1; + } + + "$year has $work-days work days".say if $verbose; + $work-days.say if ! $verbose; +} diff --git a/challenge-138/luca-ferrari/raku/ch-2.p6 b/challenge-138/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..72e7295a70 --- /dev/null +++ b/challenge-138/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,16 @@ +#!raku + +sub MAIN( Int:D $n where { $n > 0 } ) { + my $qrt = $n.sqrt; + my @digits = $n.split( '', :skip-empty ); + + # short circuit: esay case + 1.say and exit if @digits.sum == $qrt; + + # try to aggregate from left to right + for 1 ..^ @digits.elems { + last if @digits[ 0 .. $_ ].join.Int > $qrt; + '1'.say and exit if @digits[ 0 .. $_ ].join + @digits[ $_ + 1 .. * - 1 ].sum == $qrt; + } + +} |
