diff options
| author | E. Choroba <choroba@matfyz.cz> | 2019-08-05 23:36:51 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2019-08-05 23:38:59 +0200 |
| commit | bc944b806b543f08e3f182c63b9fbde04c6a2653 (patch) | |
| tree | ef5797c44def45fd18a5477025c5632a9521ea43 | |
| parent | 15a6a719c2bd06735e693f7a035f532d39821cdd (diff) | |
| download | perlweeklychallenge-club-bc944b806b543f08e3f182c63b9fbde04c6a2653.tar.gz perlweeklychallenge-club-bc944b806b543f08e3f182c63b9fbde04c6a2653.tar.bz2 perlweeklychallenge-club-bc944b806b543f08e3f182c63b9fbde04c6a2653.zip | |
Add solutions to 020 by E. Choroba
| -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"; |
