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

Bernadette Perrin Riou <[email protected]>
Newsgroups gmane.comp.mathematics.pari.user
Message-ID <[email protected]>
? (3+X)%10
%1 = 0

Bernadette

> Le 31 janv. 2025 à 18:59, Bill Allombert <[email protected]> a écrit :
> 
> On Fri, Jan 31, 2025 at 02:08:24AM +0100, Karim Belabas wrote:
>> Here's a further shortened version.
> 
> verify_isbn(N)=
> { my(M, n, z);
>  M = Map([10, [[10,9,8,7,6,5,4,3,2,1]~, 11];
>           13, [[1,3,1,3,1,3,1,3,1,3,1,3,1]~, 10]]);
>  n = if (type(N)=="t_STR", apply(eval, select(c -> c != "-", Vec(N))),
>          type(N)=="t_INT", digits(N));
>  if (!mapisdefined(M, #n, &z) || (n * z[1]) % z[2], print("Invalid! ", N)
>                                                   , print("Valid ISBN: ", N));
> }
> 
> 2 comments: 
> - for the '13' case, this just check this is an EAN13. To be an ISBN
> it needs to start by 978 or 979.
> 
> - for the '10' case, the last digit can be the letter X to denote 10,
> since the checksum is mod 11.
> 
> Game: why do we get this:
> ? verify_isbn("0-0000-0001-X");
> Valid ISBN: 0-0000-0001-X
> 
> Cheers,
> Bill, small-scale book publisher.
>
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.