in reply to Faster Luhn Check Digit Calculation?
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 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Faster Luhn Check Digit Calculation?
by kschwab (Vicar) on Nov 30, 2018 at 20:41 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2018 at 02:12 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2018 at 02:54 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2018 at 07:31 UTC | |
by kschwab (Vicar) on Dec 01, 2018 at 15:24 UTC | |
by BrowserUk (Patriarch) on Dec 01, 2018 at 20:19 UTC | |
|