aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorE. Choroba <choroba@matfyz.cz>2019-09-16 17:46:42 +0200
committerE. Choroba <choroba@matfyz.cz>2019-09-16 17:46:42 +0200
commit910aecb3c3aa5178b319feb858de187ba80aa103 (patch)
tree21dce42f9bc06e7939dfd9312f01699fa194e474
parentb46a93f225908da05ff54d40728c59ad8adf7c18 (diff)
downloadperlweeklychallenge-club-910aecb3c3aa5178b319feb858de187ba80aa103.tar.gz
perlweeklychallenge-club-910aecb3c3aa5178b319feb858de187ba80aa103.tar.bz2
perlweeklychallenge-club-910aecb3c3aa5178b319feb858de187ba80aa103.zip
Add solution to 026/1 (stones & jewels) by E. Choroba
Introduction of a new secret operator, +=()=, that could be called "Voyager approaching Saturn".
-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;
+
+
+