diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-07 10:33:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-07 10:33:14 +0100 |
| commit | 671c9ce667ea3ce40a05cfea9ba5ea553693f496 (patch) | |
| tree | 2d9e95aa2381980e44e5ea3f11de834a0eaa343c | |
| parent | 3a3ae93f3d08fdf3b2a057ccd71f4f4fd7135639 (diff) | |
| parent | 529d0e53b1c3fe887bc56262da6292788cfce62b (diff) | |
| download | perlweeklychallenge-club-671c9ce667ea3ce40a05cfea9ba5ea553693f496.tar.gz perlweeklychallenge-club-671c9ce667ea3ce40a05cfea9ba5ea553693f496.tar.bz2 perlweeklychallenge-club-671c9ce667ea3ce40a05cfea9ba5ea553693f496.zip | |
Merge pull request #9881 from kjetillll/challenge-261-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-261/
| -rw-r--r-- | challenge-261/kjetillll/perl/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-261/kjetillll/perl/ch-2.pl | 23 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-261/kjetillll/perl/ch-1.pl b/challenge-261/kjetillll/perl/ch-1.pl new file mode 100644 index 0000000000..c5a8317761 --- /dev/null +++ b/challenge-261/kjetillll/perl/ch-1.pl @@ -0,0 +1,29 @@ +use strict; use warnings; + +sub sumdiff { + eval( join '+', @_ ) + - + eval( join '+', "@_" =~ /\d/g ) +} + + + +#========== Test ======================================== +use Test::More tests => 4; +is( sumdiff( @{ $$_{input} } ), $$_{output} ) for + { + input=> [1,2,3,45], + output=> 36 + }, + { + input=> [1,12,3], + output=> 9 + }, + { + input=> [1,2,3,4], + output=> 0 + }, + { + input=> [236, 416, 336, 350], + output=> 1296 + }; diff --git a/challenge-261/kjetillll/perl/ch-2.pl b/challenge-261/kjetillll/perl/ch-2.pl new file mode 100644 index 0000000000..e8c2241641 --- /dev/null +++ b/challenge-261/kjetillll/perl/ch-2.pl @@ -0,0 +1,23 @@ +use strict; use warnings; + +sub f { + my $n = pop; + grep( $_ == $n, @_ ) ? f( @_, $n*2 ) : $n +} + +use Test::More tests => 3; +is( f( @{ $$_{input} }, $$_{start} ), $$_{output} ) for + { + input => [5,3,6,1,12], + start => 3, + output => 24}, + { + input => [1,2,4,3], + start => 1, + output => 8 + }, + { + input => [5,6,7], + start => 2, + output => 2 + }; |
