aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-01-08 13:05:02 +0000
committerGitHub <noreply@github.com>2022-01-08 13:05:02 +0000
commit12512a62698c327f54a8e2e4439f98d7aecb2d4a (patch)
treecda914e7d4f0ae5858cc5b5f782ba2f2efae7b1f
parent24b026302d147c25abaac667cca068d5d0faa27e (diff)
parentbb0bfdd4256087e61d645bd7e989b4a7eb39c314 (diff)
downloadperlweeklychallenge-club-12512a62698c327f54a8e2e4439f98d7aecb2d4a.tar.gz
perlweeklychallenge-club-12512a62698c327f54a8e2e4439f98d7aecb2d4a.tar.bz2
perlweeklychallenge-club-12512a62698c327f54a8e2e4439f98d7aecb2d4a.zip
Merge pull request #5484 from PerlBoy1967/branch-for-challenge-146
Task 1 & 2
-rwxr-xr-xchallenge-146/perlboy1967/perl/ch-1.pl27
-rwxr-xr-xchallenge-146/perlboy1967/perl/ch-2.pl46
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-146/perlboy1967/perl/ch-1.pl b/challenge-146/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..efe3ddbe44
--- /dev/null
+++ b/challenge-146/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 146
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-146/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › 10001st Prime Number
+Submitted by: Mohammad S Anwar
+
+Write a script to generate the 10001st prime number.
+
+=cut
+
+use v5.16;
+
+use Math::Primality qw(next_prime);
+
+my $N = shift // 10_001;
+
+my ($i,$p) = (1,2);
+
+$p = next_prime($p) while ($i++ < $N);
+
+printf "%d'th prime = %d\n", $N, $p;
diff --git a/challenge-146/perlboy1967/perl/ch-2.pl b/challenge-146/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..8485fbef06
--- /dev/null
+++ b/challenge-146/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,46 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 146
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-146/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #2 › Curious Fraction Tree
+Submitted by: Mohammad S Anwar
+
+You are given a fraction, member of the tree created similar to the above sample.
+
+Write a script to find out the parent and grandparent of the given member.
+Example 1:
+
+ Input: $member = '3/5';
+ Output: parent = '3/2' and grandparent = '1/2'
+
+Example 2:
+
+ Input: $member = '4/3';
+ Output: parent = '1/3' and grandparent = '1/2'
+
+=cut
+
+use v5.16;
+
+my $m = shift // '3/5';
+my $p = getCFTparent($m);
+my $g = getCFTparent($p);
+
+printf "member = '%s' has parent = '%s' and grandparent = '%s'\n", $m, $p, $g;
+
+sub getCFTparent($) {
+ my ($n) = @_;
+
+ ($a, $b) = split(/\//, $n);
+
+ if ($a < $b) {
+ return sprintf('%d/%d', $a, $b - $a);
+ } elsif ($a > $b) {
+ return sprintf('%d/%d', $a - $b, $b);
+ }
+}