Talk:Luhn algorithm: Difference between revisions

Content deleted Content added
Implementing WP:PIQA (Task 26)
Undid revision 1289018748 by 148.252.146.68 (talk)
 
(13 intermediate revisions by 10 users not shown)
Line 1:
{{WikiProject banner shell|class=C|
{{WikiProject Mathematics|frequentlyviewed=yes|priority=Low|field=discrete}}
{{WikiProject Computing|auto=inherit}}
}}
Line 62:
:::You are correct. According to Vital (Now TSYS) the wording is correct and the pseudo-code is wrong. I have recommended that it be changed. Have to be careful though in how you word the for loop cause not all languages implement for the same. While loops may be safer and more language independant. --[[User:dmprantz|dmprantz]] 17 October 2006 (UTC)
 
Interesting, the pseudocode matches the description of the algorithm now, but the example given is wrong (it doubles the OTHER digits, starting with the first from the end of the payload, and not with the second, while the description clearly says "every second" - it should say "every second counting the whole number, not only the payload"). More interesting, running the given number on 6 different online calculators, 4 of them gave the result as in the example (i.e. 4) but the other 2 gave the result as in the description and pseudocode (i.e. 3) :D My cards numbers all match the example, and not the description/pseudocode. Something is fishy in this article :P ... [[User:LaurV|LaurV]] ([[User talk:LaurV|talk]]) 04:30, 8 March 2025 (UTC)
 
=== Computing the check digit ===
Line 334 ⟶ 335:
 
All you have to do is leave the check digit as part of the payload, weight that position as 1, mod the the whole sum by 10 and compare it to 0. [[User:Tzadikv|Tzadik]] ([[User talk:Tzadikv|talk]]) 12:13, 4 January 2024 (UTC)
 
== the C# example ==
 
The code is not correct, nor does it bring a correct result. [[User:לומד|לומד]] ([[User talk:לומד|talk]]) 08:26, 21 February 2024 (UTC)
 
:How is it wrong? Can you explain what the problem is, or give an example of an input that causes it to have the wrong output?
:[[User:Sollyucko|Solomon Ucko]] ([[User talk:Sollyucko|talk]]) 14:44, 21 February 2024 (UTC)
::- `in int[1] digits` doesn't compile because of the `1` (unless this is an upcoming feature of the language, but even so we probably don't want an array with only one element)
::- whether it "doubles" a digit is based on its index from the start, not the end, of the input
::- if the check digit needs to be 0, the code instead checks that it is 10
::There used to be a working example, but all the examples were deleted (see "Remove all implementation examples" above) and someone has since added this one instead. [[User:Rawling|Rawling]] ([[User talk:Rawling|talk]]) 10:09, 9 March 2024 (UTC)
 
== Is the final step in calculating the checksum actually correct? ==
 
According to the article, the last step is "The check digit is calculated by <math>(10 - (s \bmod 10))</math>". Unfortunately, following this logic, it would be IMPOSSIBLE for the check digit to ever equal 0. The value returned by <math>(s \bmod 10)</math> can only range between 0 and 9. So when you subtract that number from 10, you get a value that ranges between 10 and 1. This set of numbers is completely missing a 0, and it also includes a 10 which is too large for a single digit. The article here doesn't mention how this is to be fixed. I would assume if the output is 10 then it would then just be converted to 0 in an additional final step, but that's not mentioned anywhere in the article, so I'm not sure how that should actually be handled. [[Special:Contributions/73.169.149.34|73.169.149.34]] ([[User talk:73.169.149.34|talk]]) 20:16, 27 September 2024 (UTC)