SEDOLs: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 2,408: | Line 2,408: | ||
=={{header|langur}}== |
=={{header|langur}}== |
||
{{trans|Go}} |
{{trans|Go}} |
||
<syntaxhighlight lang="langur"> |
<syntaxhighlight lang="langur"> |
||
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 |
if code -> re/[^B-DF-HJ-NP-TV-Z0-9]/ { |
||
return "invalid character(s)" |
return "invalid character(s)" |
||
} |
} |
||
val |
val weight = [1,3,1,7,3,9] |
||
val |
val nums = s2n(code) |
||
val |
val sum = for[=0] i of nums { |
||
_for += |
_for += nums[i] * weight[i] |
||
} |
} |
||
string 9 - ( |
string 9 - (sum - 1) rem 10 |
||
} |
} |
||
val |
val h = { |
||
# invalid... |
# invalid... |
||
"": 0, |
"": 0, |
||
Line 2,455: | Line 2,456: | ||
} |
} |
||
for |
for input in sort(keys(h)) { |
||
val |
val d = csd(input) |
||
if len( |
if len(d) > 1 { |
||
writeln |
writeln input, ": ", d |
||
} else { |
} else { |
||
val |
val expect = h[input] -> string |
||
write |
write input, d |
||
writeln if |
writeln if expect == d {""} else { |
||
" (SEDOL test failed; expected check digit {{ |
" (SEDOL test failed; expected check digit {{expect}})"} |
||
} |
} |
||
} |
} |