use strict;
use warnings;
sub is_valid_isbn {
my $n = 0;
foreach(0..12){
$n += $digits[$_] * ($_ % 2 ? 3 : 1);
}
}
foreach(qw( 9784062772211 9784150315684 )){ printf("%s => %s\n", $_, (is_valid_isbn
($_) ? "OK" : "NG")); }
dXNlIHN0cmljdDsKdXNlIHdhcm5pbmdzOwoKc3ViIGlzX3ZhbGlkX2lzYm4gewoJbXkgQGRpZ2l0cyA9IHNwbGl0IC8vLCBzaGlmdDsKCgkoQGRpZ2l0cyA9PSAxMykgb3IgcmV0dXJuOwoKCW15ICRuID0gMDsKCWZvcmVhY2goMC4uMTIpewoJCSRuICs9ICRkaWdpdHNbJF9dICogKCRfICUgMiA/IDMgOiAxKTsKCX0KCglyZXR1cm4gKCRuICUgMTAgPT0gMCk7Cn0KCmZvcmVhY2gocXcoIDk3ODQwNjI3NzIyMTEgOTc4NDE1MDMxNTY4NCApKXsKCXByaW50ZigiJXMgPT4gJXNcbiIsICRfLCAoaXNfdmFsaWRfaXNibigkXykgPyAiT0siIDogIk5HIikpOwp9Cg==