Editorial for ECOO '13 R1 P2 - The Luhn Algorithm


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Perform the Luhn Algorithm on the given number, but modify it to take account of the fact that the last digit is not there. After the sum step, isolate the last digit of the sum using the integer modulus (remainder) operator, then subtract this number from 10 to get the check digit.

Another Approach

From each credit card number, generate 10 candidates for all the possible check digits. Then run the Luhn algorithm on each candidate and find the one that comes out valid using the Luhn Algorithm.


Comments

There are no comments at the moment.