ISBN13 check digit: Difference between revisions
Optimized routine beyond the specs of my original one
(Added more general routine) |
(Optimized routine beyond the specs of my original one) |
||
Line 1,170:
=={{header|Forth}}==
The following
<lang>: is-digit [char] 0 - 10 u< ;
: isbn? ( a n -- f)
1-
▲The following slightly modified word not only identifies correct 13 digit ISBN (and EAN) codes, but also 8 digit EAN and GTIN codes:
dup i c@ dup is-digit \ get length and factor, setup loop
if [char] 0 - * rot + swap 3 * 8 mod else drop drop then
-1 chars +loop drop 10 mod 0=
;</lang>
{{out}}
|