in reply to Unique Character Combinations

A non-recursive solution (benchmarks about half as fast as powerset with sort, somewhat disappointingly). The idea is that, for example, A in generation 1 becomes AB, AC, AD in generation 2. B in generation 1 becomes BC, BD in generation 2. Each entry in a generation is mapped to each of the characters after its last character to create the next generation.
sub comb { my @alphabet = @_; my @generation = (['', 0]); my @return; while (@generation) { my @next_generation; for my $gen (@generation) { my ($base, $start_at) = @$gen; for my $i ($start_at..$#alphabet) { my $new_str = $base.$alphabet[$i]; push @return, $new_str; push @next_generation, [$new_str, $i+1] if $i < $#alph +abet; } } @generation = @next_generation; } @return; }

Caution: Contents may have been coded under pressure.