I doubt it'll beat the C version, but I think it should beat the Perl versions and the algorithm (which I think is correct but haven't verified) would readily convert to C:
sub luhn { my $total = 0; for my $i ( 0 .. length $_[0] ) { my $d = substr $_[0], $i, 1 ); if( $i & 1 ) { $d *= 2; $s -=9 if $d > 10; } $total += $d; } $total *= 9; return substr $total, -1 }
In reply to Re: Faster Luhn Check Digit Calculation?
by BrowserUk
in thread Faster Luhn Check Digit Calculation?
by kschwab
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |