Created
March 1, 2015 12:23
-
-
Save christianp/50bfcd658681a8ab81e6 to your computer and use it in GitHub Desktop.
missing digit in ISBN 0201896?34 - https://twitter.com/wacnt/status/558414046605492225
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isbn = '0201896?34' | |
t = 0 | |
for d,i in zip(isbn[:-1],range(10,1,-1)): | |
if d!='?': | |
t += int(d)*i | |
m = t%11 | |
target = int(isbn[-1]) | |
missing_index = isbn.index('?') | |
missing_mult = 10-missing_index | |
for a in range(11): | |
if (missing_mult*a+t)%11==target: | |
print(a) |
I think the output should be 8
, not 7
. When you replace the question mark in 0201896?34
with 7
, you get 0201896734
, which is an invalid ISBN according to Wolfram|Alpha (ISBN 0201896734
=> (invalid ISBN | required last digit: 7)
) and this online check digit calculator (when you enter the ISBN-10 without the check digit 020189673
, it outputs 7
).
Nevertheless, 0201896834
works: W|A is happy (ISBN 0201896834
) and so is the calculator (ISBN-10 without check digit 020189683
outputs 4
).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
7