aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-02-06 23:36:12 +0000
committerGitHub <noreply@github.com>2022-02-06 23:36:12 +0000
commit4ddaa2851216dc710650380a998f78be101929d8 (patch)
tree9b4459ca9c29b86041d203906b1227d3be244f15
parent1003815b69b763c7b723c90582c38b30b762b1ab (diff)
parent9447be663d424bc49bf511468d3188c90bf3978a (diff)
downloadperlweeklychallenge-club-4ddaa2851216dc710650380a998f78be101929d8.tar.gz
perlweeklychallenge-club-4ddaa2851216dc710650380a998f78be101929d8.tar.bz2
perlweeklychallenge-club-4ddaa2851216dc710650380a998f78be101929d8.zip
Merge pull request #5618 from PerlBoy1967/branch-for-challenge-150
Task 1 & 2
-rwxr-xr-xchallenge-150/perlboy1967/perl/ch-1.pl55
-rwxr-xr-xchallenge-150/perlboy1967/perl/ch-2.pl44
2 files changed, 99 insertions, 0 deletions
diff --git a/challenge-150/perlboy1967/perl/ch-1.pl b/challenge-150/perlboy1967/perl/ch-1.pl
new file mode 100755
index 0000000000..736c61559c
--- /dev/null
+++ b/challenge-150/perlboy1967/perl/ch-1.pl
@@ -0,0 +1,55 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 150
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-150/#TASK1
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #1 › Fibonacci Words
+Submitted by: Mohammad S Anwar
+
+You are given two strings having same number of digits, $a and $b.
+
+Write a script to generate Fibonacci Words by concatenation of the
+previous two strings. Finally print 51st digit of the first term having
+at least 51 digits.
+
+=cut
+
+use v5.16;
+use strict;
+use constant LEN => 51;
+
+use Data::Printer;
+
+# Prototype
+sub fibStr ($$$);
+
+
+@ARGV = (1234, 5678) unless @ARGV == 2;
+
+my ($i, $f) = (1);
+$f = fibStr($ARGV[0], $ARGV[1], $i++) while (length($f) < LEN);
+
+printf "The %dth digit in the first having at least 51 digits '%s' is '%s'\n",
+ LEN, $f, substr($f, LEN-1, 1);
+
+
+sub fibStr ($$$) {
+ my ($s1, $s2, $n) = @_;
+
+ my $k = "$s1:$s2";
+
+ state $s = {};
+ $s->{$k} //= [$s1, $s2];
+
+ my $r = $s->{$k};
+
+ $r->[@$r] = $r->[@$r-2] . $r->[@$r-1]
+ while (@$r < $n);
+
+ return $r->[$n-1]
+}
+
diff --git a/challenge-150/perlboy1967/perl/ch-2.pl b/challenge-150/perlboy1967/perl/ch-2.pl
new file mode 100755
index 0000000000..05927726a9
--- /dev/null
+++ b/challenge-150/perlboy1967/perl/ch-2.pl
@@ -0,0 +1,44 @@
+#!/bin/perl
+
+=pod
+
+The Weekly Challenge - 150
+ - https://perlweeklychallenge.org/blog/perl-weekly-challenge-150/#TASK2
+
+Author: Niels 'PerlBoy' van Dijke
+
+TASK #2 › Square-free Integer
+Submitted by: Mohammad S Anwar
+
+Write a script to generate all square-free integers <= 500.
+
+ | In mathematics, a square-free integer (or squarefree integer) is an
+ | integer which is divisible by no perfect square other than 1. That
+ | is, its prime factorization has exactly one factor for each prime
+ | that appears in it. For example, 10 = 2 x 5 is square-free, but
+ | 18 = 2 x 3 x 3 is not, because 18 is divisible by 9 = 3**2.
+
+=cut
+
+use v5.16;
+use strict;
+
+use List::MoreUtils qw(none);
+use Data::Printer output => 'stdout';
+
+my @i = (1);
+
+my %isqr = (2 => 4);
+my ($i, $m) = (2, 2);
+
+while ($i < 500) {
+ if ($i > 2 * $isqr{$m}) {
+ $m++;
+ $isqr{$m} = $m * $m;
+ }
+ push(@i, $i) if none{$i % $isqr{$_} == 0} keys %isqr;
+ $i++;
+}
+
+p @i;
+