aboutsummaryrefslogtreecommitdiff
path: root/challenge-053/mohammad-anwar
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-03-23 22:53:28 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-03-23 22:53:28 +0000
commitd33d09bd5df9bbc68a5e091886a92e616e2b48e6 (patch)
tree92dd5191e74ff2bf33eabcaa6db58997b9c307ee /challenge-053/mohammad-anwar
parent88db792b7d9dbe8347c886f5c0758cf82568abd1 (diff)
downloadperlweeklychallenge-club-d33d09bd5df9bbc68a5e091886a92e616e2b48e6.tar.gz
perlweeklychallenge-club-d33d09bd5df9bbc68a5e091886a92e616e2b48e6.tar.bz2
perlweeklychallenge-club-d33d09bd5df9bbc68a5e091886a92e616e2b48e6.zip
- Added Perl solution for the "Vowels String" task.
Diffstat (limited to 'challenge-053/mohammad-anwar')
-rw-r--r--challenge-053/mohammad-anwar/perl/ch-2.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-053/mohammad-anwar/perl/ch-2.pl b/challenge-053/mohammad-anwar/perl/ch-2.pl
new file mode 100644
index 0000000000..ade15bceda
--- /dev/null
+++ b/challenge-053/mohammad-anwar/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Algorithm::Combinatorics qw(combinations);
+
+my $count = $ARGV[0] // 2;
+die "ERROR: Invalid count $count.\n"
+ unless (($count >= 1) && ($count <= 5));
+
+my $chars = [qw(a e i o u)];
+
+if ($count == 1) {
+ print join "\n", @$chars;
+ print "\n";
+ exit;
+}
+
+my $iter = combinations($chars, $count);
+
+my $char_sets = [];
+while (my $char = $iter->next) {
+ push @$char_sets, join "", @$char;
+}
+
+my $rules = [
+ qr/a(?=[ie])/,
+ qr/e(?=[i])/,
+ qr/i(?=[aeou])/,
+ qr/o(?=[au])/,
+ qr/u(?=[oe])/
+];
+
+foreach my $char_set (@$char_sets) {
+ my $pass = 0;
+ foreach my $rule (@$rules) {
+ if ($char_set =~ /$rule/) {
+ $pass = 1;
+ }
+ }
+ print "$char_set\n" if ($pass);
+}