|
|
|
|
|
by peteretep
4933 days ago
|
|
And in some rather nicer Perl: sub solutions {
my ( $target_length, $alphabet, $head ) = @_;
$head //= '';
# Base Case our head is the right length
return $head if (length $head) == $target_length;
# General Case
return
map { generate( $target_length, $alphabet, $_ ) }
grep { ! /(.{2})\1/ }
map { $head . $_ }
@$alphabet;
}
eg: my @solutions = solutions( 5, [1..3] );
|
|