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


SEDOL
 NEW A,B
SEDOL1
 READ !,"Enter the first 6 digits of a SEDOL: ",A
 SET B=$$SEDOLCHK(A)
 WRITE !,$SELECT($LENGTH(B)=1:"Full SEDOL is "_A_B,1:B)
 GOTO SEDOL1
 QUIT
SEDOLCHK(STOCK)
 NEW WT,VAL,I,CHK,C,FLAG
 SET WT="1317391",VAL=0,FLAG=0
 FOR I=1:1:6 SET C=$$TOUPPER($EXTRACT(STOCK,I)),VAL=VAL+($$SEDVAL(C)*$EXTRACT(WT,I)) SET:"AEIOUaeiou"[C FLAG=1
 SET:$LENGTH(STOCK)'=6 FLAG=1
 KILL WT,I,CHK,C
 QUIT $SELECT(FLAG:"INVALID",'FLAG:(10-(VAL#10))#10)
SEDVAL(X)
 QUIT $SELECT($ISVALIDNUM(X):X,1:$ASCII(X)-$ASCII("@")+9)
TOUPPER(X)
 NEW UP,LO
 SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ",LO="abcdefghijklmnopqrstuvwxyz"
 QUIT $TRANSLATE(X,LO,UP)