in reply to Unique Character Combinations
Other clean-up is left as an exercise to the reader. ;)use strict; use warnings; print join "\n", comb( 'A' .. 'C' ); sub comb { my @c_out = (); push @c_out, permute( '', $_, @_ ) for ( 0 .. $#_ ); return @c_out; } sub permute { my @results; my ( $str, $depth, @chars ) = @_; if ( !$depth-- ) { foreach (@chars) { push @results, $str . $_; } } else { push @results, permute( $str . $chars[$_], $depth, @chars[ ( $_ + 1 ) .. ($#chars) ] ) for ( 0 .. $#chars ); } return @results; }
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Unique Character Combinations
by Roy Johnson (Monsignor) on May 02, 2005 at 15:24 UTC |