diff options
| -rwxr-xr-x | challenge-020/e-choroba/perl5/ch-1.pl | 14 | ||||
| -rwxr-xr-x | challenge-020/e-choroba/perl5/ch-2.pl | 17 |
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"; |
