Jump to content

ISBN13 check digit: Difference between revisions

→‎{{header|langur}}: added langur 0.7.1 example
(→‎{{header|langur}}: added langur 0.7.1 example)
Line 187:
 
=={{header|langur}}==
{{works with|langur|0.7.1}}
<lang langur>val .isbn13checkdigit = f(.n) {
val .s = replace .n, RE/[\- ]/
matching(re/^[0-9]{13}$/, .s) and
fold(f{+}, map([_, f .d x 3], map(f .c-'0', s2cp .s))) rem 10 == 0
}
 
val .tests = h{
"978-1734314502": true,
"978-1734314509": false,
"978-1788399081": true,
"978-1788399083": false,
}
 
for .key in sort(keys .tests) {
val .pass = .isbn13checkdigit(.key)
write .key, ": ", if(.pass: "good"; "bad")
writeln if(.pass == .tests[.key]: ""; " (ISBN-13 CHECK DIGIT TEST FAILED)")
}</lang>
 
{{works with|langur|0.6.13}}
<lang langur>val .isbn13checkdigit = f(.n) {
1,007

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.