From bc944b806b543f08e3f182c63b9fbde04c6a2653 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 5 Aug 2019 23:36:51 +0200 Subject: Add solutions to 020 by E. Choroba --- challenge-020/e-choroba/perl5/ch-1.pl | 14 ++++++++++++++ challenge-020/e-choroba/perl5/ch-2.pl | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 challenge-020/e-choroba/perl5/ch-1.pl create mode 100755 challenge-020/e-choroba/perl5/ch-2.pl 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"; -- cgit