Name: Anonymous 2008-10-09 14:27
real 1m21.853s
user 1m21.070s
sys 0m0.165sThis is on a 1.8ghz c2d. Incremental string generator from charset (999999 passes). Can anyone think of a more efficient way?
my $alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 !?";
my $pass = "a";
for (my $i = 0; $i < 1000000; $i++) {
$pass = nextPass($pass, $alpha);
}
sub nextPass {
my ($in, $alpha) = @_;
my @pass = split //, $in;
my @set = split //, $alpha;
my $current = $#pass;
my $done = 0;
while (!$done) {
# is the current character the end of the set?
if ($pass[$current] eq $set[$#set]) {
# set the current character to the start of the set
$pass[$current] = $set[0];
# is the current character the beginning of the pass?
if ($current == 0) {
# add the start of the set to the end of the pass and finish
push(@pass, $set[0]);
$done = 1;
} else {
$current--;
}
} else {
my $spot = index($alpha, $pass[$current]) + 1;
$pass[$current] = $set[$spot];
$done = 1;
}
}
my $out = join "", @pass;
return $out;
}