Damm algorithm: Difference between revisions

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