Ad
  • Custom User Avatar

    Question sufficiently answered.

  • Default User Avatar

    Thanks for this reply.
    I would not have been able to solve this without this hint. The colinear stuff in the description made literally no sense to me.

    It might be cool to add a bit more of a hint (or even the above links to the description) to help the people with shaky math know at least where to look.

    Great challenge.

  • Default User Avatar

    Lets say we have three points on a plane: A, B and C with coordinates A(xA, yA), B(xB, yB), C(xC, yC). We want to check if these three points are collinear (== lie on the same line). One of the way to do it is to use a formula for the area of a triangle:

                   |xA yA 1|
    S(ABC) = 1/2 * |xB yB 1|
                   |xC yC 1|
    

    The expression after 1/2 is the determinant of a 3x3 matrix.

    So, the points are collinear if and only if this determinant is equal to zero.

    Some links:

    Hope this helps.

    EDIT. Oops, just saw that your question was 2 years ago... :)

  • Custom User Avatar

    Yeah, fixed this

  • Custom User Avatar

    This is a fair point. I will add link to wiki on Isomorphism in set theory sense.

  • Default User Avatar

    Hi Fairyhunter... In the example, when the clue is 4, always exactly 4 skyscrapers are visible.

  • Default User Avatar

    The test cases did work just fine when I ran them on my computer too, but that says nothing about what's happening on the server side.

    1. Codewars is running your code against a suite of test cases that differ from the ones coming with the kata.
      This is to make sure you won't simply write a program that will only satisfy the unit test of the kata instead of a generic solution to the puzzle.

    2. Their server won't simply open a bash shell and run your code in a JVM instance on it.
      If they did, they would risk having their computers hacked. Any JVM 0day exploit that lets you manipulate the machines physical memory and it's "game over" for them.

    Because of that, they probably run any submitted code in some kind of disposable, sealed of environment. That environment, whatever it actually is, only mimics the behaviour of a JVM.
    You should not expect for your code to run in their environment in the same manner it does on yours. I am supremely sure they disabled many features in that "fake JVM" for security reasons.
    It may help thinking of it as a particularly nit-picky JVM that will give up the very moment it spots something fishy going down.

    As in my case, I suspect the "fake JVM" didn't take kindly to my attempt at a deep copy of the result set and botched big time. I can't say if my "fix" will work for you, but you may want to
    make sure you are using a String array that has been properly initialised to return your result set too.