From db3e48a9c0361d0c90539f45f488f3961c172093 Mon Sep 17 00:00:00 2001 From: Solathian Date: Sun, 14 May 2023 20:02:02 +0200 Subject: Added file for challenge --- challenge-216/solathian/perl/ch-1.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-216/solathian/perl/ch-1.pl 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 -- cgit