Damm algorithm: Difference between revisions

Content added Content deleted
(→‎static table: simplified and optimized the code.)
Line 1,214:
@.0= 0317598642; @.1= 7092154863; @.2= 4206871359; @.3= 1750983426; @.4= 6123045978
@.5= 3674209581; @.6= 5869720134; @.7= 8945362017; @.8= 9438617205; @.9= 2581436790
call Damm 5724, 5727, 112946, 112940 /*invoke Damm's algorithm for some #'s.*/
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
Damm: arg z; do j=1 for wordsarg(z); x= arg(j); x= word(z, j) $= 0; L z= lengthright(x, 1)
do $p=1 0; for length(x); g=$; $= substr(@.$, 1 + substr(x, p, 1), VCD= 'valid checksum digit '1)
end /*p*/
do p=1 for L; g=$; $= substr(@.$, 1 + substr(x, p, 1), 1)
if $==0 then say ' valid checksum digit ' z " endfor " /*p*/x
if $==0 thenelse say ' invalid 'checksum VCDdigit ' right(x,1) z " for " x ' (should be' g")"
end /*j*/; else say ' in'VCD right(x,1) " for " x ' (should be' g")"return</lang>
end /*j*/; return</lang>
{{out|output|text=&nbsp; when using the (internal) default inputs:}}
<pre>