ISBN13 check digit: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add ABC) |
Not a robot (talk | contribs) (Add SETL) |
||
Line 2,936: | Line 2,936: | ||
978-1788399083: FALSE |
978-1788399083: FALSE |
||
</pre> |
</pre> |
||
=={{header|SETL}}== |
|||
<syntaxhighlight lang="setl">program isbn13; |
|||
loop for test in [ |
|||
"978-0596528126", "978-0596528120", |
|||
"978-1788399081", "978-1788399083" |
|||
] do |
|||
print(test + if valid_isbn13 test then ": good" else ": bad" end); |
|||
end loop; |
|||
op valid_isbn13(isbn); |
|||
if #isbn /= 14 |
|||
or isbn(4) /= '-' |
|||
or exists c in isbn | not c in "0123456789-" then |
|||
return false; |
|||
end if; |
|||
m := 3; |
|||
loop for ch in isbn | ch in "0123456789" do |
|||
s +:= val ch * (m := 4 - m); |
|||
end loop; |
|||
return s mod 10 = 0; |
|||
end op; |
|||
end program;</syntaxhighlight> |
|||
{{out}} |
|||
<pre>978-0596528126: good |
|||
978-0596528120: bad |
|||
978-1788399081: good |
|||
978-1788399083: bad</pre> |
|||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |