ISBN13 check digit: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add BCPL) |
(Added Forth version) |
||
Line 1,167: | Line 1,167: | ||
978-1788399081: good |
978-1788399081: good |
||
978-1788399083: bad |
978-1788399083: bad |
||
</pre> |
|||
=={{header|Forth}}== |
|||
<lang>: is-digit [char] 0 - 10 u< ; |
|||
: isbn? ( a n -- f) |
|||
1- 2dup chars + c@ [char] 0 - >r 2>r 0 1 2r> bounds ?do |
|||
dup i c@ dup is-digit |
|||
if [char] 0 - * rot + swap 3 * 8 mod else drop drop then |
|||
loop drop r> + 10 mod 0= |
|||
;</lang> |
|||
{{out}} |
|||
In Forth, a "true" value is indicated by "-1". |
|||
<pre> |
|||
s" 978-1734314502" isbn? . -1 ok |
|||
s" 978-1734314509" isbn? . 0 ok |
|||
s" 978-1788399081" isbn? . -1 ok |
|||
s" 978-1788399083" isbn? . 0 ok |
|||
</pre> |
</pre> |
||