aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-01-07 08:05:20 +0000
committerGitHub <noreply@github.com>2023-01-07 08:05:20 +0000
commit5656aba7c17a2e7e202eec539ceb6fba05ad9679 (patch)
tree0514cb6266a4fec465a075c7680d7d2a6cf89b2e
parentfdc42329c7392fa47fc96f4ed6a7ac853c4a8f53 (diff)
parent202d3521b553ff5958de6263db4942b0b73f03b7 (diff)
downloadperlweeklychallenge-club-5656aba7c17a2e7e202eec539ceb6fba05ad9679.tar.gz
perlweeklychallenge-club-5656aba7c17a2e7e202eec539ceb6fba05ad9679.tar.bz2
perlweeklychallenge-club-5656aba7c17a2e7e202eec539ceb6fba05ad9679.zip
Merge pull request #7367 from polettix/polettix/pwc198
Add polettix's solution to challenge-198
-rw-r--r--challenge-198/polettix/blog.txt1
-rw-r--r--challenge-198/polettix/blog1.txt1
-rw-r--r--challenge-198/polettix/perl/ch-1.pl21
-rw-r--r--challenge-198/polettix/perl/ch-2.pl3
-rw-r--r--challenge-198/polettix/perl/cpanfile1
-rw-r--r--challenge-198/polettix/perl/cpanfile.snapshot44
-rw-r--r--challenge-198/polettix/raku/ch-1.raku20
-rw-r--r--challenge-198/polettix/raku/ch-2.raku3
8 files changed, 94 insertions, 0 deletions
diff --git a/challenge-198/polettix/blog.txt b/challenge-198/polettix/blog.txt
new file mode 100644
index 0000000000..cfc27d1738
--- /dev/null
+++ b/challenge-198/polettix/blog.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2023/01/05/pwc198-max-gap/
diff --git a/challenge-198/polettix/blog1.txt b/challenge-198/polettix/blog1.txt
new file mode 100644
index 0000000000..262ca921f8
--- /dev/null
+++ b/challenge-198/polettix/blog1.txt
@@ -0,0 +1 @@
+https://github.polettix.it/ETOOBUSY/2023/01/06/pwc198-prime-count/
diff --git a/challenge-198/polettix/perl/ch-1.pl b/challenge-198/polettix/perl/ch-1.pl
new file mode 100644
index 0000000000..174a1b5d94
--- /dev/null
+++ b/challenge-198/polettix/perl/ch-1.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+use v5.24;
+use warnings;
+use experimental 'signatures';
+no warnings 'experimental::signatures';
+
+say max_gap(@ARGV ? @ARGV : (2, 5, 8, 1));
+
+sub max_gap (@list) {
+ @list = sort { $a <=> $b } @list;
+ my $widest_gap = -1;
+ my $count = 0;
+ for my $i (1 .. $#list) {
+ my $gap = $list[$i] - $list[$i - 1];
+
+ # order of the following tests matters, do not change!
+ ++$count if $gap == $widest_gap;
+ ($count, $widest_gap) = (1, $gap) if $gap > $widest_gap;
+ }
+ return $count;
+}
diff --git a/challenge-198/polettix/perl/ch-2.pl b/challenge-198/polettix/perl/ch-2.pl
new file mode 100644
index 0000000000..6555640357
--- /dev/null
+++ b/challenge-198/polettix/perl/ch-2.pl
@@ -0,0 +1,3 @@
+#!/usr/bin/env perl
+use ntheory 'prime_count';
+print prime_count(($ARGV[0] // 10) - 1), "\n";
diff --git a/challenge-198/polettix/perl/cpanfile b/challenge-198/polettix/perl/cpanfile
new file mode 100644
index 0000000000..91dda9616f
--- /dev/null
+++ b/challenge-198/polettix/perl/cpanfile
@@ -0,0 +1 @@
+requires 'Math::Prime::Util';
diff --git a/challenge-198/polettix/perl/cpanfile.snapshot b/challenge-198/polettix/perl/cpanfile.snapshot
new file mode 100644
index 0000000000..9b674ca80a
--- /dev/null
+++ b/challenge-198/polettix/perl/cpanfile.snapshot
@@ -0,0 +1,44 @@
+# carton snapshot format: version 1.0
+DISTRIBUTIONS
+ Math-Prime-Util-0.73
+ pathname: D/DA/DANAJ/Math-Prime-Util-0.73.tar.gz
+ provides:
+ Math::Prime::Util 0.73
+ Math::Prime::Util::ChaCha 0.73
+ Math::Prime::Util::ECAffinePoint undef
+ Math::Prime::Util::ECProjectivePoint undef
+ Math::Prime::Util::Entropy 0.73
+ Math::Prime::Util::MemFree 0.73
+ Math::Prime::Util::PP 0.73
+ Math::Prime::Util::PPFE undef
+ Math::Prime::Util::PrimalityProving undef
+ Math::Prime::Util::PrimeArray 0.73
+ Math::Prime::Util::PrimeIterator 0.73
+ Math::Prime::Util::RandomPrimes undef
+ Math::Prime::Util::ZetaBigFloat undef
+ ntheory 0.73
+ requirements:
+ Carp 0
+ Config 0
+ Exporter 5.57
+ ExtUtils::MakeMaker 0
+ Math::BigFloat 1.59
+ Math::BigInt 1.88
+ Math::Prime::Util::GMP 0.50
+ Tie::Array 0
+ XSLoader 0.01
+ base 0
+ constant 0
+ perl 5.006002
+ Math-Prime-Util-GMP-0.52
+ pathname: D/DA/DANAJ/Math-Prime-Util-GMP-0.52.tar.gz
+ provides:
+ Math::Prime::Util::GMP 0.52
+ requirements:
+ Carp 0
+ Exporter 5.57
+ ExtUtils::MakeMaker 0
+ Fcntl 0
+ XSLoader 0.01
+ base 0
+ perl 5.006002
diff --git a/challenge-198/polettix/raku/ch-1.raku b/challenge-198/polettix/raku/ch-1.raku
new file mode 100644
index 0000000000..89fdf40340
--- /dev/null
+++ b/challenge-198/polettix/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/usr/bin/env raku
+use v6;
+sub MAIN (*@args) {
+ @args = 2, 5, 8, 1 unless @args;
+ put max-gap(@args);
+}
+
+sub max-gap (@list) {
+ my $widest-gap = -1;
+ my $count = 0;
+ my @sorted = @list.sort: { $^a <=> $^b };
+ for 1 ..^ @sorted -> $i {
+ my $gap = @sorted[$i] - @sorted[$i - 1];
+
+ # order of the following tests matters, do not change!
+ ++$count if $gap == $widest-gap;
+ ($count, $widest-gap) = 1, $gap if $gap > $widest-gap;
+ }
+ return $count;
+}
diff --git a/challenge-198/polettix/raku/ch-2.raku b/challenge-198/polettix/raku/ch-2.raku
new file mode 100644
index 0000000000..a87372c488
--- /dev/null
+++ b/challenge-198/polettix/raku/ch-2.raku
@@ -0,0 +1,3 @@
+#!/usr/bin/env raku
+sub prime-count ($n) { (2 ... $n).grep({.is-prime}).elems }
+put prime-count((@*ARGS[0] // 10) - 1);