diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-10-31 21:10:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-31 21:10:17 +0000 |
| commit | d910581b4a5121589345356c9e0ed02532cabc59 (patch) | |
| tree | ba57c5ba2ae9dafde76004dd017c6803e39015bf | |
| parent | 220a550a4a351e27215d593a4c9665c5a5c954f4 (diff) | |
| parent | 70cd62f9a8258b22cd2d385fa65c265e6f6423f1 (diff) | |
| download | perlweeklychallenge-club-d910581b4a5121589345356c9e0ed02532cabc59.tar.gz perlweeklychallenge-club-d910581b4a5121589345356c9e0ed02532cabc59.tar.bz2 perlweeklychallenge-club-d910581b4a5121589345356c9e0ed02532cabc59.zip | |
Merge pull request #5125 from fluca1978/pwc136
Pwc136
| -rw-r--r-- | challenge-136/luca-ferrari/blog-3.txt | 1 | ||||
| -rw-r--r-- | challenge-136/luca-ferrari/blog-4.txt | 1 | ||||
| -rw-r--r-- | challenge-136/luca-ferrari/postgresql/ch-1.sql | 24 | ||||
| -rw-r--r-- | challenge-136/luca-ferrari/postgresql/ch-2.sql | 33 |
4 files changed, 59 insertions, 0 deletions
diff --git a/challenge-136/luca-ferrari/blog-3.txt b/challenge-136/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..fd8dbeb710 --- /dev/null +++ b/challenge-136/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/10/29/PerlWeeklyChallenge136PostgreSQL.html#task1 diff --git a/challenge-136/luca-ferrari/blog-4.txt b/challenge-136/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..f9b68dd456 --- /dev/null +++ b/challenge-136/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2021/10/29/PerlWeeklyChallenge136PostgreSQL.html#task2 diff --git a/challenge-136/luca-ferrari/postgresql/ch-1.sql b/challenge-136/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..ed1f0c71a0 --- /dev/null +++ b/challenge-136/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,24 @@ +/* +testdb=> SELECT FRIENDLY( 26, 39 ); +friendly +---------- +0 +(1 row) + +testdb=> SELECT FRIENDLY( 26, 52 ); +friendly +---------- +1 +(1 row) + +*/ +CREATE OR REPLACE FUNCTION friendly( m int, n int ) +RETURNS int +AS $CODE$ + SELECT + CASE gcd( m, n ) % 2 + WHEN 0 THEN 1 + ELSE 0 + END; +$CODE$ +LANGUAGE SQL; diff --git a/challenge-136/luca-ferrari/postgresql/ch-2.sql b/challenge-136/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..e1f6439ec0 --- /dev/null +++ b/challenge-136/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE FUNCTION fibonacci_sum( l int DEFAULT 16 ) +RETURNS bigint +AS $CODE$ + +WITH RECURSIVE +fibonacci( n, p ) AS +( + SELECT 1, 1 + UNION + SELECT p + n, n + FROM fibonacci + WHERE n < l +) +, permutations AS +( + SELECT n::text AS current_value, n as total_sum + FROM fibonacci + UNION + SELECT current_value || ',' || n, total_sum + n + FROM permutations, fibonacci + WHERE + position( n::text in current_value ) = 0 + AND n > ALL( string_to_array( current_value, ',' )::int[] ) + + +) +SELECT count(*) +FROM permutations +WHERE total_sum = l +; + +$CODE$ +LANGUAGE SQL; |
