aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustavo L. de M. Chaves <gustavo@cpqd.com.br>2019-08-10 14:08:38 -0300
committerGustavo L. de M. Chaves <gustavo@cpqd.com.br>2019-08-10 14:08:38 -0300
commit34a545abbd983b402b85c23e98ab1cb723a8b966 (patch)
tree2fe3fd3b0c917aa04a33f1bae5b6dada22172246
parent201f0efb74efe1ad527beaca31e320b1fb67b735 (diff)
downloadperlweeklychallenge-club-34a545abbd983b402b85c23e98ab1cb723a8b966.tar.gz
perlweeklychallenge-club-34a545abbd983b402b85c23e98ab1cb723a8b966.tar.bz2
perlweeklychallenge-club-34a545abbd983b402b85c23e98ab1cb723a8b966.zip
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;
+}