From 910aecb3c3aa5178b319feb858de187ba80aa103 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 16 Sep 2019 17:46:42 +0200 Subject: Add solution to 026/1 (stones & jewels) by E. Choroba Introduction of a new secret operator, +=()=, that could be called "Voyager approaching Saturn". --- challenge-026/e-choroba/perl5/ch-1.pl | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 challenge-026/e-choroba/perl5/ch-1.pl 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; + + + -- cgit