Skip to content

Instantly share code, notes, and snippets.

@jettero
Created March 23, 2010 14:29
Show Gist options
  • Save jettero/341227 to your computer and use it in GitHub Desktop.
Save jettero/341227 to your computer and use it in GitHub Desktop.
ccard checksum
#!/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