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


 
'adapted from BASIC solution
    mult(1) = 1: mult(2) = 3: mult(3) = 1
    mult(4) = 7: mult(5) = 3: mult(6) = 9
 
DO
        INPUT a$
        PRINT a$ + STR$(getSedolCheckDigit(a$))
LOOP WHILE a$ <> ""
 
FUNCTION getSedolCheckDigit (str$)
    IF LEN(str$) <> 6 THEN
        PRINT "Six chars only please"
        EXIT FUNCTION
    END IF
    str$ = upper$(str$)
    total = 0
    FOR i = 1 TO 6
        s$ = MID$(str$, i, 1)
        IF (s$ = "A") OR (s$ = "E") OR (s$ = "I") OR (s$ = "O") OR (s$ = "U") THEN
                PRINT "No vowels"
                EXIT FUNCTION
        END IF
        IF (ASC(s$) >= 48) AND (ASC(s$) <= 57) THEN
                total = total + VAL(s$) * mult(i)
        ELSE
                total = total + (ASC(s$) - 55) * mult(i)
        END IF
 
    NEXT i
    getSedolCheckDigit = (10 - (total MOD 10)) MOD 10
END FUNCTION
 