SEDOLs: Difference between revisions

Content added Content deleted
 
Line 2,408: Line 2,408:
=={{header|langur}}==
=={{header|langur}}==
{{trans|Go}}
{{trans|Go}}
<syntaxhighlight lang="langur">val .csd = fn(.code) {
<syntaxhighlight lang="langur">
switch len(.code) {
val csd = fn(code) {
switch len(code) {
case 0:
case 0:
return "nada, zip, zilch"
return "nada, zip, zilch"
Line 2,416: Line 2,417:
}
}


if .code -> re/[^B-DF-HJ-NP-TV-Z0-9]/ {
if code -> re/[^B-DF-HJ-NP-TV-Z0-9]/ {
return "invalid character(s)"
return "invalid character(s)"
}
}


val .weight = [1,3,1,7,3,9]
val weight = [1,3,1,7,3,9]


val .nums = s2n .code
val nums = s2n(code)
val .sum = for[=0] .i of .nums {
val sum = for[=0] i of nums {
_for += .nums[.i] * .weight[.i]
_for += nums[i] * weight[i]
}
}


string 9 - (.sum - 1) rem 10
string 9 - (sum - 1) rem 10
}
}


val .h = {
val h = {
# invalid...
# invalid...
"": 0,
"": 0,
Line 2,455: Line 2,456:
}
}


for .input in sort(keys .h) {
for input in sort(keys(h)) {
val .d = .csd(.input)
val d = csd(input)
if len(.d) > 1 {
if len(d) > 1 {
writeln .input, ": ", .d
writeln input, ": ", d
} else {
} else {
val .expect = string .h[.input]
val expect = h[input] -> string
write .input, .d
write input, d
writeln if .expect == .d {""} else {
writeln if expect == d {""} else {
" (SEDOL test failed; expected check digit {{.expect}})"}
" (SEDOL test failed; expected check digit {{expect}})"}
}
}
}
}