From 34a545abbd983b402b85c23e98ab1cb723a8b966 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Sat, 10 Aug 2019 14:08:38 -0300 Subject: Gustavo Chaves's solutions to challenge 020 --- challenge-020/gustavo-chaves/perl5/ch-1.pl | 13 +++++++++++++ challenge-020/gustavo-chaves/perl5/ch-2.pl | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 challenge-020/gustavo-chaves/perl5/ch-1.pl create mode 100755 challenge-020/gustavo-chaves/perl5/ch-2.pl 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; +} -- cgit