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


codes = 710889,B0YBKJ,406566,B0YBLH,228276,B0YBKL,557910,B0YBKR,585284,B0YBKT,B00030,ABCDEF,BBBBBBB
Loop, Parse, codes, `,
    output .= A_LoopField "`t-> " SEDOL(A_LoopField) "`n"
Msgbox %output%
 
SEDOL(code) {
    Static weight1:=1, weight2:=3, weight3:=1, weight4:=7, weight5:=3, weight6:=9
    If (StrLen(code) != 6)
        Return "Invalid length."
    StringCaseSense On
    Loop, Parse, code
        If A_LoopField is Number
            check_digit += A_LoopField * weight%A_Index%
        Else If A_LoopField in B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z
            check_digit += (Asc(A_LoopField)-Asc("A") + 10) * weight%A_Index%
        Else
            Return "Invalid character."
    Return code . Mod(10-Mod(check_digit,10),10)
}