Anonymous user
SEDOLs: Difference between revisions
Updated for Nim 1.4: added missing parameter types. Done several other changes/improvements. Added output.
(Updated for Nim 1.4: added missing parameter types. Done several other changes/improvements. Added output.) |
|||
Line 2,449:
=={{header|Nim}}==
<lang nim>
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
const weight = [1, 3, 1, 7, 3, 9]▼
▲const weight = [1,3,1,7,3,9]
▲proc checksum(sedol): string =
▲ var tmp = 0
▲ for i,s in sedol:
▲ tmp += c2v(s) * weight[i]
for sedol in ["710889", "B0YBKJ", "406566", "B0YBLH",
▲ result = $((10 - (tmp mod 10)) mod 10)
"228276", "B0YBKL", "557910", "B0YBKR",
"585284", "B0YBKT", "B00030"]:
echo sedol, " → ", sedol & checksum(sedol)</lang>▼
{{out}}
<pre>710889 → 7108899
B0YBKJ → B0YBKJ7
406566 → 4065663
B0YBLH → B0YBLH2
228276 → 2282765
B0YBKL → B0YBKL9
557910 → 5579107
B0YBKR → B0YBKR5
585284 → 5852842
B0YBKT → B0YBKT7
B00030 → B000300</pre>
▲ echo sedol, checksum(sedol)</lang>
=={{header|OCaml}}==
|