Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Luhn Number Golf

by PrakashK (Pilgrim)
on Feb 26, 2002 at 17:45 UTC ( #147662=note: print w/ replies, xml ) Need Help??


in reply to Luhn Number Golf

Here's a sub with 62 characters. Expects the number as an argument and returns 1 or 0.

sub luhn { #2345678901234567890123456789012345678901234567890123456789012 for(pop=~/(.)(.)/g){($a+=$1)+=$_ for map{split//}2*$2}!($a%10) }
/prakash


Comment on Re: Luhn Number Golf
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-02 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (30 votes), past polls