fork download
use List::Util qw(sum);

sub is_valid_isbn {
	my @digits = split //, shift;
	return ((@digits == 13) and ((sum map{ $digits[$_] * ($_ % 2 ? 3 : 1) } (0..12)) % 10 == 0));
}

foreach("9784062772211", "9784150315684"){
	printf("%s => %s\n", $_, (is_valid_isbn($_) ? "OK" : "NG"));
}
Success #stdin #stdout 0s 4888KB
stdin
Standard input is empty
stdout
9784062772211 => OK
9784150315684 => NG