Skip to content

Instantly share code, notes, and snippets.

@christianp
Created March 1, 2015 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianp/50bfcd658681a8ab81e6 to your computer and use it in GitHub Desktop.
Save christianp/50bfcd658681a8ab81e6 to your computer and use it in GitHub Desktop.
missing digit in ISBN 0201896?34 - https://twitter.com/wacnt/status/558414046605492225
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)
@christianp
Copy link
Author

7

@generalmimon
Copy link

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