• + 1 comment

    Yes, it works

    My idea was to divide the original 6x6 matrix into 6x3 matrices. Each for loop adds all the hourglasses in each 6x3 matrix, so 4 loops were needed to cover the 6x6 matrix.

    For larger/smaller matrices, it would be necessary to adjust the loop parameters and add/remove loops, but it worked. However, I don't think it would be good for NxM matrices.