diff options
| -rwxr-xr-x | challenge-026/e-choroba/perl5/ch-1.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-026/e-choroba/perl5/ch-1.pl b/challenge-026/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..221d562b1c --- /dev/null +++ b/challenge-026/e-choroba/perl5/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use List::Util qw{ uniq }; + +sub count { + my %args = @_; + my $count = 0; + $count += () = $args{jewels} =~ /$_/g for uniq(split //, $args{stones}); + $count +} + +use Test::More tests => 6; + +is count(stones => 'a', jewels => 'b'), 0; +is count(stones => 'a', jewels => 'ab'), 1; +is count(stones => 'a', jewels => 'ababa'), 3; +is count(stones => 'aa', jewels => 'ababa'), 3; +is count(stones => 'aabb', jewels => 'ababac'), 5; +is count(stones => 'chancellor', jewels => 'chocolate'), 8; + + + |
