program to verify ISBN numbers (10 digit or 13 digit)

American Citizen <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
Hello All:

I had to verify some ISBN numbers and didn't know that they actually 
followed a well ordered scheme for being checked.

For anyone who wants it, here's the GP-Pari program to verify the number 
or string value (removing the dashes)

{verify_isbn(N)=
my(m10,m13,m,n,sz,z);
m10=[10,9,8,7,6,5,4,3,2,1]~;
m13=[1,3,1,3,1,3,1,3,1,3,1,3,1]~;
if(type(N)=="t_STR",
  m=Vec(N);
  sz=matsize(m)[2];
  n=0;
  for(i=1,sz,if(m[i]!="-",n=concat(n,eval(m[i]));););
  sz=matsize(n)[2];
  n=vector(sz-1,i,n[i+1]);
);
if(type(N)=="t_INT", n=digits(N););
if(default(debug)>0,print("n=",n));
if(matsize(n)[2]==13,
  z=n*m13;
  if(z%10==0,print("Valid ISBN: ",N);,print("Invalid! ",N););
  return;
);
if(matsize(n)[2]==10,
  z=n*m10;
  if(z%11==0,print("Valid ISBN: ",N);,print("Invalid! ",N););
  return;
);
print("Invalid ISBN: ",N);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.