5 kyu
ISBN-10 Validation
4,165 of 11,479nklein
Loading description...
Regular Expressions
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
too many edge cases for this during testing.
048665088X is valid Expected : false to equal : true
code returns true but when put in test it gets false instead?
Double check your code. I had false answer for this case too. Only because I compare correct addendums of checksum I found typo error in my code.
More like a 7kyu Kata!
I feel like it should be mentioned in the problem Statement that not only you have to check if the numbers lign up, but also if the string is the exact lenght, contains ivalid characters etc.
This comment has been hidden.
You are doing your thing with i. You probably want to do your thing with the i-th character of the isbn.
Is there a reason to post the same question twice? I deleted the duplicate question below.
Mark your post as having spoiler content next time.
@Chrono79 didnt really understand what that was. will do from now on @hobovsky accident @catechni tiny bit more clarity?
C# Translation
TypeScript translation (literal translation of JavaScript; author is inactive)
Approved
In rust X123456788 expected to be true, but if should be false. Think that this should be true :)
No, the expected answer is false and that's ok, read the posts below. Or the description again:
My fault, I didn't saw that. ALl good now
Very nice kata, congratulations.
Friendly reminder: It's more declarative use a block instructions "if", "else if", "else". That a triple nested of ternaries on a one line.
In C, X123456788 expected true, but it should be false.
That's the test for C and it expects false, not true.
Same in Rust as I can see.
Why should be false? the sum is 330
LE: Oh, it's becuase only the last character can be X
It's a problem with this case, do_test("X123456788", true); because it's sum=330
bruh, missed about X :(
Scala Translation Submitted
1293 is false? shouldnt isnt 1 * 1 + 2 * 2 + 9 * 3 + 3 * 4 = 44? 44 % 11 is 0
Those are 4 digits.
X123456788 seems perfectly valid to me, but apparently i'm meant to return "false"? can someone please explain.
One comment said that only the last digit is allowed to be an X.. meh
In C, in lower case x tests I got "for 048665088x expected false", but it should be true
the description does not say that lowercase 'x' is valid
The author needs to rewrite the instructions, only when I made the attempt did I know that all sorts of letters can be added to the ISBN when the instructions clearly say 0 to 9 and 10 can be either 0 to 9 or X.
Lua translation! (author is inactive)
approved by someone
Output says "192904397" expected True but got False. Neither is it a 10 digits nor modulo 11 equals zero, unless I put an X in the end. Am I missing something here? I found comments that say 9 digits should be correct but the description says otherwise.
Random tests are incorrect in Haskell, there are already issues raised about that. I assume after seeing your profile that this is the language you are using. Please say it next time.
Rust traslation (author is inactive)
Approved by someone
This comment has been hidden.
bruh, That's not the only thing to check for. Read the dscription properly
Nice useful in real life work Kata, iLike!
Hey there. Nice kata, I like the ideea, but one question: why is it 5 kyu? IMO it should be a maximum of 7kyu, but that is just my opinion, so feel free to comment on that. Cheers!
Ranks of approved katas cannot be changed (well, it can, by sending the kata back to beta, but it's a long and painful process, with no guarantees, particularly with old katas like this one). See there to understand how katas are ranked: https://docs.codewars.com/concepts/kata/beta-process/
Many times, old katas tend to be overranked in comparison with current criterias. However, this is not something that can be handled here.
The best way to have better rankings is to have more users involved in beta validation process.
I know how long the approvall process can be as I designed a kata myself, see: https://www.codewars.com/kata/6167e70fc9bd9b00565ffa4e, but what you say makes sense. Thanks for the clarification. thumbs up
Kotlin translation ready for review and approval.
COBOL translation (author is inactive).
Yes of course it tests for a lowercase 'x' (in Go) and expects it to be true without mentioning it in the description. * sigh *
Go is missing a test like the following, that checks for length > 10.
Expect(ValidISBN10("12930000001")).To(Equal(false), "12930000001 is not valid")
Why is 'XXXXXXXXXX' False?
not an issue. only the last digit can be 'X'.
Because the first 9 chars expected to be digits
C translation (author inactive)
Approved :)
Perl translation
One of the basic tests for javascript, 1234512345, expects false instead of true.
And how is that an issue?
"1234512345"
is not a valid ISBN-10 identifier.wdym it has 10 numbers number: 1 2 3 4 5 1 2 3 4 5 index: 1 2 3 4 5 6 7 8 9 10
It needs a valid checksum to be a valid ISBN-10.
This comment has been hidden.
Ok, but don't post your solution here, there's 'solutions' tab for it.
I've submitted a Racket translation.
Approved, thanks :) Next time, better mark it as a suggestion to give it more visibility, or it may get lost among all comments.
I knew I forgot to do something. Thanks.
Random tests appear to be broken for Haskell. I submitted two times and got something like "123456789" (nine digits) should result in True but got False (which is an incorrect statement, since 9-digits doesn't make a valid ISBN). I submitted the third time, without any changes, and it passed.
For an unknown reason to me, it happens sometimes tests fail on first attempt with some absurd results. Does this error occur sometimes (though not systematically) if you submit your code again?
Yes, it happens sometimes, since these are random tests. The success depends on the presence of the "absurd results", as you put it.
It's a big issue
A little easy for a 5 kyu... I thought it would be around 7 or 8 at least. Or maybe that's because my solution isn't optimized enough...
Indeed it's an easy one. It's a very old kata (8 years), elders are used to saying old kata, easy kata ;)
fair enough! next challenge now is to try learning the two line solutions some people are throwing out there haha
That's a good way to learn ;)
Actually it isn't. Write your code as legibly as possible and not as short as possible. And try to solve some hard problems insteat of solving easy problems in one line.
Talk for yourself. I've learnt great part of what I know in programming by dissecting (very often unreadable) code of power users on CW.
In Go tests expect 'x' lowercase to be a valid character (for 'X'), unlike stated in the description and in (at least) Python, Ruby and JS.
This comment has been hidden.
Fixed
Julia translation
Approved, thanks :)
Ah, it's really nice to do some Haskell kata again! I did the entirety of Advent of Code in Haskell, and because treated myself to a few new languages as a reward for that, I haven't done any Haskell challenges since. Well, it's nice to be back—home 😁
The Haskell version does not seem to test X'es as last character. My initial solution passed while I believe it should not:
https://www.codewars.com/kata/reviews/57cc5742a362c1629b000076/groups/608e8d49d8ca9c0001604622
This is true. I went through quite a bit of pain to make it work and make it neat and concise, and I was looking forward to seeing others' solutions—only to find many hadn't gone to the trouble!
This comment has been hidden.
Python missing test :
test.assert_equals(valid_ISBN10('123456789T'), False)
added
Java translation pls
Try writing one yourself? ;-)
the isbn-10
048665088X
isfalse
but in the test its saidtrue
theres some other random cases that have the same problem too python testBut it is valid input, leading 0s are allowed. Why do you think it should be false?
I went through other solutions and tests to verify it, and they seem correct, so it's not a kata issue, but problem with your code. Feel free to reply and figure it out, but over 100 others so far have passed tests in python.
oops, I misunderstand the description and made my code wrong, by the way, thanks! and have a great day
This comment has been hidden.
Nicely observed, I've added fixed test for this and alternated random ones, so there's chance of such case appearing.
This comment has been hidden.
You refer to sample tests, which are there for user and can be modified in any way (so you can assert whatever you want), however when you click
Attempt
full tests are run over which you have no control (and as far as I'm concerned are correct).Python translation kumited, including clearer description -- please check and approve (note: author is inactive)
Any love for this translation?
Assertions should be in a
test.it
block nested insidetest.describe
. (I think.)It's not obligatory :-)
I think I remember kazk mentioning that
describe
/it
structure is either necessary or strongly encouraged because that's what test runner relies on when analyzing test output, and if it's not there, test results are not well defined or may break in the future. I can ask for exact explanation if you want, but IIRC structuring withdescribe
/it
should be there.documentation: Python test framework
Also, consider the output:
vs
Assertions directly under
describe
should be avoided. It happens to work at the moment, but it's awkward.Top-level
it
should be fine. Many test frameworks don't havedescribe
. But usedescribe
when it makes sense.Top-level assertions are strongly discouraged.
So
describe -> it -> assertions
best,it -> assertions
ok,describe -> assertions
bad,assertions
bad.Sample tests still need
it
block.done
Ruby translation
Approved (author is inactive since may)
Hmm, I didn't notice that the reference solution in tests and the initial one were different by having
chars
andsplit
(which for some random input wasn't the same), so I fixed it afterwards but now there's messageNo supported language version
above the description even though everything works fine :oFor ISBN-10 validation, the rightmost number is the first position, not the leftmost.
exactly
JavaScript - no sample tests, no random tests.
Kata itself should be
6 kyu
at most.Fixed, but still working on fixing haskell.
Haskell now also has random tests.
PHP translation added
Was a bit too easy for a 5kyu. But nice. ;-) Maybe the initial TDD tests could be prepared.
A little challenging for me. Thank you!
Added a one liner.
This comment has been hidden.
This comment has been hidden.
!
Nice kata.
Why 1293 is not valid? "Test Failed: 1293 is not valid"
"ISBN-10 identifiers are ten digits."
This comment has been hidden.
I think this Kata is rated too high for the difficulty. I suggest Kata.kyu--;
It's a cool idea for a kata. This is the first time I've seen ISBN validation as a challenge. But I agree that it should be rated as a much easier kata.
Full Ack. Should be 6th kyu IMHO.
I second that as well. 6 kyu seems fair.
I have to agree. 5 or 6 kyu seems better suited than 4 kyu. Cool idea though.
+1 for --.
I agree. This was the easiest 4kyu i've done. Then again maybe it is the other ones that should be rated higher!