diff options
| author | Niels van Dijke <perlboy@cpan.org> | 2022-02-06 19:49:33 +0000 |
|---|---|---|
| committer | Niels van Dijke <perlboy@cpan.org> | 2022-02-06 19:49:33 +0000 |
| commit | c78c1da46f30d3bd3088822925ab25b2e6ffe02d (patch) | |
| tree | c6dc99bc93495b3d994b838d41e41002f4af7a7c | |
| parent | 1003815b69b763c7b723c90582c38b30b762b1ab (diff) | |
| download | perlweeklychallenge-club-c78c1da46f30d3bd3088822925ab25b2e6ffe02d.tar.gz perlweeklychallenge-club-c78c1da46f30d3bd3088822925ab25b2e6ffe02d.tar.bz2 perlweeklychallenge-club-c78c1da46f30d3bd3088822925ab25b2e6ffe02d.zip | |
Task 1 & 2
| -rwxr-xr-x | challenge-150/perlboy1967/perl/ch-1.pl | 47 | ||||
| -rwxr-xr-x | challenge-150/perlboy1967/perl/ch-2.pl | 44 |
2 files changed, 91 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..914cb47a49 --- /dev/null +++ b/challenge-150/perlboy1967/perl/ch-1.pl @@ -0,0 +1,47 @@ +#!/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; + +# 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) = @_; + + state $s = [$s1, $s2]; + + $s->[@$s] = $s->[@$s-2] . $s->[@$s-1] while (@$s < $n); + + return $s->[$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; + |
