Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Luhn Number Golf

by japhy (Canon)
on Feb 26, 2002 at 13:57 UTC ( [id://147562]=note: print w/replies, xml ) Need Help??


in reply to Luhn Number Golf

This code assumes the number comes as an argument to our function. It comes in at 68 (updated to allow for odd-digited credit cards).
sub luhn { #234567890123456789012345678901234567890123456789012345678901234567 $a=0;$_=reverse pop;s/(.)(.?)/$a+=$1+($2&&(($2*2-1)%9)+1)/ge;1>$a%10 }

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a (from-home) job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://147562]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-25 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found