0

the Luhn’s Algorithm in 378282246310005 = 48 and in 371449635398431 = 76 so how not INVALID

enter image description here

enter image description here

it must end with zero so the two number must be INVALID

enter image description here

4
  • Ah the wonderful internet. Here is an Online Luhn's calculator which indicates both numbers are valid, agreeing with check50. (There are lots of calculators available; I tried 3, they all agreed with check50) I'm afraid that means there's a bug in your code :( – DinoCoderSaurus Mar 16 '20 at 20:46
  • I calculated with my hand and the resulting number no end with zero – Mahmoud Mohamed Mar 16 '20 at 21:25
  • and all check50 right except two so how my code has bug – Mahmoud Mohamed Mar 16 '20 at 21:27
  • It is a bug because the two that fail have length 15, so it is likely your algorithm is not starting "from the second to last digit". (This test 369421438430814 is also 15, but starts with 36, so is invalid for that reason.) Can not add other advice without seeing the code. – DinoCoderSaurus Mar 17 '20 at 0:14
1

The second to last digit is doubled, from there every second digit.

3
7=>1+4
8
2=>4
8
2=>4
2
4=>8
6
3=>6
1
0=>0
0
0=>0
5

Sum is 3+(1+4)+8+4+8+4+2+8+6+6+1+0+0+0+5, total 60. This is divisible by 10.

6
  • when I used this another problem appear on 5105105105105100 as MASTERCARD the resulting is 25 not end with zero – Mahmoud Mohamed Mar 16 '20 at 22:44
  • Count the digits beginning with the last, and double every second. – Blauelf Mar 16 '20 at 23:34
  • Write down the number: 510510510510510 Starting with the second-to-last digit and moving to the left, double every second digit: 52010105201010520 If the result of the doubling is a two-digit number, add those 2 digits together: 5201+0105201+010520 Now add up all the digits together: 520110520110520 Sum = (5 + 2 + 0 + 1 + 1 + 0 + 5 + 2 + 0 + 1 + 1 + 0 + 5 + 2 + 0) = 25 25 mod 10 = 1, that means this number is not valid. – Mahmoud Mohamed Mar 17 '20 at 2:19
  • The comment before it was 5105105105105100 (I think you dropped the last digit). That makes a sum of ((1+0)+1+0+5+2+0+(1+0)+1+0+5+2+0+(1+0)+1+0+0)=20. From the Luhn's algorithm, this should be valid. – Blauelf Mar 17 '20 at 6:25
  • why you multiply the first element by 2 it should second to last – Mahmoud Mohamed Mar 17 '20 at 10:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .