This algorith fails on '49927398716' in my test case. That was the code given on the LUHN-10 website. It comes up with a sum of 62 when it should be a sum of 70 per the original algorithm.

I am curious if you can explain how the

($sum += chop $number) ... ($sum += $LUHN10_map[chop $number]) while $ +number ne '';
logic works. I just (like 1 minute ago) learned about the bi-stable operator.


While typing this, I figured out why this failed my test case. The call to '...' is persistant across subroutine calls. In my test case, I use

('125', '49927398716', '4992739872')
and it failed on '49927398716'. When I used
('125', '49927398716', '49927398716','4992739872')
it failed on the 1st '49927398716' and on '4992739872' so I can only assume this operator maintains its state.

UPDATE: This also fails on '620' since the bi-stable does not flip state if the side that is being evaluated returns false(or 0). So a number ending in '0' will not be processed correctly.


In reply to Re: (dkubb) Re: (2) YAL10CI (Yet Another LUHN-10 Checksum Implementation) by johannz
in thread YAL10CI (Yet Another LUHN-10 Checksum Implementation) by larryl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.