aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-12-01 19:25:23 +0000
committerGitHub <noreply@github.com>2021-12-01 19:25:23 +0000
commita3f2137fa7cc152097c4188df91c13754dc35e26 (patch)
treefce425437871a2179f0b2e2f8d40f695031ce962
parent39a07a3f975a3160b155fe1fab191a72f14668e1 (diff)
parentc89584624fde5c8d698e132b340a2ac0c462983e (diff)
downloadperlweeklychallenge-club-a3f2137fa7cc152097c4188df91c13754dc35e26.tar.gz
perlweeklychallenge-club-a3f2137fa7cc152097c4188df91c13754dc35e26.tar.bz2
perlweeklychallenge-club-a3f2137fa7cc152097c4188df91c13754dc35e26.zip
Merge pull request #5308 from fluca1978/pwc141
Pwc141
-rw-r--r--challenge-141/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-141/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-141/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-141/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-141/luca-ferrari/postgresql/ch-1.sql32
-rw-r--r--challenge-141/luca-ferrari/postgresql/ch-2.sql21
-rwxr-xr-xchallenge-141/luca-ferrari/raku/ch-1.p619
-rwxr-xr-xchallenge-141/luca-ferrari/raku/ch-2.p66
8 files changed, 82 insertions, 0 deletions
diff --git a/challenge-141/luca-ferrari/blog-1.txt b/challenge-141/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..80cbe14380
--- /dev/null
+++ b/challenge-141/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/11/29/PerlWeeklyChallenge141.html#task1
diff --git a/challenge-141/luca-ferrari/blog-2.txt b/challenge-141/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..35e7946b2f
--- /dev/null
+++ b/challenge-141/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/11/29/PerlWeeklyChallenge141.html#task2
diff --git a/challenge-141/luca-ferrari/blog-3.txt b/challenge-141/luca-ferrari/blog-3.txt
new file mode 100644
index 0000000000..e064c87e1a
--- /dev/null
+++ b/challenge-141/luca-ferrari/blog-3.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/11/29/PerlWeeklyChallenge141.html#task1pg
diff --git a/challenge-141/luca-ferrari/blog-4.txt b/challenge-141/luca-ferrari/blog-4.txt
new file mode 100644
index 0000000000..0c5caa9c08
--- /dev/null
+++ b/challenge-141/luca-ferrari/blog-4.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/11/29/PerlWeeklyChallenge141.html#task2pg
diff --git a/challenge-141/luca-ferrari/postgresql/ch-1.sql b/challenge-141/luca-ferrari/postgresql/ch-1.sql
new file mode 100644
index 0000000000..c68e881175
--- /dev/null
+++ b/challenge-141/luca-ferrari/postgresql/ch-1.sql
@@ -0,0 +1,32 @@
+CREATE OR REPLACE FUNCTION
+f_find_divisors( divisors int default 8, count int default 10 )
+RETURNS SETOF int
+AS $CODE$
+DECLARE
+ current_number int;
+ current_divisor int;
+ current_found int;
+BEGIN
+ FOR current_number IN 1 .. 999999 LOOP
+ IF count = 0 THEN
+ EXIT;
+ END IF;
+
+ current_found := 0;
+
+ FOR current_divisor IN 1 .. current_number LOOP
+ IF current_number % current_divisor = 0 THEN
+ current_found := current_found + 1;
+ END IF;
+ END LOOP;
+
+ IF current_found = divisors THEN
+ count := count - 1;
+ RETURN NEXT current_number;
+ END IF;
+ END LOOP;
+
+ RETURN;
+END
+$CODE$
+LANGUAGE plpgsql;
diff --git a/challenge-141/luca-ferrari/postgresql/ch-2.sql b/challenge-141/luca-ferrari/postgresql/ch-2.sql
new file mode 100644
index 0000000000..239d846b58
--- /dev/null
+++ b/challenge-141/luca-ferrari/postgresql/ch-2.sql
@@ -0,0 +1,21 @@
+CREATE OR REPLACE FUNCTION
+f_live_numbers( m int, n int )
+RETURNS SETOF int
+AS $CODE$
+WITH RECURSIVE
+numbers AS ( SELECT unnest( regexp_split_to_array( m::text, '' ) ) AS n )
+, combinations( i, v, c ) AS (
+SELECT 1, n, n
+FROM numbers
+UNION
+SELECT i + 1, n, c || num.n
+FROM combinations, numbers num
+WHERE length( c || num.n ) < length( m::text ) - 1
+AND num.n IN ( SELECT n FROM numbers WHERE n::int > i )
+)
+
+SELECT c::int FROM combinations
+WHERE c::int % n = 0;
+
+$CODE$
+LANGUAGE sql;
diff --git a/challenge-141/luca-ferrari/raku/ch-1.p6 b/challenge-141/luca-ferrari/raku/ch-1.p6
new file mode 100755
index 0000000000..621db2a13e
--- /dev/null
+++ b/challenge-141/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,19 @@
+#!raku
+
+
+sub MAIN( Int $divisors = 8, Int $count = 10 ) {
+
+ "Searching $count numbers with $divisors divisors...".say;
+
+ my %solutions;
+
+ for $divisors + 1 .. Inf -> $current-number {
+ my @intra-solutions = ( 1 .. $current-number ).grep( { $current-number %% $_ } );
+
+ %solutions{ $current-number } = @intra-solutions if @intra-solutions.elems == $divisors;
+
+ last if %solutions.keys.elems >= $count;
+ }
+
+ "$_ has $divisors divisors: { %solutions{ $_ }.join( ', ' ) }".say for %solutions.keys.sort;
+}
diff --git a/challenge-141/luca-ferrari/raku/ch-2.p6 b/challenge-141/luca-ferrari/raku/ch-2.p6
new file mode 100755
index 0000000000..ae278b19e1
--- /dev/null
+++ b/challenge-141/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,6 @@
+#!raku
+
+sub MAIN( Int $m, Int $n ) {
+ $m.comb.combinations( 1 ..^ $m.Str.chars ).map( *.join.Int ).grep( * %% $n ).unique.sort.say;
+
+}