$n = '4564123800603607'; # this is not my credit card number ($o = reverse($n)) =~ s/.(.)/($1*2)/ge; # every other number in it, times 2 # (reversed because then it will work # for numbers of different lengths, as # some cards are 13, not 16). ($e = reverse($n)) =~ s/(.)./$1/ge; # the other numbers, not times 2 $o =~ s/(.)/$x+=$1/ge; $e =~ s/(.)/$y+=$1/ge; # add the digits printf("%sValid.",(($x+$y)%10 == 0?'':'Not ')); # print the result
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Luhn Number Golf
by japhy (Canon) on Feb 26, 2002 at 13:57 UTC | |
|
Re: Luhn Number Golf
by jmcnamara (Monsignor) on Feb 26, 2002 at 15:27 UTC | |
|
Re: Luhn Number Golf
by demerphq (Chancellor) on Feb 26, 2002 at 15:24 UTC | |
|
Re: Luhn Number Golf
by chipmunk (Parson) on Feb 26, 2002 at 19:57 UTC | |
by PrakashK (Pilgrim) on Feb 26, 2002 at 21:47 UTC | |
by chipmunk (Parson) on Feb 26, 2002 at 22:15 UTC | |
by blakem (Monsignor) on Mar 08, 2002 at 09:10 UTC | |
by petral (Curate) on Feb 27, 2002 at 17:02 UTC | |
|
Re: Luhn Number Golf
by PrakashK (Pilgrim) on Feb 26, 2002 at 17:45 UTC | |
|
122 Char Sub - Re: Luhn Number Golf
by metadoktor (Hermit) on Feb 26, 2002 at 13:29 UTC |