35 lines
729 B
Text
35 lines
729 B
Text
local function sedol(s)
|
|
if not(type(s) == "string" and #s == 6) then return false end
|
|
local weights = {1, 3, 1, 7, 3, 9}
|
|
local sum = 0
|
|
for i = 1, 6 do
|
|
local c = s[i]
|
|
if not c:isupper() and not(c in "0123456789") then
|
|
return nil
|
|
end
|
|
if c in "AEIOU" then return nil end
|
|
sum += tonumber(c, 36) * weights[i]
|
|
end
|
|
local cd = (10 - sum % 10) % 10
|
|
return s .. $"{cd}"
|
|
end
|
|
|
|
local tests = {
|
|
"710889",
|
|
"B0YBKJ",
|
|
"406566",
|
|
"B0YBLH",
|
|
"228276",
|
|
"B0YBKL",
|
|
"557910",
|
|
"B0YBKR",
|
|
"585284",
|
|
"B0YBKT",
|
|
"B00030",
|
|
"I23456"
|
|
}
|
|
|
|
for tests as test do
|
|
local ans = sedol(test) ?? "not valid"
|
|
print($"{test} -> {ans}")
|
|
end
|