Task

For each number list of 6-digit SEDOLs, calculate and append the checksum digit.



That is, given this input:

710889
B0YBKJ
406566
B0YBLH
228276
B0YBKL
557910
B0YBKR
585284
B0YBKT
B00030

Produce this output:

7108899
B0YBKJ7
4065663
B0YBLH2
2282765
B0YBKL9
5579107
B0YBKR5
5852842
B0YBKT7
B000300

Extra credit

Check each input is correctly formed, especially with respect to valid characters allowed in a SEDOL string.



Related tasks

   Luhn test
   ISIN


INT FUNC SedolChecksum(CHAR ARRAY sedol)
  BYTE ARRAY weights=[1 3 1 7 3 9]
  INT i,sum
  CHAR c
 
  IF sedol(0)#6 THEN
    RETURN (-1)
  FI
 
  sum=0
  FOR i=1 TO sedol(0)
  DO
    c=sedol(i)
    IF c>='0 AND c<='9 THEN
      sum==+(c-'0)*weights(i-1)
    ELSE
      IF c>='a AND c<='z THEN
        c==-'a-'A
      FI
      IF c='A OR c='E OR c='I OR c='O OR c='U THEN
        RETURN (-1)
      ELSEIF c>='A AND c<='Z THEN
        sum==+(c-'A+10)*weights(i-1)
      ELSE
        RETURN (-1)
      FI
    FI
  OD
  sum=(10-(sum MOD 10)) MOD 10
RETURN (sum)
 
PROC Test(CHAR ARRAY sedol)
  INT res
 
  res=SedolChecksum(sedol)  
  Print(sedol) Print(" -> ")
  IF res>=0 THEN
    Print(sedol) PrintIE(res)
  ELSE
    PrintE("invalid input")
  FI
RETURN
 
PROC Main()
  Test("710889")
  Test("B0YBKJ")
  Test("406566")
  Test("B0YBLH")
  Test("228276")
  Test("B0YBKL")
  Test("557910")
  Test("B0YBKR")
  Test("585284")
  Test("B0YBKT")
  Test("B00030")
  Test("12345A")
  Test("12345")
  Test("1234567")
RETURN