Skip to content

Instantly share code, notes, and snippets.

@geta6
Created January 27, 2014 04:10
Show Gist options
  • Save geta6/8643144 to your computer and use it in GitHub Desktop.
Save geta6/8643144 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
print 'ISBN: ';
$_ = readline(*STDIN);
if (/\d{10}/) {
s/^\s+|\s+$//g;
my $sum = 0;
for (my $i = 1; $i < length($_); $i++) {
$sum += $i * (substr($_, $i-1, 1) + 0);
}
if (4 == $sum % 11) {
print "ok\n";
exit;
}
}
print 'ng';
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment