aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-17 12:37:17 +0000
committerGitHub <noreply@github.com>2021-11-17 12:37:17 +0000
commitb8fd1a1ce00e7498815facc65e266b0f8f0d36cb (patch)
tree8343f0210619bdb2a30b0a78f2af517839e397f6
parent3fd6c833bfe376d1afe45be35dc455c1eb9328fb (diff)
parent470f4f134166a0d88b4800b54c5e13510e4dfa50 (diff)
downloadperlweeklychallenge-club-b8fd1a1ce00e7498815facc65e266b0f8f0d36cb.tar.gz
perlweeklychallenge-club-b8fd1a1ce00e7498815facc65e266b0f8f0d36cb.tar.bz2
perlweeklychallenge-club-b8fd1a1ce00e7498815facc65e266b0f8f0d36cb.zip
Merge pull request #5237 from wlmb/challenges
Challenges
-rw-r--r--challenge-139/wlmb/blog.txt1
-rwxr-xr-xchallenge-139/wlmb/perl/ch-1.pl12
-rwxr-xr-xchallenge-139/wlmb/perl/ch-2.pl32
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-139/wlmb/blog.txt b/challenge-139/wlmb/blog.txt
new file mode 100644
index 0000000000..cb8992e369
--- /dev/null
+++ b/challenge-139/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2021/11/16/PWC139/
diff --git a/challenge-139/wlmb/perl/ch-1.pl b/challenge-139/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..5610caae31
--- /dev/null
+++ b/challenge-139/wlmb/perl/ch-1.pl
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 139
+# Task 1: JortSort
+#
+# See https://wlmb.github.io/2021/11/16/PWC139/#task-1-jortsort
+use v5.12;
+use warnings;
+use List::Util qw(none);
+say "Input: (", (join " ",@ARGV), ")";
+my $x; # previous element
+my $y=shift @ARGV; # current element
+say "Output: ", (none {($x,$y)=($y,$_); $x>$y}@ARGV)?1:0;
diff --git a/challenge-139/wlmb/perl/ch-2.pl b/challenge-139/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..7776cb696c
--- /dev/null
+++ b/challenge-139/wlmb/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 139
+# Task 2: Long Primes
+#
+# See https://wlmb.github.io/2021/11/16/PWC139/#task-2-long-primes
+use v5.12;
+use warnings;
+use bignum;
+use Math::Prime::Util qw(next_prime);
+use List::Util qw(first);
+use Text::Wrap qw(wrap $columns $break);
+$columns=62;
+$break=qr/\s|_/;
+my $max_count=shift @ARGV//5; # get number of long primes from command line
+my $prime=2; #current prime (will skip '2')
+my $count=0;
+my @lines;
+while($count<$max_count){
+ $prime=next_prime($prime);
+ my $length=$prime-1; # expected length of large cycle
+ Math::BigFloat->accuracy(3.5*$length); # allow 3+ repetitions
+ my @groups= grep {$_} split /(\d{$length})/, 1./$prime; # groups of digits
+ pop @groups; # throw away last (guard) repetition (posibly inexact)
+ ++$count, push @lines,
+ "$count-th long prime is $prime",
+ " as 1/$prime = " . shift(@groups) . join "_", @groups,"..."
+ if (first # if cycle doesn't stop early
+ {my $x=10**$_%$prime; $x==1||$x==0}
+ (1..$prime-1))
+ == $prime-1
+}
+say wrap("", " _", $_) for @lines;