ISBN13 check digit: Difference between revisions

Line 1,970:
=={{header|langur}}==
In this example, we map to multiple functions (actually 1 no-op).
<syntaxhighlight lang="langur">val .isbn13checkdigit = fn(var .s) {
val isbn13checkdigit = fn(var s) {
.s = replace(.s, RE/[\- ]/)
.s ->= rereplace(s, RE/^[0\-9 ]{13}$/ and)
s -> re/^[0-9]{13}$/ and
fold(fn{+}, map ([_, fn{*3}], s2n .(s))) div 10
}
 
val .tests = {
"978-0596528126": true,
"978-0596528120": false,
Line 1,983 ⟶ 1,984:
}
 
for .key of .tests {
val .pass = .isbn13checkdigit(.key)
write .key, ": ", if(.pass: "good"; "bad")
writeln if(.pass == .tests[.key]: ""; " (ISBN-13 CHECK DIGIT TEST FAILED)")
}
}</syntaxhighlight>
 
{{out}}
1,007

edits