Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -1,18 +1,18 @@
|
|||
val .isbn13checkdigit = fn(var .s) {
|
||||
.s = replace(.s, RE/[\- ]/)
|
||||
.s -> re/^[0-9]{13}$/ and
|
||||
fold(fn{+}, map [_, fn{*3}], s2n .s) div 10
|
||||
val isbn13checkdigit = fn(var s) {
|
||||
s = replace(s, RE/[\- ]/)
|
||||
s -> re/^[0-9]{13}$/ and
|
||||
fold(fn{+}, map([_, fn{*3}], s2n(s))) div 10
|
||||
}
|
||||
|
||||
val .tests = h{
|
||||
val tests = {
|
||||
"978-0596528126": true,
|
||||
"978-0596528120": false,
|
||||
"978-1788399081": true,
|
||||
"978-1788399083": false,
|
||||
}
|
||||
|
||||
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)")
|
||||
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)")
|
||||
}
|
||||
|
|
|
|||
22
Task/ISBN13-check-digit/Standard-ML/isbn13-check-digit-1.ml
Normal file
22
Task/ISBN13-check-digit/Standard-ML/isbn13-check-digit-1.ml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(* these type decorations are optional, you could just as well put:
|
||||
fun isValidISBN s =
|
||||
*)
|
||||
fun isValidISBN (s : string) : bool =
|
||||
let
|
||||
val digits = List.filter Char.isDigit (explode s)
|
||||
val nums = map (fn x => ord x - ord #"0") digits
|
||||
val len = length nums
|
||||
fun sumISBN [] = raise Domain
|
||||
| sumISBN [x] = x
|
||||
| sumISBN (x1::x2::xs) = x1 + 3*x2 + sumISBN xs
|
||||
in
|
||||
len = 13 andalso sumISBN nums mod 10 = 0
|
||||
end
|
||||
|
||||
val test = ["978-1734314502", "978-1734314509",
|
||||
"978-1788399081", "978-1788399083"]
|
||||
|
||||
fun printTest (s : string) : unit =
|
||||
(print s; print (if isValidISBN s then ": good\n" else ": bad\n"))
|
||||
|
||||
fun main () = app printTest test
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
local
|
||||
let
|
||||
fun check (c, p as (m, n)) =
|
||||
if Char.isDigit c then
|
||||
(not m, (if m then 3 * (ord c - 48) else ord c - 48) + n)
|
||||
Loading…
Add table
Add a link
Reference in a new issue