PROG0183 - ISBN

In the new ISBN-13 (International Standard Book Numbering) system, each book is assigned a unique 13-digit code. The first twelve digits identify the book itself, whereas the last digit merely serves as a check digit to detect invalid ISBN-13 codes.

ISBN
ISBN in text and barcode

If $x_1, \ldots, x_{12}$ represent the first twelve digits of an ISBN-13 code, the check digit $x_{13}$ is calculated as $$x_{13} = (10 - (x_1 + x_3 + x_5 + x_7 + x_9 + x_{11} + 3(x_2 + x_4 + x_6 + x_8 + x_{10} + x_{12}))\!\!\!\!\!\mod{10})\!\!\!\!\!\mod{10}$$ As a result, $x_{13}$ always takes a value in between 0 and 9, so that ISBN-13 codes only contain digits.

An ISBN-13 code is at the same time also an EAN-13 barcode. The EAN-13 barcode (originally European Article Number but now renamed into International Article Number even though the abbreviation EAN has been retained) is a 13-digit barcoding standard which is used worldwide for marking products often sold at retail point of sale. When the EAN-13 barcode encodes a conversion of an ISBN-13 code, its prefix will be either 978 or 979 and those are the only valid prefixes for ISBN-13 codes. The fourth digit identifies the country where the book was published. Countries using the same language are grouped into the same category. The following table gives an overview of these categories.

group identifier registration group
0, 1 English speaking countries
2 French speaking countries
3 German speaking countries
4 Japan
5 Russian speaking countries
7 China
6, 8, 9 Other countries

Assignment

Write a function overview that takes a list of strings representing ISBN-13 codes. The function must print an overview that shows the distribution of the list of ISBN-13 codes over the different registration groups. Invalid ISBN-13 codes must be included in the overview under the category Errors. Use the names of the registration groups and maintain their order as given in the example below. Registrations groups for which no ISBN-13 codes occur in the list should also be included in the overview (having 0 occurrences).

Example

>>> codes = [
...    '9789743159664', '9785301556616', '9797668174969', '9781787559554',
...    '9780817481461', '9785130738708', '9798810365062', '9795345206033', 
...    '9792361848797', '9785197570819', '9786922535370', '9791978044523', 
...    '9796357284378', '9792982208529', '9793509549576', '9787954527409', 
...    '9797566046955', '9785239955499', '9787769276051', '9789910855708', 
...    '9783807934891', '9788337967876', '9786509441823', '9795400240705', 
...    '9787509152157', '9791478081103', '9780488170969', '9795755809220', 
...    '9793546666847', '9792322242176', '9782582638543', '9795919445653', 
...    '9796783939729', '9782384928398', '9787590220100', '9797422143460', 
...    '9798853923096', '9784177414990', '9799562126426', '9794732912038', 
...    '9787184435972', '9794455619207', '9794270312172', '9783811648340', 
...    '9799376073039', '9798552650309', '9798485624965', '9780734764010', 
...    '9783635963865', '9783246924279', '9797449285853', '9781631746260', 
...    '9791853742292', '9781796458336', '9791260591924', '9789367398012' 
... ]
>>> overview(codes)
English speaking countries: 8
French speaking countries: 4
German speaking countries: 6
Japan: 3
Russian speaking countries: 7
China: 8
Other countries: 11
Errors: 9

Binnen het nieuwe ISBN-13 (International Standard Book Numbering) systeem krijgt elk boek een unieke code toegewezen die bestaat uit 13 cijfers. De eerste 12 daarvan geven informatie over het boek zelf, terwijl het laatste louter een controlecijfer is dat dient om foutieve ISBN-13 codes te detecteren.

ISBN
ISBN in tekst en streepjescode

Indien $x_1, \ldots, x_{12}$ de eerste 12 cijfers van een ISBN-13 code voorstellen, dan wordt het controlecijfer $x_{13}$ als volgt berekend: $$x_{13} = (10 - (x_1 + x_3 + x_5 + x_7 + x_9 + x_{11} + 3(x_2 + x_4 + x_6 + x_8 + x_{10} + x_{12}))\!\!\!\!\!\mod{10})\!\!\!\!\!\mod{10}$$ $x_{13}$ kan m.a.w. de waarden 0 tot en met 9 aannemen, waardoor ISBN-13 codes uitsluitend uit cijfers bestaan.

Een ISBN-13 code is tegelijkertijd ook een EAN-13 code. De Europese artikelnummering (EAN) is een streepjescode die wereldwijd wordt toegepast als artikelcodering in winkels ten behoeve van kassa-afhandeling en voorraadadministratie. Enkel de EAN-13 codes die starten met 978 en 979 zijn gereserveerd voor ISBN-13 codes. Dit betekent dus dat een ISBN-13 code enkel geldig is als ze begint met 978 en 979. Het vierde cijfer identificeert het land waar het boek gepubliceerd is. Landen met dezelfde taal worden hierin gegroepeerd. Hieronder vind je een overzicht van deze groepen.

groepsidentifier registratiegroep
0, 1 Engelstalige landen
2 Franstalige landen
3 Duitstalige landen
4 Japan
5 Russischtalige landen
7 China
6, 8, 9 Overige landen

Opgave

Schrijf een functie overzicht waaraan een lijst van strings moet doorgegeven worden. Deze strings stellen ISBN-13 codes voor. De functie moet een overzicht uitschrijven die de verdeling weergeeft van de lijst van ISBN-13 codes over de verschillende registratiegroepen. Ongeldige ISBN-13 codes moeten in het overzicht opgenomen worden onder de categorie Fouten. Gebruik de namen van de registratiegroepen en handhaaf hun volgorde zoals ze in onderstaand voorbeeld weergegeven worden. Registratiegroepen waarvoor geen ISBN-13 codes in de lijst voorkomen, moeten ook in het overzicht opgenomen worden (met 0 voorkomens).

Voorbeeld

>>> codes = [
...    '9789743159664', '9785301556616', '9797668174969', '9781787559554',
...    '9780817481461', '9785130738708', '9798810365062', '9795345206033', 
...    '9792361848797', '9785197570819', '9786922535370', '9791978044523', 
...    '9796357284378', '9792982208529', '9793509549576', '9787954527409', 
...    '9797566046955', '9785239955499', '9787769276051', '9789910855708', 
...    '9783807934891', '9788337967876', '9786509441823', '9795400240705', 
...    '9787509152157', '9791478081103', '9780488170969', '9795755809220', 
...    '9793546666847', '9792322242176', '9782582638543', '9795919445653', 
...    '9796783939729', '9782384928398', '9787590220100', '9797422143460', 
...    '9798853923096', '9784177414990', '9799562126426', '9794732912038', 
...    '9787184435972', '9794455619207', '9794270312172', '9783811648340', 
...    '9799376073039', '9798552650309', '9798485624965', '9780734764010', 
...    '9783635963865', '9783246924279', '9797449285853', '9781631746260', 
...    '9791853742292', '9781796458336', '9791260591924', '9789367398012' 
... ]
>>> overzicht(codes)
Engelstalige landen: 8
Franstalige landen: 4
Duitstalige landen: 6
Japan: 3
Russischtalige landen: 7
China: 8
Overige landen: 11
Fouten: 9

Added by:Peter Dawyndt
Date:2011-11-02
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:PY_NBC
Resource:None

© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.