Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    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:

    test.it("is accurate ;-)")
    listPointsA = [(0,0),(2665,4242),(6397, 7584)]
    resultsA = [3, [[(2665, 4242),(6397, 7584)]], 5009.6695] # note that 5009.6695 is also the rounded distance of (0,0),(2665,4242)
    test.assert_equals(closest_points(listPointsA), resultsA)
    
  • Custom User Avatar

    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 all 0<k<n, you only need to sample finitely many canidate solutions for any given finite a, so a provably correct overall solution must exist. (I am not sure how to prevent that kind of brute force, but for large a 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 whether n-choose-k == a, if the candidate pairs are picked more reasonably.

  • Custom User Avatar

    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. :-)

  • Custom User Avatar

    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.

  • Custom User Avatar

    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 get Exception 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?

  • Custom User Avatar

    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 the parseInts input was Integer-parseable in the first place, but actually checked the wrong thing (index off-by-1).

  • Custom User Avatar

    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).