-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Luhn algorithm calculated in reverse #10
Labels
bug
Something isn't working
Comments
You're right, Great catch! This fix would address the issue and make the LuhnAlgorithm function accurate for both even and odd-length numbers. Do you want to create PR ? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When looking at the definition of
LuhnAlgorithm
, I noticed the multiplication of digits in the number by the alternating pattern of 2 and 1 starts from the left. The Luhn algorithm actually starts this multiplication from the right instead. Since the test case has an odd length (excluding the checksum digit), it does not capture this difference. For example, 109 should be valid, but insteadLuhnAlgorithm("108").verify()
returnsTrue
. This can be fixed by replacingremaining_numbers
byreversed(remaining_numbers)
in the implementation.The text was updated successfully, but these errors were encountered: