Hello
I need to check that the NHS numbers in my database are valid. I’m
storing them as tendigit strings: the first nine are the identifier and
the tenth is a check digit.
There are four steps to calculating the check digit (from
http://www.connectingforhealth.nhs.uk/systemsandservices/nsts/docs/tech_nn_check_digit.pdf):

multiply each of the first nine digits by a weighting factor (10 for
the first digit, 9 for the second… 2 for the ninth) 
sum the results of these multiplications

divide the total by 11 and establish the remainder

subtract the remainder from 11 to give the check digit.
If the result of step 4 is 11 a check digit of 0 is used; if the result
is 10 then the number is invalid.
I’m struggling to implement this into my model. I imagine that the first
thing is to convert the string to an array:
nhs_no = “1234567890”
nhs_no.split("").map{ v v.to_i } # => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Then I get a bit stuck (i.e. before step 1!): I want to transform the
first nine digits of the array so that the new value of the kth element
is v*(10k).
I hope this makes some sense, and I’d really appreciate any help.
Thanks.