aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-053/markus-holzer/perl/ch-2.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-053/markus-holzer/perl/ch-2.pl b/challenge-053/markus-holzer/perl/ch-2.pl
new file mode 100644
index 0000000000..f2973a3da7
--- /dev/null
+++ b/challenge-053/markus-holzer/perl/ch-2.pl
@@ -0,0 +1,39 @@
+use Modern::Perl;
+use feature qw( signatures postderef switch );
+no warnings qw(experimental);
+
+my %rules = (
+ a => [ 'e', 'i' ],
+ e => [ 'i' ],
+ i => [ 'a', 'e', 'o', 'u' ],
+ o => [ 'a', 'u' ],
+ u => [ 'e', 'o' ],
+);
+
+main( shift @ARGV || 2 );
+
+sub main( $n )
+{
+ my @r;
+
+ build_str( $_, $n, \@r )
+ for ( sort keys %rules );
+
+ print join "\n", @r;
+}
+
+sub build_str( $current, $n, $result )
+{
+ my $last = substr( $current, -1 );
+
+ for ( $rules{ $last }->@* )
+ {
+ given ( $current . $_ )
+ {
+ push $result->@*, $_ and next
+ if length($_) == $n;
+
+ build_str( $_, $n, $result );
+ }
+ }
+} \ No newline at end of file