in reply to Re^4: Faster Luhn Check Digit Calculation?
in thread Faster Luhn Check Digit Calculation?

L("XXYY") = ( L("XX") + L("YY") ) % 10

for all even length substrings XX and YY ...

I think I see where you're going, and I think you're right. Even with just a 0 .. 9999 / 10K character lookup string, a 13-16 digit number's Luhn checksum character could be found with four substr lookups, three adds and a mod; likely quite fast. Going to six digits would only reduce by one lookup and one add; I'm not sure it would be worth the memory. Looks like you've found a nice project to occupy your Sunday :)


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^6: Faster Luhn Check Digit Calculation?
by LanX (Saint) on Dec 02, 2018 at 02:59 UTC
    > Looks like you've found a nice project to occupy your Sunday :)

    Nay!

    You know the saying: mathematicians are like eunuchs. ;)

    I leave the "fun" - especially with C - to the engineers here ...

    > six digits would only reduce by one 

    Well you were the one talking about a general approach with unknown input length.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Re^6: Faster Luhn Check Digit Calculation?
by LanX (Saint) on Dec 02, 2018 at 03:09 UTC
    > 10k lookup string

    FWIW this could be halved to 5k by addressing nibbles instead of bytes.

    4 bits are more than enough to encode 10 digits.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice