aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-08-10 20:49:59 +0100
committerGitHub <noreply@github.com>2019-08-10 20:49:59 +0100
commit5c4df461cbf4dcbd6597ab45db1e3c820c74ea4d (patch)
tree1a26c47065d77968cee1b442c7e30ec5ca8272bf
parent458f3f5e05a1372a4b735ce23faa22f0a4175867 (diff)
parent34a545abbd983b402b85c23e98ab1cb723a8b966 (diff)
downloadperlweeklychallenge-club-5c4df461cbf4dcbd6597ab45db1e3c820c74ea4d.tar.gz
perlweeklychallenge-club-5c4df461cbf4dcbd6597ab45db1e3c820c74ea4d.tar.bz2
perlweeklychallenge-club-5c4df461cbf4dcbd6597ab45db1e3c820c74ea4d.zip
Merge pull request #495 from gnustavo/020
Gustavo Chaves's solutions to challenge 020
-rwxr-xr-xchallenge-020/gustavo-chaves/perl5/ch-1.pl13
-rwxr-xr-xchallenge-020/gustavo-chaves/perl5/ch-2.pl24
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-020/gustavo-chaves/perl5/ch-1.pl b/challenge-020/gustavo-chaves/perl5/ch-1.pl
new file mode 100755
index 0000000000..a285a921b5
--- /dev/null
+++ b/challenge-020/gustavo-chaves/perl5/ch-1.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+
+# Write a script to accept a string from command line and split it on change of
+# character. For example, if the string is “ABBCDEEF”, then it should split like
+# “A”, “BB”, “C”, “D”, “EE”, “F”.
+
+use 5.026;
+use strict;
+use warnings;
+
+my $string = shift or die "Usage: $0 STRING\n";
+
+say $& while $string =~ /(.)\g1*/g;
diff --git a/challenge-020/gustavo-chaves/perl5/ch-2.pl b/challenge-020/gustavo-chaves/perl5/ch-2.pl
new file mode 100755
index 0000000000..391f3a90c6
--- /dev/null
+++ b/challenge-020/gustavo-chaves/perl5/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+# Write a script to print the smallest pair of Amicable Numbers. For more
+# information, please checkout wikipedia page:
+# https://en.wikipedia.org/wiki/Amicable_numbers.
+
+use 5.026;
+use strict;
+use warnings;
+use Math::Prime::Util qw/divisor_sum/;
+use Memoize;
+
+memoize('divisor_sum');
+
+for (my $n=2; ; ++$n) {
+ my $pds = divisor_sum($n) - $n;
+ next if $n == $pds;
+
+ my $pds_pds = divisor_sum($pds) - $pds;
+ next if $n != $pds_pds;
+
+ say "$n $pds";
+ last;
+}