Ad
  • Default User Avatar

    you should see what sagemath can do. I strongly recommend using sagemath as it is python 3 with a huge library of extra modules specifically for applied and abstract mathematics.

  • Custom User Avatar

    Wow, a nice example of how much difference the choice of programming language can make. Thanks for the explanation. So I'm going to correct myself: It's not the kata. But it's the Java translation (or the language itself) which makes things very difficult.

  • Default User Avatar

    Maybe this kata is totally misranked and should be much higher

    I wrote the original kata in Haskell.
    The syntax for the function declaration and definition in Haskell is much simpler than in Java.

    In fact some people considered the Haskell kata too trivial to be approved.

  • Custom User Avatar

    or it just needs more explanation, or I'm a complete idiot

    No, you are not a complete idiot. It's the kata which is very misleading. Consider this example code:

      public static void main(String[] args) {
        Integer[] intArr = new Integer[] {1, 2, 3};
        Long[] objArr = cast(intArr); // no type erasure here, fails with ClassCastException
        System.out.println(objArr[0]);
    
        List<Integer> intList = List.of(1, 2, 3);
        List<Long> longList = cast(intList); // type erasure applies, does not fail
        System.out.println(longList.get(0)); // prints 1
        Long val = longList.get(0); // fails with ClassCastException
      }
    
      private static <T, R> R[] cast(T[] arr) {
        return (R[]) arr;
      }
    
      private static <T, R> List<R> cast(List<T> arr) {
        return (List<R>) arr;
      }
    

    Note how the cast(...) method can be compared to what a gridMap(...) implementation is supposed to do. I hope this helps.

  • Custom User Avatar

    It's just one step ahead of this one. Maybe you should try it first in Java.

  • Default User Avatar

    Agree. I find that the descriptions on a lot of the code challenges lacking. Spend more time trying to work out what the question is rather than finding a solution. Glad it wasn't just me trying ot figure out what to do.

  • Default User Avatar

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

  • Custom User Avatar

    Well, just tried it in Python and it was super easy.

  • Custom User Avatar

    I'm trying to learn Java and came across this kata. I was daunted by the syntax in the problem which I had never seen before. But I sat down, looked up the unknowns bit by bit, trying to understand what the problem was asking and how I might solve it.

    Despite my best efforts I couldn't get anywhere close. Not just a bad solution, or a partial one, I simply couldn't write an answer which even ran. I know a little bit more about Function, lambda, and generics, but my confidence kinda took a hit.

    Maybe this kata is totally misranked and should be much higher, or it just needs more explanation, or I'm a complete idiot. It could be the latter, I'm willing to admit that, but it feels like something is off with this kata.

  • Custom User Avatar

    Don't know why I didn't expect math to have a hypotenuse function. Should read the documentation.

  • Custom User Avatar

    My solution was similar to this one, but it shows the value of experience with the extras which they used:

    1. Using an * to unpack the tuple generated by divmod.
    2. Using the quotient operator to lose decimal places of a float (rather than casting to int).

    I'm glad I got close, but even gladder I could reference this answer to learn a little more.

    Thanks.