Task 156 Luhn Algorithm

Back to Problem Solutions forum

crydolphin666     2020-10-19 18:53:21

For some reason I've got an error in this test case:
Was: 1097696166985934
Expected: 1907696166985934

But hash sum of both numbers is 80.
So my answer was obviously 1097696166985934
How should I detect swap error in such test cases? In my opinion this test case shows how inapplicable Luhn Algorithm for error's detection.
While writting this topic I've found the confrmation of my words in this article Luhn Algorithm
I guess you should rework your test cases.

jquaranta89     2025-01-26 19:57:15

I have run into the same problem but am ignoring it for now

zelevin     2025-01-27 06:26:12

This point gets brought up every now and then.

The problem does mention that:

each of the numbers contain one of two errors

So submitting the original number as the answer is clearly incorrect.

It is true that Lunh's checksum is the same after the 0-9 swap; but this does mean that in this case the correct answer is the original number with the leftmost 0-9 pair swapped.

Given that 1000+ people solved this problem correctly, I don't think there is a dire necessity to rewrite the setter (I presume, to avoid the 0-9 swap issue).

Please login and solve 5 problems to be able to post at forum