Skip to content
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

Closed
troyfigiel opened this issue Jun 9, 2024 · 1 comment
Closed

Luhn algorithm calculated in reverse #10

troyfigiel opened this issue Jun 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@troyfigiel
Copy link

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 instead LuhnAlgorithm("108").verify() returns True. This can be fixed by replacing remaining_numbers by reversed(remaining_numbers) in the implementation.

@troyfigiel troyfigiel added the bug Something isn't working label Jun 9, 2024
@codeperfectplus
Copy link
Owner

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
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants