ISBN13 check digit: Difference between revisions
Content added Content deleted
Alpha bravo (talk | contribs) (Added AutoHotkey) |
|||
Line 504: | Line 504: | ||
return ((sum + ISBN13) mod 10 = 0) |
return ((sum + ISBN13) mod 10 = 0) |
||
end validateISBN13</lang> |
end validateISBN13</lang> |
||
=={{header|AutoHotkey}}== |
|||
<lang AutoHotkey>ISBN13_check_digit(n){ |
|||
for i, v in StrSplit(RegExReplace(n, "[^0-9]")) |
|||
sum += !Mod(i, 2) ? v*3 : v |
|||
return n "`t" (Mod(sum, 10) ? "(bad)" : "(good)") |
|||
}</lang> |
|||
Examples:<lang AutoHotkey>output := "" |
|||
nums := ["978-1734314502","978-1734314509","978-1788399081","978-1788399083"] |
|||
for i, n in nums |
|||
output .= ISBN13_check_digit(n) "`n" |
|||
MsgBox % output |
|||
return</lang> |
|||
{{out}} |
|||
<pre>978-1734314502 (good) |
|||
978-1734314509 (bad) |
|||
978-1788399081 (good) |
|||
978-1788399083 (bad)</pre> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |