in reply to Re: Algorithm for "Incrementing" strings
in thread Algorithm for "Incrementing" strings
And with only a few tweaks, we can decrement strings:
#!/usr/bin/perl use strict; use warnings; my $consonants = 'BCDFGHJKLMNPQRSTVWXZ'; my @letters = split //, $consonants; my ($first, $last) = @letters[0, -1]; my %prev; @prev{@letters} = ('', @letters); my $x = 'BCD'; while( length $x ) { print "$x "; $x =~ s/(.)($first*)$/ $prev{$1} . $last x length $2 /e; } print "\n";
|
---|