in reply to Re^2: Faster Luhn Check Digit Calculation?
in thread Faster Luhn Check Digit Calculation?
... why not a string of digits together at the same time?
If I correctly understand what you're saying, something like
my $check_digits = join '', map { chr((10 - $_ % 10) % 10) } 0 .. 9 * $n_digits;
...
return substr $check_digits $total, 1;
(returning the check digit as a character) certainly would be a more memory-conservative approach than using an array of, e.g., 136 numbers. However, my suspicion is that when you get through with the substr call, you've burned about as much time as with the just-as-simple $total *= 9; return chop $total; calls.
6 digits are 1 million entries ...
I don't understand this point: where do the 1 million entries come from? Would you be building a lookup string from every possible 6-digit combination? The OPed question posited 15 digits; that's a really long string.
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Faster Luhn Check Digit Calculation?
by LanX (Saint) on Dec 02, 2018 at 02:01 UTC | |
by AnomalousMonk (Archbishop) on Dec 02, 2018 at 02:47 UTC | |
by LanX (Saint) on Dec 02, 2018 at 02:59 UTC | |
by LanX (Saint) on Dec 02, 2018 at 03:09 UTC |