aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-08-06 01:14:59 +0100
committerGitHub <noreply@github.com>2019-08-06 01:14:59 +0100
commit5a1db36c1102aafba1c2cb218eca96f9fc2bc88c (patch)
treeef5797c44def45fd18a5477025c5632a9521ea43
parent15a6a719c2bd06735e693f7a035f532d39821cdd (diff)
parentbc944b806b543f08e3f182c63b9fbde04c6a2653 (diff)
downloadperlweeklychallenge-club-5a1db36c1102aafba1c2cb218eca96f9fc2bc88c.tar.gz
perlweeklychallenge-club-5a1db36c1102aafba1c2cb218eca96f9fc2bc88c.tar.bz2
perlweeklychallenge-club-5a1db36c1102aafba1c2cb218eca96f9fc2bc88c.zip
Merge pull request #478 from choroba/ech20
Add solutions to 020 by E. Choroba
-rwxr-xr-xchallenge-020/e-choroba/perl5/ch-1.pl14
-rwxr-xr-xchallenge-020/e-choroba/perl5/ch-2.pl17
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-020/e-choroba/perl5/ch-1.pl b/challenge-020/e-choroba/perl5/ch-1.pl
new file mode 100755
index 0000000000..f0c351f239
--- /dev/null
+++ b/challenge-020/e-choroba/perl5/ch-1.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+sub split_on_change {
+ my ($string) = @_;
+ my $i;
+ grep ++$i % 2, $string =~ /((.)\2*)/g
+}
+
+use Test::More tests => 1;
+is_deeply [split_on_change('ABBCDEEF')],
+ [qw[ A BB C D EE F ]];
diff --git a/challenge-020/e-choroba/perl5/ch-2.pl b/challenge-020/e-choroba/perl5/ch-2.pl
new file mode 100755
index 0000000000..4e17ef1186
--- /dev/null
+++ b/challenge-020/e-choroba/perl5/ch-2.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use feature qw(say);
+
+use List::Util qw{ sum0 };
+
+sub sum_divisors {
+ my $n = shift;
+ return sum0(grep 0 == $n % $_, 1 .. $n - 1)
+}
+
+my ($a1, $a2) = (0, 0);
+until ($a1 == sum_divisors($a2) && $a1 < $a2) {
+ $a2 = sum_divisors(++$a1);
+}
+say "$a1 $a2";