diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-05-14 22:26:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-14 22:26:07 +0100 |
| commit | db13649c6e1a3610120bd5fdffba0194625f6d4e (patch) | |
| tree | d62376a3e75c74e59a6a73731e0d777be6b08c0f | |
| parent | a3e809db1e8a1e2168d9ceaaa2e8a24d25419bdb (diff) | |
| parent | db3e48a9c0361d0c90539f45f488f3961c172093 (diff) | |
| download | perlweeklychallenge-club-db13649c6e1a3610120bd5fdffba0194625f6d4e.tar.gz perlweeklychallenge-club-db13649c6e1a3610120bd5fdffba0194625f6d4e.tar.bz2 perlweeklychallenge-club-db13649c6e1a3610120bd5fdffba0194625f6d4e.zip | |
Merge pull request #8071 from Solathian/branch-for-challenge-216
Added file for challenge
| -rw-r--r-- | challenge-216/solathian/perl/ch-1.pl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-216/solathian/perl/ch-1.pl b/challenge-216/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..5dd374ee8f --- /dev/null +++ b/challenge-216/solathian/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!usr/bin/perl +use v5.36; + + +# Challenge 216 - 1 - Registration Number +# You are given a list of words and a random registration number. +# Write a script to find all the words in the given list that has every letter in the given registration number. + +regNum('AB1 2CD', ('abc', 'abcd', 'bcd')); # abcd +regNum('007 JB', ('job', 'james', 'bjorg')); # ('job', 'bjorg') +regNum('C7 RA2', ('crack', 'road', 'rac')); # ('crack', 'rac') + +sub regNum($reg, @wordlist) +{ + $reg =~ s"\d|\s""g; + + my @resultArr; + + OUTER: + foreach my $word (@wordlist) + { + foreach my $char (split('', $reg)) + { + next OUTER if( $word !~ /$char/i) + } + push(@resultArr, $word); + } + + say join(', ', @resultArr); +}
\ No newline at end of file |
