diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-03-18 16:52:33 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-18 16:52:33 +0000 |
| commit | 2cce5fa06bfe9859e189f820541be11d133eb31f (patch) | |
| tree | 4fb009bf965e64a5d97d4b175b7fe5eab346a50d | |
| parent | 46cf2ec29f488c992bf0a9c142f2cb8dd7ea2e5d (diff) | |
| parent | b63339d7d4f13572bf0087b32a07f5760aa132af (diff) | |
| download | perlweeklychallenge-club-2cce5fa06bfe9859e189f820541be11d133eb31f.tar.gz perlweeklychallenge-club-2cce5fa06bfe9859e189f820541be11d133eb31f.tar.bz2 perlweeklychallenge-club-2cce5fa06bfe9859e189f820541be11d133eb31f.zip | |
Merge pull request #9769 from choroba/ech261
Solve 261: Element Digit Sum & Multiple by Two by E. Choroba
| -rwxr-xr-x | challenge-261/e-choroba/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-261/e-choroba/perl/ch-2.pl | 15 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-261/e-choroba/perl/ch-1.pl b/challenge-261/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..7d99202d5e --- /dev/null +++ b/challenge-261/e-choroba/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use List::Util qw{ sum }; + +sub element_digit_sum(@ints) { + abs(sum(@ints) - sum(map { split // } @ints)) +} + +use Test::More tests => 4; + +is element_digit_sum(1, 2, 3, 45), 36, 'Example 1'; +is element_digit_sum(1, 12, 3), 9, 'Example 2'; +is element_digit_sum(1, 2, 3, 4), 0, 'Example 3'; +is element_digit_sum(236, 416, 336, 350), 1296, 'Example 4'; diff --git a/challenge-261/e-choroba/perl/ch-2.pl b/challenge-261/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..2cca2ac3f6 --- /dev/null +++ b/challenge-261/e-choroba/perl/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +sub multiple_by_two($start, @ints) { + $start *= 2 while grep $_ == $start, @ints; + return $start +} + +use Test::More tests => 3; + +is multiple_by_two(3, 5, 3, 6, 1, 12), 24, 'Example 1'; +is multiple_by_two(1, 1, 2, 4, 3), 8, 'Example 2'; +is multiple_by_two(2, 5, 6, 7), 2, 'Example 3'; |
