Created
March 23, 2010 14:29
-
-
Save jettero/341227 to your computer and use it in GitHub Desktop.
ccard checksum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use common::sense; | |
use List::Util qw(sum); | |
my $ccard = shift; | |
print crunch($ccard) ? "OK" : "BAD", "\n"; | |
sub crunch { | |
my $skip = 1; | |
my @digits = reverse map { split m// } map {($skip=not $skip) ? $_*2 : $_} reverse split m//, shift; | |
my $checksum = sum @digits; | |
return !($checksum % 10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment