# Incorrect mastercard number in pset1 [duplicate]

by lunh algoritm result of calculating 5105105105105100 will be 25 and it means that this card is invalid, but check50 output this:

:( identifies 5105105105105100 as MASTERCARD expected "MASTERCARD\n", not "INVAlID\n"

Why it happening and how correct it ???

## 1 Answer

I'm not sure where you went wrong, but don't forget doubling the digits always starts with the second-to-last.

``````5 * 2 = 10 => 1 + 0 = 1
1 * 1 = 1
0 * 2 = 0
5 * 1 = 5
1 * 2 = 2
0 * 1 = 0
5 * 2 = 10 => 1 + 0 = 1
1 * 1 = 1
0 * 2 = 0
5 * 1 = 5
1 * 2 = 2
0 * 1 = 0
5 * 2 = 10 => 1 + 0 = 1
1 * 1 = 1
0 * 2 = 0
0 * 1 = 0
``````

sums up to 1+1+0+5+2+0+1+1+0+5+2+0+1+1+0+0=20 => valid checksum.

Also, `INVALID\n`, not `INVAlID\n`. Case does matter.

• Second to last, I completely skipped this. – Mina Aug 15 '18 at 10:22
• How did you start at "second to last". You doubled the `5` .. clearly. That's the last digit, not the second to last. – I Support The Boycott Jan 29 '19 at 6:35
• It's the first digit, and happens to be an even number of digits from the second-to-last. – Blauelf Jan 29 '19 at 8:16