/
ch-2.pl
executable file
·37 lines (24 loc) · 871 Bytes
/
ch-2.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/perl
=pod
The Weekly Challenge - 239
- https://theweeklychallenge.org/blog/perl-weekly-challenge-239
Author: Niels 'PerlBoy' van Dijke
Task 2: Consistent Strings
Submitted by: Mohammad S Anwar
You are given an array of strings and allowed string having distinct characters.
|| A string is consistent if all characters in the string appear in the string allowed.
Write a script to return the number of consistent strings in the given array.
=cut
use v5.32;
use common::sense;
use feature 'signatures';
use Test::More;
sub consistentStrings ($allowed,@strings) {
my $re = "[^$allowed]";
grep { length and !/$re/ } @strings;
}
is(consistentStrings('ab',qw(ad bd aaab baa badab)),2);
is(consistentStrings('abc',qw(a b c ab ac bc abc)),7);
is(consistentStrings('cad',qw(cc acd b ba bac bad ac d)),4);
is(consistentStrings('a','a',''),1);
done_testing;