sub is_valid_isbn {
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")); }
dXNlIExpc3Q6OlV0aWwgcXcoc3VtKTsKCnN1YiBpc192YWxpZF9pc2JuIHsKCW15IEBkaWdpdHMgPSBzcGxpdCAvLywgc2hpZnQ7CglyZXR1cm4gKChAZGlnaXRzID09IDEzKSBhbmQgKChzdW0gbWFweyAkZGlnaXRzWyRfXSAqICgkXyAlIDIgPyAzIDogMSkgfSAoMC4uMTIpKSAlIDEwID09IDApKTsKfQoKZm9yZWFjaCgiOTc4NDA2Mjc3MjIxMSIsICI5Nzg0MTUwMzE1Njg0Iil7CglwcmludGYoIiVzID0+ICVzXG4iLCAkXywgKGlzX3ZhbGlkX2lzYm4oJF8pID8gIk9LIiA6ICJORyIpKTsKfQ==