You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 ?
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: