Open viggy28 opened 5 years ago
Okay, Yeah should read that twice. Instead of doing it from right, I was doing from left.
Thanks.
This happens a lot, so I'd like to re-word the test case annotations a bit to make this clearer. Thanks for opening the issue!
Hi @bitfield.
Is this still actual, in your opinion?
I checked the readme that now states:
The first step of the Luhn algorithm is to double every second digit,
starting from the right. We will be doubling...
And again, some lines below:
Double the second digits, starting from the right
There also is the link to the wikipedia page at the top of the page and it should be very clear, at least nowadays, and also in my opinion.
Do you think it's safe to close this issue now?
Thank you for considering my request.
Well, people still continue to get it wrong (and they always assume that they are correct and that despite literally tens of thousands of people successfully completing the exercise, the test case must be wrong). I agree with you that the exercise itself makes the situation abundantly clear, but nevertheless, people who aren't paying attention see what they expect to see, and clearly they need a little more prompting here.
Hey, I came across this exercise today and it seems like at least its description is misleading. It says, "double every second digit starting from the right". At the same time in all examples this procedure starts from the second rightmost digit (_
were skipped): for 4539 3195 0343 6467
it is 4_3_ 3_9_ 0_4_ 6_6_
.
Wikipedia says (see: https://en.wikipedia.org/wiki/Luhn_algorithm) it should start at the rightmost digit (the last one). So, with that knowledge, the example from above should look like this: _5_9_1_5_3_3_4_7
.
Thanks, @kwiat1990. Following your reference, Wikipedia says:
Take the original number and starting from the rightmost digit moving left, double the value of every second digit
In your example, 4539 3195 0343 6467, the rightmost digit is the last 7. So we wouldn't double that one, we'd double the second digit as we move leftwards. That would be the 6, and every second digit thereafter.
So the exercise is correct, but as you and others have amply demonstrated, it's confusing! That's why I've suggested it be reworded to avoid this.
@bitfield please take a closer look at the example on Wikipedia: for a 7992739871
doubling starts at the last digit (1) and from there we move towards the first digit in the string. The point is, that we should also double the last digit, where we start counting.
The exact quote from Wikipedia says:
Take the original number and starting from the rightmost digit moving left, double the value of every second digit (including the rightmost digit).
I am starting this exercise now and I believe the reason for the confusion @kwiat1990 is that in the first of the example, they show less digits than the actual card number.
79927398713
is the full number, the 3
is left off because that is the checksum.
So the idea here is that the sum should be evenly divisible by the 3 with no remainder.
Few questions that I think I can easily figure out from running the test cases.
But in the Wikipedia entry a checksum digit exists, but it does not here. The checksum is also not part of the sum (I believe).
Additional, if a value is doubled, like 9 -> 18, the 1 & 8 are added to make it 9 again.
Card - 4539 3195 0343 6467
Impacted Digits - 4_3_ 3_9_ 0_4_ 6_6_ // _ are not doubled
Resulting Values - 8569 6195 0383 3437
In the example given, when a 6
is doubled to 12
, the 1
+ 2
of the values are added to make 3
. This could be made a lot clearer.
What is different here is that the 7
should really be the checksum to match the Luhn wikipedia example, not 10
. The 7
would also not be part of the addition 8+5+6+9+6+1+9+5+0+3+8+3+3+4+3+7 = 80
as the checksum would be left off.
My thoughts are this -
10
as the checksum, but be clear how that differs from LuhnThoughts @bitfield?
I think the Wikipedia page is probably not helpful here. Perhaps the best thing to do with the exercise instructions is to add the same kind of clarification that Wikipedia does:
The first step of the Luhn algorithm is to double every second digit, starting from the right (not including the rightmost digit).
Hi,
One of the test case for Luhn exercise is
{ "a valid Canadian SIN", "055 444 285", true, }
The sum is 35 which is not evenly divisible by 10. Am i missing anything?
Thanks