blob: 719f58ddcc3cf382055c2c3e5d7731f4d22303e7 (
plain)
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
|
#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };
my %next = (
a => [qw[ e i ]],
e => [qw[ i ]],
i => [qw[ a e o u ]],
o => [qw[ a u ]],
u => [qw[ o e ]]);
my $n = shift;
die "Invalid argument" unless ($n // "") =~ /^[1-5]$/;
my @agenda = sort keys %next;
while ($n > length $agenda[0]) {
my @next;
for my $string (@agenda) {
my $last = substr $string, -1;
push @next, map $string . $_, @{ $next{$last} };
}
@agenda = @next;
}
say for @agenda;
|