SEDOLs: Difference between revisions

310 bytes added ,  3 years ago
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>importproc strutilsc2v(c: char): int =
 
proc c2v(c): int =
assert c notin "AEIOU"
if c < 'A': ord(c) - ord('0') else: ord(c) - ord('7')
let a = ord(c)
if a < 65: a - 48
const weight = [1, 3, 1, 7, 3, 9]
else: a - 55
 
proc checksum(sedol): string): char =
const weight = [1,3,1,7,3,9]
var tmpval = 0
 
for i,s ch in sedol:
proc checksum(sedol): string =
tmpval += c2v(sch) * weight[i]
var tmp = 0
result = $chr((10 - (tmpval mod 10)) mod 10 + ord('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}}
for sedol in """710889
<pre>710889 → 7108899
B0YBKJ
B0YBKJ → B0YBKJ7
406566
406566 → 4065663
B0YBLH
B0YBLH → B0YBLH2
228276
228276 → 2282765
B0YBKL
B0YBKL → B0YBKL9
557910
557910 → 5579107
B0YBKR
B0YBKR → B0YBKR5
585284
585284 → 5852842
B0YBKT
B0YBKT → B0YBKT7
B00030""".splitLines():
B00030 → B000300</pre>
echo sedol, checksum(sedol)</lang>
 
=={{header|OCaml}}==
Anonymous user