Bernadette Perrin Riou on Thu, 20 Mar 2025 16:42:21 +0100
|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: program to verify ISBN numbers (10 digit or 13 digit)
|
- To: Bill Allombert <Bill.Allombert@math.u-bordeaux.fr>
- Subject: Re: program to verify ISBN numbers (10 digit or 13 digit)
- From: Bernadette Perrin Riou <bernadette.m.riou@orange.fr>
- Date: Thu, 20 Mar 2025 16:41:52 +0100
- Cc: pari-users@pari.math.u-bordeaux.fr, Loïc Grenié <loic.grenie@gmail.com>, American Citizen <website.reader3@gmail.com>
- Delivery-date: Thu, 20 Mar 2025 16:42:21 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1742485336; bh=+kOwpC4KKLL/K5iayTMlXSeOwZwlFETi/cxcMRZi2hY=; h=Mime-Version:Subject:From:Date:Message-Id:To; b=gYRsIkamgO6nbrguhE2pLNvRv1Sl+l3BVJWqNkk3qrjv+co4qo9Hc8DHW+hibYPYe bAtel6E96hlXDegVRAprXmZDB+rLy8lBVDqzokJ/kzb05qWalLArMO4HFX2WkNfYyK Y4P/rjiy3vzDMEicHYcc3F5GqoJDnRoxmwWvk0JN2GvyLcRoiDlQkJg5umVxaeNsNa 0FErYfYsF3dTxS5K59ym6sXjCkAHuHRv3JCg1mlyb94jU/6LPWgHQU7eUMR851zz6f IiLqDVJtrROunToed9/Opeh0FCnCHJZz2vYLFR/itEA+t4xn2zwg+ZChJ5scLy8jJs xBmtTD1FAkIrw==
- In-reply-to: <Z50Pc5DRDiLE2_Mo@seventeen>
- References: <554e0a25-822d-494f-bf78-4cf418c98c4b@gmail.com> <CAMLkfFT00g8zNppTpQ8Gx2JxZ3MkZWk5NKzUO9zMNvtnDaPZJQ@mail.gmail.com> <Z5wiiOlUgNStEA_z@math.u-bordeaux.fr> <Z50Pc5DRDiLE2_Mo@seventeen>
? (3+X)%10
%1 = 0
Bernadette
> Le 31 janv. 2025 à 18:59, Bill Allombert <Bill.Allombert@math.u-bordeaux.fr> 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.
>