58 lines
1.1 KiB
Text
58 lines
1.1 KiB
Text
val .csd = fn(.code) {
|
|
switch len(.code) {
|
|
case 0:
|
|
return "nada, zip, zilch"
|
|
case != 6:
|
|
return "invalid length"
|
|
}
|
|
|
|
if .code -> re/[^B-DF-HJ-NP-TV-Z0-9]/ {
|
|
return "invalid character(s)"
|
|
}
|
|
|
|
val .weight = [1,3,1,7,3,9]
|
|
|
|
val .nums = s2n .code
|
|
val .sum = for[=0] .i of .nums {
|
|
_for += .nums[.i] * .weight[.i]
|
|
}
|
|
|
|
string 9 - (.sum - 1) rem 10
|
|
}
|
|
|
|
val .h = h{
|
|
# invalid...
|
|
"": 0,
|
|
"123": 0,
|
|
"A00030": 0,
|
|
"E00030": 0,
|
|
"I00030": 0,
|
|
"O00030": 0,
|
|
"U00030": 0,
|
|
"β00030": 0,
|
|
|
|
# valid...
|
|
"710889": 9,
|
|
"B0YBKJ": 7,
|
|
"406566": 3,
|
|
"B0YBLH": 2,
|
|
"228276": 5,
|
|
"B0YBKL": 9,
|
|
"557910": 7,
|
|
"B0YBKR": 5,
|
|
"585284": 2,
|
|
"B0YBKT": 7,
|
|
"B00030": 0,
|
|
}
|
|
|
|
for .input in sort(keys .h) {
|
|
val .d = .csd(.input)
|
|
if len(.d) > 1 {
|
|
writeln .input, ": ", .d
|
|
} else {
|
|
val .expect = string .h[.input]
|
|
write .input, .d
|
|
writeln if .expect == .d {""} else {
|
|
$" (SEDOL test failed; expected check digit \.expect;)"}
|
|
}
|
|
}
|