aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-09-16 16:52:33 +0100
committerGitHub <noreply@github.com>2019-09-16 16:52:33 +0100
commit2cb6f59208fc4284cdcef4efe63fbd12564edb9b (patch)
tree21dce42f9bc06e7939dfd9312f01699fa194e474
parentb46a93f225908da05ff54d40728c59ad8adf7c18 (diff)
parent910aecb3c3aa5178b319feb858de187ba80aa103 (diff)
downloadperlweeklychallenge-club-2cb6f59208fc4284cdcef4efe63fbd12564edb9b.tar.gz
perlweeklychallenge-club-2cb6f59208fc4284cdcef4efe63fbd12564edb9b.tar.bz2
perlweeklychallenge-club-2cb6f59208fc4284cdcef4efe63fbd12564edb9b.zip
Merge pull request #638 from choroba/ech-026-1
Add solution to 026/1 (stones & jewels) by E. Choroba
-rwxr-xr-xchallenge-026/e-choroba/perl5/ch-1.pl24
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;
+
+
+