16 lines
408 B
Text
16 lines
408 B
Text
isISBN13 = function(n)
|
|
n = n.replace("-","").replace(" ","")
|
|
s = 0
|
|
for i in range(0, n.len-1,2)
|
|
s += n[i].val
|
|
end for
|
|
for i in range(1, n.len-1,2)
|
|
s += n[i].val * 3
|
|
end for
|
|
return not (s % 10)
|
|
end function
|
|
|
|
testValues = "978-0596528126 978-0596528120 978-1788399081 978-1788399083".split(" ")
|
|
for val in testValues
|
|
print val + " " + ["bad", "good"][isISBN13(val)]
|
|
end for
|