Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
Even although the first sentence calls for an accurate solution, many current solutions, including the one with most "best practices" upvotes (4), will fail the following test case, which I think should be added to rule out the not-quite-right solutions:
I am not aware of a general solution, and if one were known, I suspect Singmaster's conjecture would rather be known as Someone's theorem.
Anyway since
n-choose-k >= n
for all0<k<n
, you only need to sample finitely many canidate solutions for any given finitea
, so a provably correct overall solution must exist. (I am not sure how to prevent that kind of brute force, but for largea
it will probably time out already.)One should be able to pass all tests with this approach, i.e. find
(n,k)
candidate pairs and check whethern-choose-k == a
, if the candidate pairs are picked more reasonably.Well, the random test does not check your solution against mine, it only did a rather rudimentary plausibility check. I expanded it to do more plausibility checks. :-)
Oops...Fixed. (I had just copied the a section of the full test cases there. Seems I cannot run the example tests only from the author interface.) Sorry for the inconvenience.
No need to investigate, after I fixed the off-by-1-error my solution was fine. :-)
However, if I run
class Main {public static void main(String[] args) { Integer.parseInt("X"); }}
at repl.it, I getException in thread "main" java.lang.NumberFormatException: For input string: "X"
(and even more detail), so I blame the test setup here at least partially for not letting me know that there was a NumberFormatException involved, which would have been enough information to find the problem.Is the disappearance of the Exception name (or the fact that there was an exception at all) due to the way codewars runs the test or specific to the test setup of this Kata?
Thanks for the reply. Re: input in the console: Nope, must have been too tired to think of that. :-)
The problem was (I hope that is not spoiler-worthy...)
Integer.parseInt(...)
throwing (and only a little bit of the exception message reaching me): I thought I checked whether theparseInt
s input was Integer-parseable in the first place, but actually checked the wrong thing (index off-by-1).In the Java version, my attempts fail with '
MoreBasicTests(SolutionTest)
For input string: "X"
'. Nothing more. BasicTests pass, random tests fail with same message. Please forgive my ignorance (haven't solved many Java Katas yet), but what is 'For input string: "X"' supposed to mean? (For the record, my function returns 10 for input string "X". I did not see any requirement to validate the input, or what to return if it is not valid).