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;
}
1. don't use perl for c's job
2. don't do a string scan every time you want to know what number you just stored
3. don't convert between strings and arrays on every pass
4. write it in fucking c goddamn
Name:
Anonymous2008-10-09 16:27
Such a waste of precious CPU power should make you sick. Man up and learn ASM.
My computer is a wee bit faster than his, so the perl script clocked in at 45 seconds, while mine is 0.008.
45/0.008 = 5625 times faster.
Name:
Anonymous2008-10-09 21:07
Wait, my code includes a syscall to print the output, while his stays silent.
After removing the syscall it's 0.004, so 11250 times faster.
Name:
Anonymous2008-10-09 21:51
>>11
I did read the first 3 lines, but 0,008 is not a number.
Name:
Anonymous2008-10-09 21:57
One word, the forced Europification of the numbers.
Name:
Anonymous2008-10-09 23:01
>>14
In European countries, the comma character is used as the decimal separator, whereas in the US and other countries the period is used.
Name:
Anonymous2008-10-09 23:40
>>9
That's great and all, but you don't really factor in the ``writing-to-a-file'' aspect of the program. I'd imagine including file writing would increase the elapsed time by a lot.
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;
}
And, >>9, fuck you, this should work with unicode strings. Go back to seventies with your ascii.
Name:
Anonymous2008-10-10 2:40
>>20
Dictionary generators have a wide application of uses oh God what am I saying. I think I'm starting to lose my mind, but as long as I know I'm losing my mind I can't possibly be losing my mind