Content deleted Content added
Nick Levine (talk | contribs) →Pseudocode: new section Tags: Mobile edit Mobile web edit Advanced mobile edit |
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags |
||
Line 158:
Both the C# implementation and the Scala implementation seems wrong to me. The algorithm states "Counting from the check digit, which is the rightmost, and moving left, double the value of every second digit". Then, shouldn't the example read:
<
bool isLuhnValid(string s)
{
return s.Reverse().SelectMany((c, i) => ((c - '0') << (i & 1)).ToString()).Sum(c => (c - '0')) % 10 == 0;
}
</syntaxhighlight>
Similarly for Scala, shouldn't it be:
<
def isLuhnValid(s : String) =
s.reverse.zipWithIndex.map({ case (c, i) => ((c - '0') << (i & 1))}).mkString.map(_ - '0').sum % 10 == 0
</syntaxhighlight>
[[User:Rehno Lindeque|Rehno Lindeque]] ([[User talk:Rehno Lindeque|talk]]) 09:33, 1 June 2011 (UTC)
Line 204:
I've also put up a gist on github with the code and tests showing correctness. https://gist.github.com/1773914
<
def luhn_checksum(card_number):
def digits_of(n):
Line 222:
def calculate_luhn(partial_card_number):
return 10 - luhn_checksum(int(partial_card_number) * 10)
</syntaxhighlight>
[[Special:Contributions/206.169.213.106|206.169.213.106]] ([[User talk:206.169.213.106|talk]]) 21:08, 8 February 2012 (UTC)
:It looks good. I've put this version up in the article. – [[User:Acdx|Acdx]] <small>(<i>[[User_talk:Acdx|talk]]</i>)</small> 11:55, 18 February 2012 (UTC)
Line 237:
Here is a basic Ruby solution to luhn10 validation. I decided to place it here instead of the article.
<
def luhn10?(number)
checksum = 0
Line 256:
split_integer(number).inject(0){ |sum,digit| sum += digit.to_i}
end
</syntaxhighlight>
<small><span class="autosigned">— Preceding [[Wikipedia:Signatures|unsigned]] comment added by [[User:{{{1}}}|{{{1}}}]] ([[User talk:{{{1}}}|talk]] • [[Special:Contributions/{{{1}}}|contribs]]) </span></small><!-- Template:Unsigned -->
|