ISBN check digit puzzle

what validator are you failing?

The first one.

and all the others are ok?

Yes. All test-cases and all the other validators are ok.

Here the same!
All test cases are green, but the last two validators are red.
I checked that the would-be ISBN are 10 or 13 digits long, checked there are no letters or symbols in the first 9 or 12 digits of any ISBN, and checked the check digit is correct.
For 13 digit ISBN is pretty easy,
For 10 digit I checked the “no rest” version (ends with 0), the "rest 10 (ends with ‘X’) and the more common version.
What is happening with the validators? Could we at least have more test cases with different particular cases that maybe we are not considering?

The hint is in the statement:
“Before year 2007 ISBNs were 10-digit long. After that year ISBNs extended to 13 digits…”
“A valid ISBN should contain the digits 0 to 9 only, except for…”

Look out for entries that do not meet the stated format.

Another hint about the check digit:

"Check digit is the value needed to add to the sum to make it dividable by [11 (isbn-10) or 10 (isbn-13)]."

“sum” means the weighted sum of digits.
Check the marginal cases.
For isbn-10,
assume sum % 11 = 0, what is the check digit?
assume sum % 11 = 10, what is the check digit?

For isbn-13,
assume sum % 10 = 0, what is the check digit?
assume sum % 10 = 9, what is the check digit?

Hi java, unfortunately the two hints you gave are unhelpful for figuring out what’s going wrong with the last two validators. These hints are already known by anybody who solved for all test cases, and do not provide any help for what else might be going wrong.

1 Like

For isbn-10,
assume sum % 11 = 0, what is the check digit? - 0
assume sum % 11 = 10, what is the check digit? - 1

For isbn-13,
assume sum % 10 = 0, what is the check digit? - 0
assume sum % 10 = 9, what is the check digit? - X

I had the same problem but then I figured it out. The ‘X’-character is only a valid character as the last character of an ISBN-10. In ISBN-13 the ‘X’-character isn’t allowed, because there the modolus is 10 and not 11, so the highest check digit is ‘9’. I hope this was your problem too.

Hello, I am beginner and I have tried this puzzle. I tried to pass the first test and I do not know why it says the following:

I have tried to remove that new line as follows:

 for(int i = 0; i < invalidISBNs.Length; i++){

Could you help me please?

Thank you.

After the last line it is valid to have an ending \n. I guess the if…else here is unnecessary.

May be there is another Console.Write in your source causing extra \n to output?
Or your string in the array already have an \n appending to it? - count the string length to assure

Hi all,

I don’t well understand how to catch the ‘X’-character in an ISBN.
Is it ok at last position in ISBN-10, like a generic character ?
For exemple, “154875155X” is it valid (it is not in the “Short” test) ?
Because “111842297X” is valid in the “Much Longer” test.

Please help, i turn crazy !

154875155X is invalid
111842297X is valid

The first one ought to have chk dig as 3
The second one ought to have chk dig as 10. (X means 10)

Thanks. I see now.
So, will try to improve my bushy code. Ouch !!!

Sorry again but checksum for 111842297X is 166, so chk dig should be 4. No ?!?

ISBN-10 check digit is calculated by Modulus 11

Oups ! This one is for me.

I don’t get it, too.Really frustrating.
My code runs all Tests incl. the Custom one fine.
Then it fails the first validator “Example”, but finishes validator 2-4 OK.

Code Logic:

  • Check length 10 or 13 (so every other length fails)
  • Convert digit 0-8 / 0-11 to an integer (so every other char produces a failure)
  • Do calculation of checksum and check with digit 9/12 with the special case for a ISBN-10 with X.

Pretty sure I am missing something, but also pretty sure the test cases do not cover everything the validators do…

Updated a few examples to catch certain exceptions.
BTW, “Convert digit 0-8 / 0-11 to an integer” is incorrect, at least a typo.