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.