Matrix Jigsaw Puzzles












24












$begingroup$


Input:




  • An integer n

  • Two equal-sized square matrices (with their width/height being a multiple of n)


Output:



One of two distinct values of your own choice, one being for truthy results and one for falsey results (so yes, 1/0 instead of true/false are valid outputs for languages like Java, even though they're not considered official truthy/falsey values).



The truthy/falsey output indicates whether we can rearrange blocks of size n by n in one matrix to make it equal to the other matrix.



Example:



Input:



Matrix 1:
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 6 7 8
9 8 7 6 5 4
3 2 1 0 9 8
1 1 1 1 1 1

Matrix 2:
3 2 9 8 7 8
1 1 1 1 5 4
3 4 5 6 1 0
9 0 7 6 1 1
5 6 1 2 3 4
1 2 7 8 9 8

Integer n:
2


Output: truthy



Why?



If we split the matrices in blocks of 2 by 2, we can see that all blocks on one matrix can also be found in the other matrix:



Matrix 1:
1 2 | 3 4 | 5 6
7 8 | 9 0 | 1 2
---------------
3 4 | 5 6 | 7 8
9 8 | 7 6 | 5 4
---------------
3 2 | 1 0 | 9 8
1 1 | 1 1 | 1 1

Matrix 2:
3 2 | 9 8 | 7 8
1 1 | 1 1 | 5 4
---------------
3 4 | 5 6 | 1 0
9 0 | 7 6 | 1 1
---------------
5 6 | 1 2 | 3 4
1 2 | 7 8 | 9 8


Challenge rules:




  • You can assume the matrices will only contain non-negative digits (range [0,9])

  • You can assume the width/height of the matrices are equal, and a multiple of n

  • You can assume n will be in the range [1, 50], and the width/height of the matrices are in the range [1,100].

  • The individual blocks of n by n can only be used once to determine if the matrices are permutations of each other when split into blocks of n by n.

  • There can be multiple n by n blocks that are the same.

  • The n by n blocks will remain in the same orientation when checking if the two matrices are permutation of each other when split into blocks of n by n.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 2
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 1
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 3
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 3 4 4
2 3 4 5 2 3 4 5
3 4 5 6 3 4 5 6
4 5 6 7 4 5 6 7
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 3 4 3 4 2
2 3 4 5 4 5 4 5
3 4 5 6 1 2 5 6
4 5 6 7 2 3 6 6
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 2 3 1
3 4 1 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
0 8 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 1 2 2
5 6 7 8 5 6 5 6
9 0 0 9 0 9 9 0
4 3 2 1 2 1 4 3
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 1 2 9 5 1 2 2
3 4 3 4 7 7 3 4
8 3 9 5 1 2 8 3
6 1 7 7 3 4 6 1
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 0 2 0 0 3 1 1 1 0 0 3 2
1 1 1 1 1 1 2 0 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5
Output:
falsey


Pastebin with matrices in [[,]] format.










share|improve this question











$endgroup$












  • $begingroup$
    Can we take the matrices as a list of matrices?
    $endgroup$
    – Jo King
    Jan 14 at 9:46










  • $begingroup$
    @JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 9:47












  • $begingroup$
    Loosely related subset.
    $endgroup$
    – Mr. Xcoder
    Jan 14 at 11:15










  • $begingroup$
    Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
    $endgroup$
    – Olivier Grégoire
    Jan 14 at 12:59








  • 2




    $begingroup$
    @OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 13:01


















24












$begingroup$


Input:




  • An integer n

  • Two equal-sized square matrices (with their width/height being a multiple of n)


Output:



One of two distinct values of your own choice, one being for truthy results and one for falsey results (so yes, 1/0 instead of true/false are valid outputs for languages like Java, even though they're not considered official truthy/falsey values).



The truthy/falsey output indicates whether we can rearrange blocks of size n by n in one matrix to make it equal to the other matrix.



Example:



Input:



Matrix 1:
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 6 7 8
9 8 7 6 5 4
3 2 1 0 9 8
1 1 1 1 1 1

Matrix 2:
3 2 9 8 7 8
1 1 1 1 5 4
3 4 5 6 1 0
9 0 7 6 1 1
5 6 1 2 3 4
1 2 7 8 9 8

Integer n:
2


Output: truthy



Why?



If we split the matrices in blocks of 2 by 2, we can see that all blocks on one matrix can also be found in the other matrix:



Matrix 1:
1 2 | 3 4 | 5 6
7 8 | 9 0 | 1 2
---------------
3 4 | 5 6 | 7 8
9 8 | 7 6 | 5 4
---------------
3 2 | 1 0 | 9 8
1 1 | 1 1 | 1 1

Matrix 2:
3 2 | 9 8 | 7 8
1 1 | 1 1 | 5 4
---------------
3 4 | 5 6 | 1 0
9 0 | 7 6 | 1 1
---------------
5 6 | 1 2 | 3 4
1 2 | 7 8 | 9 8


Challenge rules:




  • You can assume the matrices will only contain non-negative digits (range [0,9])

  • You can assume the width/height of the matrices are equal, and a multiple of n

  • You can assume n will be in the range [1, 50], and the width/height of the matrices are in the range [1,100].

  • The individual blocks of n by n can only be used once to determine if the matrices are permutations of each other when split into blocks of n by n.

  • There can be multiple n by n blocks that are the same.

  • The n by n blocks will remain in the same orientation when checking if the two matrices are permutation of each other when split into blocks of n by n.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 2
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 1
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 3
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 3 4 4
2 3 4 5 2 3 4 5
3 4 5 6 3 4 5 6
4 5 6 7 4 5 6 7
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 3 4 3 4 2
2 3 4 5 4 5 4 5
3 4 5 6 1 2 5 6
4 5 6 7 2 3 6 6
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 2 3 1
3 4 1 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
0 8 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 1 2 2
5 6 7 8 5 6 5 6
9 0 0 9 0 9 9 0
4 3 2 1 2 1 4 3
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 1 2 9 5 1 2 2
3 4 3 4 7 7 3 4
8 3 9 5 1 2 8 3
6 1 7 7 3 4 6 1
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 0 2 0 0 3 1 1 1 0 0 3 2
1 1 1 1 1 1 2 0 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5
Output:
falsey


Pastebin with matrices in [[,]] format.










share|improve this question











$endgroup$












  • $begingroup$
    Can we take the matrices as a list of matrices?
    $endgroup$
    – Jo King
    Jan 14 at 9:46










  • $begingroup$
    @JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 9:47












  • $begingroup$
    Loosely related subset.
    $endgroup$
    – Mr. Xcoder
    Jan 14 at 11:15










  • $begingroup$
    Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
    $endgroup$
    – Olivier Grégoire
    Jan 14 at 12:59








  • 2




    $begingroup$
    @OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 13:01
















24












24








24


2



$begingroup$


Input:




  • An integer n

  • Two equal-sized square matrices (with their width/height being a multiple of n)


Output:



One of two distinct values of your own choice, one being for truthy results and one for falsey results (so yes, 1/0 instead of true/false are valid outputs for languages like Java, even though they're not considered official truthy/falsey values).



The truthy/falsey output indicates whether we can rearrange blocks of size n by n in one matrix to make it equal to the other matrix.



Example:



Input:



Matrix 1:
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 6 7 8
9 8 7 6 5 4
3 2 1 0 9 8
1 1 1 1 1 1

Matrix 2:
3 2 9 8 7 8
1 1 1 1 5 4
3 4 5 6 1 0
9 0 7 6 1 1
5 6 1 2 3 4
1 2 7 8 9 8

Integer n:
2


Output: truthy



Why?



If we split the matrices in blocks of 2 by 2, we can see that all blocks on one matrix can also be found in the other matrix:



Matrix 1:
1 2 | 3 4 | 5 6
7 8 | 9 0 | 1 2
---------------
3 4 | 5 6 | 7 8
9 8 | 7 6 | 5 4
---------------
3 2 | 1 0 | 9 8
1 1 | 1 1 | 1 1

Matrix 2:
3 2 | 9 8 | 7 8
1 1 | 1 1 | 5 4
---------------
3 4 | 5 6 | 1 0
9 0 | 7 6 | 1 1
---------------
5 6 | 1 2 | 3 4
1 2 | 7 8 | 9 8


Challenge rules:




  • You can assume the matrices will only contain non-negative digits (range [0,9])

  • You can assume the width/height of the matrices are equal, and a multiple of n

  • You can assume n will be in the range [1, 50], and the width/height of the matrices are in the range [1,100].

  • The individual blocks of n by n can only be used once to determine if the matrices are permutations of each other when split into blocks of n by n.

  • There can be multiple n by n blocks that are the same.

  • The n by n blocks will remain in the same orientation when checking if the two matrices are permutation of each other when split into blocks of n by n.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 2
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 1
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 3
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 3 4 4
2 3 4 5 2 3 4 5
3 4 5 6 3 4 5 6
4 5 6 7 4 5 6 7
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 3 4 3 4 2
2 3 4 5 4 5 4 5
3 4 5 6 1 2 5 6
4 5 6 7 2 3 6 6
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 2 3 1
3 4 1 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
0 8 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 1 2 2
5 6 7 8 5 6 5 6
9 0 0 9 0 9 9 0
4 3 2 1 2 1 4 3
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 1 2 9 5 1 2 2
3 4 3 4 7 7 3 4
8 3 9 5 1 2 8 3
6 1 7 7 3 4 6 1
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 0 2 0 0 3 1 1 1 0 0 3 2
1 1 1 1 1 1 2 0 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5
Output:
falsey


Pastebin with matrices in [[,]] format.










share|improve this question











$endgroup$




Input:




  • An integer n

  • Two equal-sized square matrices (with their width/height being a multiple of n)


Output:



One of two distinct values of your own choice, one being for truthy results and one for falsey results (so yes, 1/0 instead of true/false are valid outputs for languages like Java, even though they're not considered official truthy/falsey values).



The truthy/falsey output indicates whether we can rearrange blocks of size n by n in one matrix to make it equal to the other matrix.



Example:



Input:



Matrix 1:
1 2 3 4 5 6
7 8 9 0 1 2
3 4 5 6 7 8
9 8 7 6 5 4
3 2 1 0 9 8
1 1 1 1 1 1

Matrix 2:
3 2 9 8 7 8
1 1 1 1 5 4
3 4 5 6 1 0
9 0 7 6 1 1
5 6 1 2 3 4
1 2 7 8 9 8

Integer n:
2


Output: truthy



Why?



If we split the matrices in blocks of 2 by 2, we can see that all blocks on one matrix can also be found in the other matrix:



Matrix 1:
1 2 | 3 4 | 5 6
7 8 | 9 0 | 1 2
---------------
3 4 | 5 6 | 7 8
9 8 | 7 6 | 5 4
---------------
3 2 | 1 0 | 9 8
1 1 | 1 1 | 1 1

Matrix 2:
3 2 | 9 8 | 7 8
1 1 | 1 1 | 5 4
---------------
3 4 | 5 6 | 1 0
9 0 | 7 6 | 1 1
---------------
5 6 | 1 2 | 3 4
1 2 | 7 8 | 9 8


Challenge rules:




  • You can assume the matrices will only contain non-negative digits (range [0,9])

  • You can assume the width/height of the matrices are equal, and a multiple of n

  • You can assume n will be in the range [1, 50], and the width/height of the matrices are in the range [1,100].

  • The individual blocks of n by n can only be used once to determine if the matrices are permutations of each other when split into blocks of n by n.

  • There can be multiple n by n blocks that are the same.

  • The n by n blocks will remain in the same orientation when checking if the two matrices are permutation of each other when split into blocks of n by n.


General rules:




  • This is code-golf, so shortest answer in bytes wins.

    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.


  • Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.


  • Default Loopholes are forbidden.

  • If possible, please add a link with a test for your code (i.e. TIO).

  • Also, adding an explanation for your answer is highly recommended.


Test cases:



Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 2
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 1
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 5 6 3 2 9 8 7 8 3
7 8 9 0 1 2 1 1 1 1 5 4
3 4 5 6 7 8 3 4 5 6 1 0
9 8 7 6 5 4 9 0 7 6 1 1
3 2 1 0 9 8 5 6 1 2 3 4
1 1 1 1 1 1 1 2 7 8 9 8
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 3 4 4
2 3 4 5 2 3 4 5
3 4 5 6 3 4 5 6
4 5 6 7 4 5 6 7
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 3 4 3 4 2
2 3 4 5 4 5 4 5
3 4 5 6 1 2 5 6
4 5 6 7 2 3 6 6
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 2 3 1
3 4 1 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
0 8 1
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 3 4 1 2 1 2 2
5 6 7 8 5 6 5 6
9 0 0 9 0 9 9 0
4 3 2 1 2 1 4 3
Output:
falsey

Input:
Matrix 1: Matrix 2: Integer:
1 2 1 2 9 5 1 2 2
3 4 3 4 7 7 3 4
8 3 9 5 1 2 8 3
6 1 7 7 3 4 6 1
Output:
truthy

Input:
Matrix 1: Matrix 2: Integer:
1 0 2 0 0 3 1 1 1 0 0 3 2
1 1 1 1 1 1 2 0 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2
3 3 3 3 3 3 3 3 3 3 3 3
4 4 4 4 4 4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5 5 5 5
Output:
falsey


Pastebin with matrices in [[,]] format.







code-golf number integer matrix






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 14 at 13:00







Kevin Cruijssen

















asked Jan 14 at 7:58









Kevin CruijssenKevin Cruijssen

36.6k555192




36.6k555192












  • $begingroup$
    Can we take the matrices as a list of matrices?
    $endgroup$
    – Jo King
    Jan 14 at 9:46










  • $begingroup$
    @JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 9:47












  • $begingroup$
    Loosely related subset.
    $endgroup$
    – Mr. Xcoder
    Jan 14 at 11:15










  • $begingroup$
    Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
    $endgroup$
    – Olivier Grégoire
    Jan 14 at 12:59








  • 2




    $begingroup$
    @OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 13:01




















  • $begingroup$
    Can we take the matrices as a list of matrices?
    $endgroup$
    – Jo King
    Jan 14 at 9:46










  • $begingroup$
    @JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 9:47












  • $begingroup$
    Loosely related subset.
    $endgroup$
    – Mr. Xcoder
    Jan 14 at 11:15










  • $begingroup$
    Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
    $endgroup$
    – Olivier Grégoire
    Jan 14 at 12:59








  • 2




    $begingroup$
    @OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
    $endgroup$
    – Kevin Cruijssen
    Jan 14 at 13:01


















$begingroup$
Can we take the matrices as a list of matrices?
$endgroup$
– Jo King
Jan 14 at 9:46




$begingroup$
Can we take the matrices as a list of matrices?
$endgroup$
– Jo King
Jan 14 at 9:46












$begingroup$
@JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
$endgroup$
– Kevin Cruijssen
Jan 14 at 9:47






$begingroup$
@JoKing You mean a list with both matrices instead of two separated matrix-inputs? If that's what you're asking, then sure, why not.
$endgroup$
– Kevin Cruijssen
Jan 14 at 9:47














$begingroup$
Loosely related subset.
$endgroup$
– Mr. Xcoder
Jan 14 at 11:15




$begingroup$
Loosely related subset.
$endgroup$
– Mr. Xcoder
Jan 14 at 11:15












$begingroup$
Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
$endgroup$
– Olivier Grégoire
Jan 14 at 12:59






$begingroup$
Why is the example [ [ 0 ] ], [ [ 25 ] ], 1 present? I understood with You can assume the matrices will only contain non-negative digits (range [0,9]) that the matrix values are only between 0 and 9?
$endgroup$
– Olivier Grégoire
Jan 14 at 12:59






2




2




$begingroup$
@OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
$endgroup$
– Kevin Cruijssen
Jan 14 at 13:01






$begingroup$
@OlivierGrégoire Sorry, added that rule about range [0,9] later on in the Sandbox. I've changed the test case to [[0]],[[8]].
$endgroup$
– Kevin Cruijssen
Jan 14 at 13:01












15 Answers
15






active

oldest

votes


















8












$begingroup$


APL (Dyalog Extended), 19 18 bytes





-1 thanks to ngn.



Anonymous tacit infix function. Takes n as left argument and list of two matrices as right argument. Requires zero-indexing (⎕IO←0). Incidentally, this function works on arrays of any number of dimensions.



≡/{∧,⍵⊂⍨⊂0=⍺|⍳≢⍵}¨


Try it online!



{ for each matrix with n as , call the following function:



≢⍵ size of matrix



 indices 0…size–1



⍺| division remainder when divided by n



 enclose to use along all dimensions



⍵⊂⍨ use that to partition* the matrix into a matrix of submatrices

  * begins new partition when corresponding element is less than the previous; removes elements marked by zero



, ravel the matrix into a list of submatrices



 sort ascending



≡/ are the sorted lists of submatrices identical?






share|improve this answer











$endgroup$













  • $begingroup$
    (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
    $endgroup$
    – ngn
    Jan 14 at 16:23










  • $begingroup$
    @ngn Thanks. Done.
    $endgroup$
    – Adám
    Jan 14 at 21:56



















6












$begingroup$


Python 2, 108 103 bytes





lambda s,*a:len(set(`sorted(sum([zip(*[iter(zip(*l))]*s)for l in zip(*[iter(m)]*s)],))`for m in a))<2


Try it online!






share|improve this answer











$endgroup$





















    6












    $begingroup$


    Perl 6, 94 68 63 bytes





    {[eqv] map *.rotor($^a).map({[Z] $_}).flat.rotor($a²).sort,@_}


    Try it online!



    Anonymous code block that takes input as size, [matrix1, matrix2] and returns a boolean True/False. There might be a more efficient way of splitting the matrix into chunks than rotor.



    Explanation:



    {                                                            }  # Anonymous code block
    map ,@_ # For both matrices
    *.rotor($^a) # Split the matrix into N sized chunks
    .map({[Z] $_}) # Then zip each of those chunks together
    .flat # Flatten the resulting list
    .rotor($a²) # Then split into the NxN lists
    .sort # And sort them
    [eqv] # And then check if the lists are equivalent





    share|improve this answer











    $endgroup$





















      6












      $begingroup$


      05AB1E, 14 bytes



      εε²ô}ø˜²ô²ô{]Ë


      Try it online!






      share|improve this answer











      $endgroup$





















        4












        $begingroup$


        Java (JDK), 221 bytes





        (n,a,b)->{java.util.Arrays A=null;int l=a.length,x=l/n,i=0,j,z;var c=new String[x*x];A.fill(c,"");var d=c.clone();for(;i<l;i++)for(j=0;j<l;d[z]+=b[i][j++])c[z=i/n+j/n*x]+=a[i][j];A.sort(c);A.sort(d);return A.equals(c,d);}


        Try it online!



        Explanation



        The idea is to pick each small cell as a string, which is comparable, and then to sort those strings and compare them in order.



        (n,a,b)->{
        java.util.Arrays A=null; // Shortcut A for the several java.util.Arrays that'll come
        int l=a.length,x=l/n,i=0,j,z; // Variable declarations
        var c=new String[x*x]; // Declare the small squares list
        A.fill(c,""); // Fill the lists of small squares with the empty string.
        var d=c.clone(); // Make a copy of the list, for the second matrix
        for(;i<l;i++)
        for(j=0;j<l;d[z]+=b[i][j++]) // For each matrix cell
        c[z=i/n+j/n*x]+=a[i][j]; // Fill the small square with the value, string-wise
        A.sort(c);A.sort(d); // Sort both small squares list
        return A.equals(c,d); // Return true if they're equal, false otherwise.
        }


        Credits




        • -12 bytes thanks to Kevin Cruijssen!






        share|improve this answer











        $endgroup$













        • $begingroup$
          Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
          $endgroup$
          – Kevin Cruijssen
          Jan 14 at 13:28










        • $begingroup$
          And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
          $endgroup$
          – Kevin Cruijssen
          Jan 14 at 13:29










        • $begingroup$
          PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
          $endgroup$
          – Kevin Cruijssen
          Jan 14 at 13:31










        • $begingroup$
          Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
          $endgroup$
          – Olivier Grégoire
          Jan 14 at 13:33










        • $begingroup$
          The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
          $endgroup$
          – Olivier Grégoire
          Jan 14 at 13:36





















        4












        $begingroup$


        Jelly,  10  9 bytes



        ż⁹/ẎsṢʋ€E


        Try it online! (or with pre-processing for easier copy & paste from the test cases)



        A dyadic Link accepting a list of the two matrices (as lists of lists) on the left and the integer on the right which yields 1 or 0 for truthy or falsey respectively.



        How?



        ż⁹/ẎsṢʋ€E - Link: [M1, M2]; N
        € - for each of [M1, M2]:
        ʋ - last four links as a dyad (i.e. f(M, N)):
        ⁹ - (chain's right argument, N)
        ⁹/ - N-wise-reduce with:
        ż - zip together
        Ẏ - tighten
        s - split into chunks of length N
        Ṣ - sort
        E - equal?





        share|improve this answer











        $endgroup$





















          4












          $begingroup$


          Japt, 18 bytes



          ®mòV yòV rc n qÃr¥


          Try it online!



          Explanation:



          ®              Ã      #Apply this to each of the input matrices:
          mòV # Split each row into groups of n
          yòV # Split each column into groups of n
          rc # Flatten into a list of nxn submatrices
          n # Sort that list
          q # Turn it into a string
          r¥ #Return true if both matrices had identical results


          The "Turn it into a string" step is necessary because Japt doesn't compare arrays by value and the builtin to work around that doesn't work for multidimensional arrays.






          share|improve this answer











          $endgroup$









          • 2




            $begingroup$
            I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
            $endgroup$
            – Shaggy
            Jan 14 at 21:30










          • $begingroup$
            By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
            $endgroup$
            – Shaggy
            Jan 15 at 12:57



















          4












          $begingroup$

          TSQL, 164 bytes



          Populating a table variable in order to have input, this creating input and inserting data has not been included in the byte count. Only the actual query to extract the data.



          Golfed(not including test table - it can be found in the ungolfed version):



          SELECT iif(exists(SELECT*FROM(SELECT string_agg(v,'')within
          group(order by x,y)s,m FROM @t GROUP BY x/@,y/@,m)x
          GROUP BY s HAVING max(m)=min(m)or sum(m-.5)<>0),0,1)


          Ungolfed:



          -- test data
          DECLARE @ INT = 2
          -- x = x-position of the input
          -- y = y-position of the input
          -- v = value
          -- m = matrix(0 or 1)
          DECLARE @t table(x int, y int, v int, m int)
          --insert first matrix values
          INSERT @t values
          (0,0,1,0),(0,1,2,0),(0,2,1,0),(0,3,2,0),
          (1,0,3,0),(1,1,4,0),(1,2,3,0),(1,3,4,0),
          (2,0,8,0),(2,1,3,0),(2,2,9,0),(2,3,5,0),
          (3,0,6,0),(3,1,1,0),(3,2,7,0),(3,3,7,0)
          INSERT @t values
          (0,0,9,1),(0,1,5,1),(0,2,1,1),(0,3,2,1),
          (1,0,7,1),(1,1,7,1),(1,2,3,1),(1,3,4,1),
          (2,0,1,1),(2,1,2,1),(2,2,8,1),(2,3,3,1),
          (3,0,3,1),(3,1,4,1),(3,2,6,1),(3,3,1,1)

          -- query
          SELECT iif(exists
          (
          SELECT *
          FROM
          (
          SELECT string_agg(v,'')within group(order by x,y)s,m
          FROM @t
          GROUP BY x/@,y/@,m
          ) x
          GROUP BY s
          HAVING max(m)=min(m)or sum(m-.5)<>0
          ),0,1)


          Try it out






          share|improve this answer











          $endgroup$





















            4












            $begingroup$

            JavaScript (ES6), 88 bytes





            (n,a,b)=>(g=a=>a.map((r,y)=>r.map((v,x)=>o[y/n<<7|x/n]+=[v]),o=)&&o.sort()+o)(a)==g(b)


            Try it online!



            How?



            This code is:




            • extracting all sub-matrices in each input matrix as a concatenation of cells

            • sorting the sub-matrices in lexicographical order

            • testing whether the result is the same for both input matrices


            It is taking advantage of the limits described in the challenge:




            • A matrix consists of single digits, so we can just concatenate all cells of a sub-matrix without any separator and still get a unique representation of it (e.g. [[1,2],[3,4]] can be stored as "1234").



            • The width of the input matrices is less than or equal to $100$. To convert the coordinates $(x,y)$ in an input matrix into a unique slot index $I$ in our storage area, we can do:



              $$I=leftlfloorfrac{y}{n}rightrfloortimes128+leftlfloorfrac{x}{n}rightrfloor$$



              or as JS code: y / n << 7 | x << n




            Commented



            (n, a, b) =>           // n, a, b = input variables (integer, matrix 1, matrix 2)
            (g = a => // g = helper function taking one of the two matrices
            a.map((r, y) => // for each row r at position y in a:
            r.map((v, x) => // for each value v at position x in r:
            o[ // update o:
            y / n << 7 | // the position of the slot is computed by taking advantage
            x / n // of the limit on the matrix width (see above)
            ] += [v] // coerce v to a string and append it to o[slot]
            // all slots are initially undefined, so all resulting strings
            // are going to start with "undefined", which is harmless
            ), // end of inner map()
            o = // start with o = empty array
            ) && // end of outer map()
            o.sort() + o // sort o and coerce it to a string by concatenating it with itself
            )(a) == g(b) // test whether g(a) is equal to g(b)





            share|improve this answer











            $endgroup$





















              3












              $begingroup$


              Charcoal, 54 49 bytes



              1FθF⪪ιηF÷L§κ⁰η⊞υEκ§⪪μηλW∧υ⊟υ¿№✂υ⁰⊘⊕Lυ¹ι≔Φυ⁻⌕υιλυ⎚


              Try it online! Link is to verbose version of code. Takes input as an array of equal-sized two-dimensional arrays. Outputs 1 on success, nothing on failure. Explanation:



              1


              Assume success.



              Fθ


              Loop over the arrays.



              F⪪ιη


              Divide the array into n-sized row chunks.



              F÷L§κ⁰η


              Loop over each column chunk.



              ⊞υEκ§⪪μηλ


              Extract the column chunk for each row of the row chunk and save the resulting submatrix in a list.



              W∧υ⊟υ


              While the list is nonempty, remove the last chunk of the list, which under normal circumstances comes from the second array.



              ¿№✂υ⁰⊘⊕Lυ¹ι


              Count the number of occurrences of that chunk in the first half of the list, which under normal circumstances contains the remaining chunks from the first array.



              ≔Φυ⁻⌕υιλυ


              If nonzero then remove the first occurrence of that chunk from the list.






              If zero then clear the output, making it falsy.






              share|improve this answer











              $endgroup$





















                2












                $begingroup$


                J, 55 bytes



                [:-:/[([:/:~([*-@[)],@])"3(((;])@(#@]$1{.~[),;.1])&>])


                Try it online!



                A horrible solution, just made it work - I have no power to golf it...






                share|improve this answer









                $endgroup$





















                  2












                  $begingroup$

                  Haskell, 74 73 bytes



                  import Data.Lists
                  i#m|c<-chunksOf i=c.transpose=<<c m
                  (m!n)i=i#m\i#n==


                  Note: TIO hasn't installed Data.Lists, so I'm using Data.List instead an add the missing function chunksOf: Try it online!



                  i#m=           -- function '#' makes a list of all transposed jigsaw blocks of matrix 'm'
                  -- of size 'i'
                  c<-chunksOf i -- define helper function 'c' that splits it's argument into
                  -- chunks of site 'i'
                  c m -- split the matrix into chunks of size 'i'
                  =<< -- for each chunk
                  transpose -- transpose
                  c. -- and split into chunks of size 'i', again
                  -- flatten one level of nesting ('=<<' is concatMap)

                  (m!n)i= -- main function
                  i#m\i#n -- remove every element of i#n from i#m
                  == -- and check if it results in an empty list





                  share|improve this answer











                  $endgroup$





















                    2












                    $begingroup$


                    C# (Visual C# Interactive Compiler), 186 bytes





                    (a,b,n)=>{strings(intc){int i=0,j,l=a.Length,m=l/n;var r=new string[m*m];for(;i<l;i++)for(j=0;j<l;)r[i/n*m+j/n]+=c[i][j++];Array.Sort(r);return r;}return s(a).SequenceEqual(s(b));}


                    Try it online!



                    -1 thanks to @KevinCruijssen!



                    Less golfed code:



                    // anonymous function
                    // a and b are 2d jagged arrays
                    // n is the size of the sub matrix
                    (a,b,n)=>{
                    // helper function that translates
                    // the sub matrices into strings
                    // of digits.
                    strings(intc){
                    // i and j are loop counters
                    int i=0,j,
                    // l is the size of a side of a matrix
                    l=a.Length,
                    // m is the number of sub matrices
                    // per side of a matrix
                    m=l/n;
                    // the concatenated digits are
                    // stored in a single dimension
                    // array
                    var r=new string[m*m];
                    // nested loops build up
                    // the digit strings
                    for(;i<l;i++)
                    for(j=0;j<l;)
                    r[i/n*m+j/n]+=c[i][j++];
                    // The resulting array is
                    // sorted before it is returned for
                    // ease of comparison.
                    Array.Sort(r);
                    return r;
                    }
                    return s(a).SequenceEqual(s(b));
                    }





                    share|improve this answer











                    $endgroup$













                    • $begingroup$
                      One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                      $endgroup$
                      – Kevin Cruijssen
                      Jan 15 at 6:57










                    • $begingroup$
                      Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                      $endgroup$
                      – dana
                      Jan 15 at 7:02



















                    1












                    $begingroup$


                    PHP, 186 163 162 bytes





                    function($a,$b,$n){$f=function($j,$n){foreach($j as$x=>$r)foreach($r as$y=>$v)$o[count($j)*($x/$n|0)+$y/$n|0].=$v;sort($o);return$o;};return$f($a,$n)==$f($b,$n);}


                    Try it online!



                    Like all good challenges, I started off thinking this was fairly easy and it threw me some curves. Nicely done @Kevin Cruijssen!



                    Chunks the matrix into strings containing the values for each block. Arrays are then sorted and compared for equality.



                    Ungolfed:



                    function jigsaw_chunk( $j, $n ) {
                    foreach( $j as $x => $r ) {
                    foreach( $r as $y => $v ) {
                    $o[ count( $j ) * floor( $x/$n ) + floor( $y/$n )] .= $v;
                    }
                    }
                    sort( $o );
                    return $o;
                    }

                    function jigsaw_test( $a, $b, $n ) {
                    return jigsaw_chunk( $a, $n ) == jigsaw_chunk( $b, $n );
                    }

                    // Test 6
                    var_dump( jigsaw_test( [[1,2],[3,4]], [[2,3],[1,1]], 1 ) );


                    Output



                    bool(false)





                    share|improve this answer











                    $endgroup$





















                      1












                      $begingroup$


                      Red, 148 147 142 bytes



                      func[a b n][g: func[m][
                      sort collect[loop k:(length? m)/ n[i: 0
                      loop k[keep/only
                      collect[loop n[keep
                      take/part m/(i: i + 1) n]]]]]](g a)= g b]


                      Try it online!






                      share|improve this answer











                      $endgroup$













                        Your Answer





                        StackExchange.ifUsing("editor", function () {
                        return StackExchange.using("mathjaxEditing", function () {
                        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                        });
                        });
                        }, "mathjax-editing");

                        StackExchange.ifUsing("editor", function () {
                        StackExchange.using("externalEditor", function () {
                        StackExchange.using("snippets", function () {
                        StackExchange.snippets.init();
                        });
                        });
                        }, "code-snippets");

                        StackExchange.ready(function() {
                        var channelOptions = {
                        tags: "".split(" "),
                        id: "200"
                        };
                        initTagRenderer("".split(" "), "".split(" "), channelOptions);

                        StackExchange.using("externalEditor", function() {
                        // Have to fire editor after snippets, if snippets enabled
                        if (StackExchange.settings.snippets.snippetsEnabled) {
                        StackExchange.using("snippets", function() {
                        createEditor();
                        });
                        }
                        else {
                        createEditor();
                        }
                        });

                        function createEditor() {
                        StackExchange.prepareEditor({
                        heartbeatType: 'answer',
                        autoActivateHeartbeat: false,
                        convertImagesToLinks: false,
                        noModals: true,
                        showLowRepImageUploadWarning: true,
                        reputationToPostImages: null,
                        bindNavPrevention: true,
                        postfix: "",
                        imageUploader: {
                        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                        allowUrls: true
                        },
                        onDemand: true,
                        discardSelector: ".discard-answer"
                        ,immediatelyShowMarkdownHelp:true
                        });


                        }
                        });














                        draft saved

                        draft discarded


















                        StackExchange.ready(
                        function () {
                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178728%2fmatrix-jigsaw-puzzles%23new-answer', 'question_page');
                        }
                        );

                        Post as a guest















                        Required, but never shown

























                        15 Answers
                        15






                        active

                        oldest

                        votes








                        15 Answers
                        15






                        active

                        oldest

                        votes









                        active

                        oldest

                        votes






                        active

                        oldest

                        votes









                        8












                        $begingroup$


                        APL (Dyalog Extended), 19 18 bytes





                        -1 thanks to ngn.



                        Anonymous tacit infix function. Takes n as left argument and list of two matrices as right argument. Requires zero-indexing (⎕IO←0). Incidentally, this function works on arrays of any number of dimensions.



                        ≡/{∧,⍵⊂⍨⊂0=⍺|⍳≢⍵}¨


                        Try it online!



                        { for each matrix with n as , call the following function:



                        ≢⍵ size of matrix



                         indices 0…size–1



                        ⍺| division remainder when divided by n



                         enclose to use along all dimensions



                        ⍵⊂⍨ use that to partition* the matrix into a matrix of submatrices

                          * begins new partition when corresponding element is less than the previous; removes elements marked by zero



                        , ravel the matrix into a list of submatrices



                         sort ascending



                        ≡/ are the sorted lists of submatrices identical?






                        share|improve this answer











                        $endgroup$













                        • $begingroup$
                          (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                          $endgroup$
                          – ngn
                          Jan 14 at 16:23










                        • $begingroup$
                          @ngn Thanks. Done.
                          $endgroup$
                          – Adám
                          Jan 14 at 21:56
















                        8












                        $begingroup$


                        APL (Dyalog Extended), 19 18 bytes





                        -1 thanks to ngn.



                        Anonymous tacit infix function. Takes n as left argument and list of two matrices as right argument. Requires zero-indexing (⎕IO←0). Incidentally, this function works on arrays of any number of dimensions.



                        ≡/{∧,⍵⊂⍨⊂0=⍺|⍳≢⍵}¨


                        Try it online!



                        { for each matrix with n as , call the following function:



                        ≢⍵ size of matrix



                         indices 0…size–1



                        ⍺| division remainder when divided by n



                         enclose to use along all dimensions



                        ⍵⊂⍨ use that to partition* the matrix into a matrix of submatrices

                          * begins new partition when corresponding element is less than the previous; removes elements marked by zero



                        , ravel the matrix into a list of submatrices



                         sort ascending



                        ≡/ are the sorted lists of submatrices identical?






                        share|improve this answer











                        $endgroup$













                        • $begingroup$
                          (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                          $endgroup$
                          – ngn
                          Jan 14 at 16:23










                        • $begingroup$
                          @ngn Thanks. Done.
                          $endgroup$
                          – Adám
                          Jan 14 at 21:56














                        8












                        8








                        8





                        $begingroup$


                        APL (Dyalog Extended), 19 18 bytes





                        -1 thanks to ngn.



                        Anonymous tacit infix function. Takes n as left argument and list of two matrices as right argument. Requires zero-indexing (⎕IO←0). Incidentally, this function works on arrays of any number of dimensions.



                        ≡/{∧,⍵⊂⍨⊂0=⍺|⍳≢⍵}¨


                        Try it online!



                        { for each matrix with n as , call the following function:



                        ≢⍵ size of matrix



                         indices 0…size–1



                        ⍺| division remainder when divided by n



                         enclose to use along all dimensions



                        ⍵⊂⍨ use that to partition* the matrix into a matrix of submatrices

                          * begins new partition when corresponding element is less than the previous; removes elements marked by zero



                        , ravel the matrix into a list of submatrices



                         sort ascending



                        ≡/ are the sorted lists of submatrices identical?






                        share|improve this answer











                        $endgroup$




                        APL (Dyalog Extended), 19 18 bytes





                        -1 thanks to ngn.



                        Anonymous tacit infix function. Takes n as left argument and list of two matrices as right argument. Requires zero-indexing (⎕IO←0). Incidentally, this function works on arrays of any number of dimensions.



                        ≡/{∧,⍵⊂⍨⊂0=⍺|⍳≢⍵}¨


                        Try it online!



                        { for each matrix with n as , call the following function:



                        ≢⍵ size of matrix



                         indices 0…size–1



                        ⍺| division remainder when divided by n



                         enclose to use along all dimensions



                        ⍵⊂⍨ use that to partition* the matrix into a matrix of submatrices

                          * begins new partition when corresponding element is less than the previous; removes elements marked by zero



                        , ravel the matrix into a list of submatrices



                         sort ascending



                        ≡/ are the sorted lists of submatrices identical?







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jan 14 at 21:55

























                        answered Jan 14 at 8:54









                        AdámAdám

                        29.5k271194




                        29.5k271194












                        • $begingroup$
                          (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                          $endgroup$
                          – ngn
                          Jan 14 at 16:23










                        • $begingroup$
                          @ngn Thanks. Done.
                          $endgroup$
                          – Adám
                          Jan 14 at 21:56


















                        • $begingroup$
                          (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                          $endgroup$
                          – ngn
                          Jan 14 at 16:23










                        • $begingroup$
                          @ngn Thanks. Done.
                          $endgroup$
                          – Adám
                          Jan 14 at 21:56
















                        $begingroup$
                        (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                        $endgroup$
                        – ngn
                        Jan 14 at 16:23




                        $begingroup$
                        (≢⍵)⍴⍺↑1 -> 0=⍺|⍳≢⍵ (with ⎕io←0)
                        $endgroup$
                        – ngn
                        Jan 14 at 16:23












                        $begingroup$
                        @ngn Thanks. Done.
                        $endgroup$
                        – Adám
                        Jan 14 at 21:56




                        $begingroup$
                        @ngn Thanks. Done.
                        $endgroup$
                        – Adám
                        Jan 14 at 21:56











                        6












                        $begingroup$


                        Python 2, 108 103 bytes





                        lambda s,*a:len(set(`sorted(sum([zip(*[iter(zip(*l))]*s)for l in zip(*[iter(m)]*s)],))`for m in a))<2


                        Try it online!






                        share|improve this answer











                        $endgroup$


















                          6












                          $begingroup$


                          Python 2, 108 103 bytes





                          lambda s,*a:len(set(`sorted(sum([zip(*[iter(zip(*l))]*s)for l in zip(*[iter(m)]*s)],))`for m in a))<2


                          Try it online!






                          share|improve this answer











                          $endgroup$
















                            6












                            6








                            6





                            $begingroup$


                            Python 2, 108 103 bytes





                            lambda s,*a:len(set(`sorted(sum([zip(*[iter(zip(*l))]*s)for l in zip(*[iter(m)]*s)],))`for m in a))<2


                            Try it online!






                            share|improve this answer











                            $endgroup$




                            Python 2, 108 103 bytes





                            lambda s,*a:len(set(`sorted(sum([zip(*[iter(zip(*l))]*s)for l in zip(*[iter(m)]*s)],))`for m in a))<2


                            Try it online!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 14 at 9:45

























                            answered Jan 14 at 8:59









                            TFeldTFeld

                            14.6k21241




                            14.6k21241























                                6












                                $begingroup$


                                Perl 6, 94 68 63 bytes





                                {[eqv] map *.rotor($^a).map({[Z] $_}).flat.rotor($a²).sort,@_}


                                Try it online!



                                Anonymous code block that takes input as size, [matrix1, matrix2] and returns a boolean True/False. There might be a more efficient way of splitting the matrix into chunks than rotor.



                                Explanation:



                                {                                                            }  # Anonymous code block
                                map ,@_ # For both matrices
                                *.rotor($^a) # Split the matrix into N sized chunks
                                .map({[Z] $_}) # Then zip each of those chunks together
                                .flat # Flatten the resulting list
                                .rotor($a²) # Then split into the NxN lists
                                .sort # And sort them
                                [eqv] # And then check if the lists are equivalent





                                share|improve this answer











                                $endgroup$


















                                  6












                                  $begingroup$


                                  Perl 6, 94 68 63 bytes





                                  {[eqv] map *.rotor($^a).map({[Z] $_}).flat.rotor($a²).sort,@_}


                                  Try it online!



                                  Anonymous code block that takes input as size, [matrix1, matrix2] and returns a boolean True/False. There might be a more efficient way of splitting the matrix into chunks than rotor.



                                  Explanation:



                                  {                                                            }  # Anonymous code block
                                  map ,@_ # For both matrices
                                  *.rotor($^a) # Split the matrix into N sized chunks
                                  .map({[Z] $_}) # Then zip each of those chunks together
                                  .flat # Flatten the resulting list
                                  .rotor($a²) # Then split into the NxN lists
                                  .sort # And sort them
                                  [eqv] # And then check if the lists are equivalent





                                  share|improve this answer











                                  $endgroup$
















                                    6












                                    6








                                    6





                                    $begingroup$


                                    Perl 6, 94 68 63 bytes





                                    {[eqv] map *.rotor($^a).map({[Z] $_}).flat.rotor($a²).sort,@_}


                                    Try it online!



                                    Anonymous code block that takes input as size, [matrix1, matrix2] and returns a boolean True/False. There might be a more efficient way of splitting the matrix into chunks than rotor.



                                    Explanation:



                                    {                                                            }  # Anonymous code block
                                    map ,@_ # For both matrices
                                    *.rotor($^a) # Split the matrix into N sized chunks
                                    .map({[Z] $_}) # Then zip each of those chunks together
                                    .flat # Flatten the resulting list
                                    .rotor($a²) # Then split into the NxN lists
                                    .sort # And sort them
                                    [eqv] # And then check if the lists are equivalent





                                    share|improve this answer











                                    $endgroup$




                                    Perl 6, 94 68 63 bytes





                                    {[eqv] map *.rotor($^a).map({[Z] $_}).flat.rotor($a²).sort,@_}


                                    Try it online!



                                    Anonymous code block that takes input as size, [matrix1, matrix2] and returns a boolean True/False. There might be a more efficient way of splitting the matrix into chunks than rotor.



                                    Explanation:



                                    {                                                            }  # Anonymous code block
                                    map ,@_ # For both matrices
                                    *.rotor($^a) # Split the matrix into N sized chunks
                                    .map({[Z] $_}) # Then zip each of those chunks together
                                    .flat # Flatten the resulting list
                                    .rotor($a²) # Then split into the NxN lists
                                    .sort # And sort them
                                    [eqv] # And then check if the lists are equivalent






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 14 at 9:55

























                                    answered Jan 14 at 9:18









                                    Jo KingJo King

                                    21.4k248110




                                    21.4k248110























                                        6












                                        $begingroup$


                                        05AB1E, 14 bytes



                                        εε²ô}ø˜²ô²ô{]Ë


                                        Try it online!






                                        share|improve this answer











                                        $endgroup$


















                                          6












                                          $begingroup$


                                          05AB1E, 14 bytes



                                          εε²ô}ø˜²ô²ô{]Ë


                                          Try it online!






                                          share|improve this answer











                                          $endgroup$
















                                            6












                                            6








                                            6





                                            $begingroup$


                                            05AB1E, 14 bytes



                                            εε²ô}ø˜²ô²ô{]Ë


                                            Try it online!






                                            share|improve this answer











                                            $endgroup$




                                            05AB1E, 14 bytes



                                            εε²ô}ø˜²ô²ô{]Ë


                                            Try it online!







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Jan 14 at 12:43

























                                            answered Jan 14 at 12:03









                                            EmignaEmigna

                                            45.8k432139




                                            45.8k432139























                                                4












                                                $begingroup$


                                                Java (JDK), 221 bytes





                                                (n,a,b)->{java.util.Arrays A=null;int l=a.length,x=l/n,i=0,j,z;var c=new String[x*x];A.fill(c,"");var d=c.clone();for(;i<l;i++)for(j=0;j<l;d[z]+=b[i][j++])c[z=i/n+j/n*x]+=a[i][j];A.sort(c);A.sort(d);return A.equals(c,d);}


                                                Try it online!



                                                Explanation



                                                The idea is to pick each small cell as a string, which is comparable, and then to sort those strings and compare them in order.



                                                (n,a,b)->{
                                                java.util.Arrays A=null; // Shortcut A for the several java.util.Arrays that'll come
                                                int l=a.length,x=l/n,i=0,j,z; // Variable declarations
                                                var c=new String[x*x]; // Declare the small squares list
                                                A.fill(c,""); // Fill the lists of small squares with the empty string.
                                                var d=c.clone(); // Make a copy of the list, for the second matrix
                                                for(;i<l;i++)
                                                for(j=0;j<l;d[z]+=b[i][j++]) // For each matrix cell
                                                c[z=i/n+j/n*x]+=a[i][j]; // Fill the small square with the value, string-wise
                                                A.sort(c);A.sort(d); // Sort both small squares list
                                                return A.equals(c,d); // Return true if they're equal, false otherwise.
                                                }


                                                Credits




                                                • -12 bytes thanks to Kevin Cruijssen!






                                                share|improve this answer











                                                $endgroup$













                                                • $begingroup$
                                                  Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:28










                                                • $begingroup$
                                                  And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:29










                                                • $begingroup$
                                                  PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:31










                                                • $begingroup$
                                                  Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:33










                                                • $begingroup$
                                                  The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:36


















                                                4












                                                $begingroup$


                                                Java (JDK), 221 bytes





                                                (n,a,b)->{java.util.Arrays A=null;int l=a.length,x=l/n,i=0,j,z;var c=new String[x*x];A.fill(c,"");var d=c.clone();for(;i<l;i++)for(j=0;j<l;d[z]+=b[i][j++])c[z=i/n+j/n*x]+=a[i][j];A.sort(c);A.sort(d);return A.equals(c,d);}


                                                Try it online!



                                                Explanation



                                                The idea is to pick each small cell as a string, which is comparable, and then to sort those strings and compare them in order.



                                                (n,a,b)->{
                                                java.util.Arrays A=null; // Shortcut A for the several java.util.Arrays that'll come
                                                int l=a.length,x=l/n,i=0,j,z; // Variable declarations
                                                var c=new String[x*x]; // Declare the small squares list
                                                A.fill(c,""); // Fill the lists of small squares with the empty string.
                                                var d=c.clone(); // Make a copy of the list, for the second matrix
                                                for(;i<l;i++)
                                                for(j=0;j<l;d[z]+=b[i][j++]) // For each matrix cell
                                                c[z=i/n+j/n*x]+=a[i][j]; // Fill the small square with the value, string-wise
                                                A.sort(c);A.sort(d); // Sort both small squares list
                                                return A.equals(c,d); // Return true if they're equal, false otherwise.
                                                }


                                                Credits




                                                • -12 bytes thanks to Kevin Cruijssen!






                                                share|improve this answer











                                                $endgroup$













                                                • $begingroup$
                                                  Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:28










                                                • $begingroup$
                                                  And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:29










                                                • $begingroup$
                                                  PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:31










                                                • $begingroup$
                                                  Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:33










                                                • $begingroup$
                                                  The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:36
















                                                4












                                                4








                                                4





                                                $begingroup$


                                                Java (JDK), 221 bytes





                                                (n,a,b)->{java.util.Arrays A=null;int l=a.length,x=l/n,i=0,j,z;var c=new String[x*x];A.fill(c,"");var d=c.clone();for(;i<l;i++)for(j=0;j<l;d[z]+=b[i][j++])c[z=i/n+j/n*x]+=a[i][j];A.sort(c);A.sort(d);return A.equals(c,d);}


                                                Try it online!



                                                Explanation



                                                The idea is to pick each small cell as a string, which is comparable, and then to sort those strings and compare them in order.



                                                (n,a,b)->{
                                                java.util.Arrays A=null; // Shortcut A for the several java.util.Arrays that'll come
                                                int l=a.length,x=l/n,i=0,j,z; // Variable declarations
                                                var c=new String[x*x]; // Declare the small squares list
                                                A.fill(c,""); // Fill the lists of small squares with the empty string.
                                                var d=c.clone(); // Make a copy of the list, for the second matrix
                                                for(;i<l;i++)
                                                for(j=0;j<l;d[z]+=b[i][j++]) // For each matrix cell
                                                c[z=i/n+j/n*x]+=a[i][j]; // Fill the small square with the value, string-wise
                                                A.sort(c);A.sort(d); // Sort both small squares list
                                                return A.equals(c,d); // Return true if they're equal, false otherwise.
                                                }


                                                Credits




                                                • -12 bytes thanks to Kevin Cruijssen!






                                                share|improve this answer











                                                $endgroup$




                                                Java (JDK), 221 bytes





                                                (n,a,b)->{java.util.Arrays A=null;int l=a.length,x=l/n,i=0,j,z;var c=new String[x*x];A.fill(c,"");var d=c.clone();for(;i<l;i++)for(j=0;j<l;d[z]+=b[i][j++])c[z=i/n+j/n*x]+=a[i][j];A.sort(c);A.sort(d);return A.equals(c,d);}


                                                Try it online!



                                                Explanation



                                                The idea is to pick each small cell as a string, which is comparable, and then to sort those strings and compare them in order.



                                                (n,a,b)->{
                                                java.util.Arrays A=null; // Shortcut A for the several java.util.Arrays that'll come
                                                int l=a.length,x=l/n,i=0,j,z; // Variable declarations
                                                var c=new String[x*x]; // Declare the small squares list
                                                A.fill(c,""); // Fill the lists of small squares with the empty string.
                                                var d=c.clone(); // Make a copy of the list, for the second matrix
                                                for(;i<l;i++)
                                                for(j=0;j<l;d[z]+=b[i][j++]) // For each matrix cell
                                                c[z=i/n+j/n*x]+=a[i][j]; // Fill the small square with the value, string-wise
                                                A.sort(c);A.sort(d); // Sort both small squares list
                                                return A.equals(c,d); // Return true if they're equal, false otherwise.
                                                }


                                                Credits




                                                • -12 bytes thanks to Kevin Cruijssen!







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Jan 14 at 14:58

























                                                answered Jan 14 at 13:25









                                                Olivier GrégoireOlivier Grégoire

                                                8,92511843




                                                8,92511843












                                                • $begingroup$
                                                  Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:28










                                                • $begingroup$
                                                  And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:29










                                                • $begingroup$
                                                  PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:31










                                                • $begingroup$
                                                  Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:33










                                                • $begingroup$
                                                  The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:36




















                                                • $begingroup$
                                                  Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:28










                                                • $begingroup$
                                                  And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:29










                                                • $begingroup$
                                                  PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                  $endgroup$
                                                  – Kevin Cruijssen
                                                  Jan 14 at 13:31










                                                • $begingroup$
                                                  Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:33










                                                • $begingroup$
                                                  The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                  $endgroup$
                                                  – Olivier Grégoire
                                                  Jan 14 at 13:36


















                                                $begingroup$
                                                Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:28




                                                $begingroup$
                                                Did you forgot to golf for(j=0;j<l;){c[z=i/n+j/n*x]+=a[i][j];d[z]+=b[i][j++];}?.. You can remove the brackets by putting everything inside the loop. Also, the i=0 in the loop can be removed, because your i is already 0 at declaration.
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:28












                                                $begingroup$
                                                And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:29




                                                $begingroup$
                                                And one thing to actually golf: var d=new String[x*x]; can be var d=c.clone(); instead. 234 bytes
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:29












                                                $begingroup$
                                                PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:31




                                                $begingroup$
                                                PS: Why does your TIO contains String which you convert to 2D-integer arrays? I've added a paste-bin with the test cases at the bottom, for which you can replace the [ and ] with { and } and add a leading new int, and it would have been enough. ;)
                                                $endgroup$
                                                – Kevin Cruijssen
                                                Jan 14 at 13:31












                                                $begingroup$
                                                Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                $endgroup$
                                                – Olivier Grégoire
                                                Jan 14 at 13:33




                                                $begingroup$
                                                Dammit, I hadn't seen the paste-bin :( And for the rest, I'm still golfing. I did a rough pass, but thank you :-)
                                                $endgroup$
                                                – Olivier Grégoire
                                                Jan 14 at 13:33












                                                $begingroup$
                                                The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                $endgroup$
                                                – Olivier Grégoire
                                                Jan 14 at 13:36






                                                $begingroup$
                                                The i=0 was a remnant when I filled the arrays by myself rather than using Arrays.fill. Thanks :-) And for the clone I thought about using it, but I still thought it'd have returned anObject and not the actual type. I must be several versions late on that point ;)
                                                $endgroup$
                                                – Olivier Grégoire
                                                Jan 14 at 13:36













                                                4












                                                $begingroup$


                                                Jelly,  10  9 bytes



                                                ż⁹/ẎsṢʋ€E


                                                Try it online! (or with pre-processing for easier copy & paste from the test cases)



                                                A dyadic Link accepting a list of the two matrices (as lists of lists) on the left and the integer on the right which yields 1 or 0 for truthy or falsey respectively.



                                                How?



                                                ż⁹/ẎsṢʋ€E - Link: [M1, M2]; N
                                                € - for each of [M1, M2]:
                                                ʋ - last four links as a dyad (i.e. f(M, N)):
                                                ⁹ - (chain's right argument, N)
                                                ⁹/ - N-wise-reduce with:
                                                ż - zip together
                                                Ẏ - tighten
                                                s - split into chunks of length N
                                                Ṣ - sort
                                                E - equal?





                                                share|improve this answer











                                                $endgroup$


















                                                  4












                                                  $begingroup$


                                                  Jelly,  10  9 bytes



                                                  ż⁹/ẎsṢʋ€E


                                                  Try it online! (or with pre-processing for easier copy & paste from the test cases)



                                                  A dyadic Link accepting a list of the two matrices (as lists of lists) on the left and the integer on the right which yields 1 or 0 for truthy or falsey respectively.



                                                  How?



                                                  ż⁹/ẎsṢʋ€E - Link: [M1, M2]; N
                                                  € - for each of [M1, M2]:
                                                  ʋ - last four links as a dyad (i.e. f(M, N)):
                                                  ⁹ - (chain's right argument, N)
                                                  ⁹/ - N-wise-reduce with:
                                                  ż - zip together
                                                  Ẏ - tighten
                                                  s - split into chunks of length N
                                                  Ṣ - sort
                                                  E - equal?





                                                  share|improve this answer











                                                  $endgroup$
















                                                    4












                                                    4








                                                    4





                                                    $begingroup$


                                                    Jelly,  10  9 bytes



                                                    ż⁹/ẎsṢʋ€E


                                                    Try it online! (or with pre-processing for easier copy & paste from the test cases)



                                                    A dyadic Link accepting a list of the two matrices (as lists of lists) on the left and the integer on the right which yields 1 or 0 for truthy or falsey respectively.



                                                    How?



                                                    ż⁹/ẎsṢʋ€E - Link: [M1, M2]; N
                                                    € - for each of [M1, M2]:
                                                    ʋ - last four links as a dyad (i.e. f(M, N)):
                                                    ⁹ - (chain's right argument, N)
                                                    ⁹/ - N-wise-reduce with:
                                                    ż - zip together
                                                    Ẏ - tighten
                                                    s - split into chunks of length N
                                                    Ṣ - sort
                                                    E - equal?





                                                    share|improve this answer











                                                    $endgroup$




                                                    Jelly,  10  9 bytes



                                                    ż⁹/ẎsṢʋ€E


                                                    Try it online! (or with pre-processing for easier copy & paste from the test cases)



                                                    A dyadic Link accepting a list of the two matrices (as lists of lists) on the left and the integer on the right which yields 1 or 0 for truthy or falsey respectively.



                                                    How?



                                                    ż⁹/ẎsṢʋ€E - Link: [M1, M2]; N
                                                    € - for each of [M1, M2]:
                                                    ʋ - last four links as a dyad (i.e. f(M, N)):
                                                    ⁹ - (chain's right argument, N)
                                                    ⁹/ - N-wise-reduce with:
                                                    ż - zip together
                                                    Ẏ - tighten
                                                    s - split into chunks of length N
                                                    Ṣ - sort
                                                    E - equal?






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jan 14 at 21:21

























                                                    answered Jan 14 at 20:42









                                                    Jonathan AllanJonathan Allan

                                                    51.3k535166




                                                    51.3k535166























                                                        4












                                                        $begingroup$


                                                        Japt, 18 bytes



                                                        ®mòV yòV rc n qÃr¥


                                                        Try it online!



                                                        Explanation:



                                                        ®              Ã      #Apply this to each of the input matrices:
                                                        mòV # Split each row into groups of n
                                                        yòV # Split each column into groups of n
                                                        rc # Flatten into a list of nxn submatrices
                                                        n # Sort that list
                                                        q # Turn it into a string
                                                        r¥ #Return true if both matrices had identical results


                                                        The "Turn it into a string" step is necessary because Japt doesn't compare arrays by value and the builtin to work around that doesn't work for multidimensional arrays.






                                                        share|improve this answer











                                                        $endgroup$









                                                        • 2




                                                          $begingroup$
                                                          I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 14 at 21:30










                                                        • $begingroup$
                                                          By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 15 at 12:57
















                                                        4












                                                        $begingroup$


                                                        Japt, 18 bytes



                                                        ®mòV yòV rc n qÃr¥


                                                        Try it online!



                                                        Explanation:



                                                        ®              Ã      #Apply this to each of the input matrices:
                                                        mòV # Split each row into groups of n
                                                        yòV # Split each column into groups of n
                                                        rc # Flatten into a list of nxn submatrices
                                                        n # Sort that list
                                                        q # Turn it into a string
                                                        r¥ #Return true if both matrices had identical results


                                                        The "Turn it into a string" step is necessary because Japt doesn't compare arrays by value and the builtin to work around that doesn't work for multidimensional arrays.






                                                        share|improve this answer











                                                        $endgroup$









                                                        • 2




                                                          $begingroup$
                                                          I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 14 at 21:30










                                                        • $begingroup$
                                                          By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 15 at 12:57














                                                        4












                                                        4








                                                        4





                                                        $begingroup$


                                                        Japt, 18 bytes



                                                        ®mòV yòV rc n qÃr¥


                                                        Try it online!



                                                        Explanation:



                                                        ®              Ã      #Apply this to each of the input matrices:
                                                        mòV # Split each row into groups of n
                                                        yòV # Split each column into groups of n
                                                        rc # Flatten into a list of nxn submatrices
                                                        n # Sort that list
                                                        q # Turn it into a string
                                                        r¥ #Return true if both matrices had identical results


                                                        The "Turn it into a string" step is necessary because Japt doesn't compare arrays by value and the builtin to work around that doesn't work for multidimensional arrays.






                                                        share|improve this answer











                                                        $endgroup$




                                                        Japt, 18 bytes



                                                        ®mòV yòV rc n qÃr¥


                                                        Try it online!



                                                        Explanation:



                                                        ®              Ã      #Apply this to each of the input matrices:
                                                        mòV # Split each row into groups of n
                                                        yòV # Split each column into groups of n
                                                        rc # Flatten into a list of nxn submatrices
                                                        n # Sort that list
                                                        q # Turn it into a string
                                                        r¥ #Return true if both matrices had identical results


                                                        The "Turn it into a string" step is necessary because Japt doesn't compare arrays by value and the builtin to work around that doesn't work for multidimensional arrays.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Jan 14 at 21:36

























                                                        answered Jan 14 at 17:10









                                                        Kamil DrakariKamil Drakari

                                                        3,131416




                                                        3,131416








                                                        • 2




                                                          $begingroup$
                                                          I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 14 at 21:30










                                                        • $begingroup$
                                                          By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 15 at 12:57














                                                        • 2




                                                          $begingroup$
                                                          I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 14 at 21:30










                                                        • $begingroup$
                                                          By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                          $endgroup$
                                                          – Shaggy
                                                          Jan 15 at 12:57








                                                        2




                                                        2




                                                        $begingroup$
                                                        I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                        $endgroup$
                                                        – Shaggy
                                                        Jan 14 at 21:30




                                                        $begingroup$
                                                        I'll see if I can make some time between meetings tomorrow to try and get A.e() working for multi-dimensional arrays; always meant to come back to it. In the meantime ÕmòV -> yòV will save you a byte.
                                                        $endgroup$
                                                        – Shaggy
                                                        Jan 14 at 21:30












                                                        $begingroup$
                                                        By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                        $endgroup$
                                                        – Shaggy
                                                        Jan 15 at 12:57




                                                        $begingroup$
                                                        By the way, the limitation on comparing arrays for equality is JavaScript's rather than being particular to Japt ;)
                                                        $endgroup$
                                                        – Shaggy
                                                        Jan 15 at 12:57











                                                        4












                                                        $begingroup$

                                                        TSQL, 164 bytes



                                                        Populating a table variable in order to have input, this creating input and inserting data has not been included in the byte count. Only the actual query to extract the data.



                                                        Golfed(not including test table - it can be found in the ungolfed version):



                                                        SELECT iif(exists(SELECT*FROM(SELECT string_agg(v,'')within
                                                        group(order by x,y)s,m FROM @t GROUP BY x/@,y/@,m)x
                                                        GROUP BY s HAVING max(m)=min(m)or sum(m-.5)<>0),0,1)


                                                        Ungolfed:



                                                        -- test data
                                                        DECLARE @ INT = 2
                                                        -- x = x-position of the input
                                                        -- y = y-position of the input
                                                        -- v = value
                                                        -- m = matrix(0 or 1)
                                                        DECLARE @t table(x int, y int, v int, m int)
                                                        --insert first matrix values
                                                        INSERT @t values
                                                        (0,0,1,0),(0,1,2,0),(0,2,1,0),(0,3,2,0),
                                                        (1,0,3,0),(1,1,4,0),(1,2,3,0),(1,3,4,0),
                                                        (2,0,8,0),(2,1,3,0),(2,2,9,0),(2,3,5,0),
                                                        (3,0,6,0),(3,1,1,0),(3,2,7,0),(3,3,7,0)
                                                        INSERT @t values
                                                        (0,0,9,1),(0,1,5,1),(0,2,1,1),(0,3,2,1),
                                                        (1,0,7,1),(1,1,7,1),(1,2,3,1),(1,3,4,1),
                                                        (2,0,1,1),(2,1,2,1),(2,2,8,1),(2,3,3,1),
                                                        (3,0,3,1),(3,1,4,1),(3,2,6,1),(3,3,1,1)

                                                        -- query
                                                        SELECT iif(exists
                                                        (
                                                        SELECT *
                                                        FROM
                                                        (
                                                        SELECT string_agg(v,'')within group(order by x,y)s,m
                                                        FROM @t
                                                        GROUP BY x/@,y/@,m
                                                        ) x
                                                        GROUP BY s
                                                        HAVING max(m)=min(m)or sum(m-.5)<>0
                                                        ),0,1)


                                                        Try it out






                                                        share|improve this answer











                                                        $endgroup$


















                                                          4












                                                          $begingroup$

                                                          TSQL, 164 bytes



                                                          Populating a table variable in order to have input, this creating input and inserting data has not been included in the byte count. Only the actual query to extract the data.



                                                          Golfed(not including test table - it can be found in the ungolfed version):



                                                          SELECT iif(exists(SELECT*FROM(SELECT string_agg(v,'')within
                                                          group(order by x,y)s,m FROM @t GROUP BY x/@,y/@,m)x
                                                          GROUP BY s HAVING max(m)=min(m)or sum(m-.5)<>0),0,1)


                                                          Ungolfed:



                                                          -- test data
                                                          DECLARE @ INT = 2
                                                          -- x = x-position of the input
                                                          -- y = y-position of the input
                                                          -- v = value
                                                          -- m = matrix(0 or 1)
                                                          DECLARE @t table(x int, y int, v int, m int)
                                                          --insert first matrix values
                                                          INSERT @t values
                                                          (0,0,1,0),(0,1,2,0),(0,2,1,0),(0,3,2,0),
                                                          (1,0,3,0),(1,1,4,0),(1,2,3,0),(1,3,4,0),
                                                          (2,0,8,0),(2,1,3,0),(2,2,9,0),(2,3,5,0),
                                                          (3,0,6,0),(3,1,1,0),(3,2,7,0),(3,3,7,0)
                                                          INSERT @t values
                                                          (0,0,9,1),(0,1,5,1),(0,2,1,1),(0,3,2,1),
                                                          (1,0,7,1),(1,1,7,1),(1,2,3,1),(1,3,4,1),
                                                          (2,0,1,1),(2,1,2,1),(2,2,8,1),(2,3,3,1),
                                                          (3,0,3,1),(3,1,4,1),(3,2,6,1),(3,3,1,1)

                                                          -- query
                                                          SELECT iif(exists
                                                          (
                                                          SELECT *
                                                          FROM
                                                          (
                                                          SELECT string_agg(v,'')within group(order by x,y)s,m
                                                          FROM @t
                                                          GROUP BY x/@,y/@,m
                                                          ) x
                                                          GROUP BY s
                                                          HAVING max(m)=min(m)or sum(m-.5)<>0
                                                          ),0,1)


                                                          Try it out






                                                          share|improve this answer











                                                          $endgroup$
















                                                            4












                                                            4








                                                            4





                                                            $begingroup$

                                                            TSQL, 164 bytes



                                                            Populating a table variable in order to have input, this creating input and inserting data has not been included in the byte count. Only the actual query to extract the data.



                                                            Golfed(not including test table - it can be found in the ungolfed version):



                                                            SELECT iif(exists(SELECT*FROM(SELECT string_agg(v,'')within
                                                            group(order by x,y)s,m FROM @t GROUP BY x/@,y/@,m)x
                                                            GROUP BY s HAVING max(m)=min(m)or sum(m-.5)<>0),0,1)


                                                            Ungolfed:



                                                            -- test data
                                                            DECLARE @ INT = 2
                                                            -- x = x-position of the input
                                                            -- y = y-position of the input
                                                            -- v = value
                                                            -- m = matrix(0 or 1)
                                                            DECLARE @t table(x int, y int, v int, m int)
                                                            --insert first matrix values
                                                            INSERT @t values
                                                            (0,0,1,0),(0,1,2,0),(0,2,1,0),(0,3,2,0),
                                                            (1,0,3,0),(1,1,4,0),(1,2,3,0),(1,3,4,0),
                                                            (2,0,8,0),(2,1,3,0),(2,2,9,0),(2,3,5,0),
                                                            (3,0,6,0),(3,1,1,0),(3,2,7,0),(3,3,7,0)
                                                            INSERT @t values
                                                            (0,0,9,1),(0,1,5,1),(0,2,1,1),(0,3,2,1),
                                                            (1,0,7,1),(1,1,7,1),(1,2,3,1),(1,3,4,1),
                                                            (2,0,1,1),(2,1,2,1),(2,2,8,1),(2,3,3,1),
                                                            (3,0,3,1),(3,1,4,1),(3,2,6,1),(3,3,1,1)

                                                            -- query
                                                            SELECT iif(exists
                                                            (
                                                            SELECT *
                                                            FROM
                                                            (
                                                            SELECT string_agg(v,'')within group(order by x,y)s,m
                                                            FROM @t
                                                            GROUP BY x/@,y/@,m
                                                            ) x
                                                            GROUP BY s
                                                            HAVING max(m)=min(m)or sum(m-.5)<>0
                                                            ),0,1)


                                                            Try it out






                                                            share|improve this answer











                                                            $endgroup$



                                                            TSQL, 164 bytes



                                                            Populating a table variable in order to have input, this creating input and inserting data has not been included in the byte count. Only the actual query to extract the data.



                                                            Golfed(not including test table - it can be found in the ungolfed version):



                                                            SELECT iif(exists(SELECT*FROM(SELECT string_agg(v,'')within
                                                            group(order by x,y)s,m FROM @t GROUP BY x/@,y/@,m)x
                                                            GROUP BY s HAVING max(m)=min(m)or sum(m-.5)<>0),0,1)


                                                            Ungolfed:



                                                            -- test data
                                                            DECLARE @ INT = 2
                                                            -- x = x-position of the input
                                                            -- y = y-position of the input
                                                            -- v = value
                                                            -- m = matrix(0 or 1)
                                                            DECLARE @t table(x int, y int, v int, m int)
                                                            --insert first matrix values
                                                            INSERT @t values
                                                            (0,0,1,0),(0,1,2,0),(0,2,1,0),(0,3,2,0),
                                                            (1,0,3,0),(1,1,4,0),(1,2,3,0),(1,3,4,0),
                                                            (2,0,8,0),(2,1,3,0),(2,2,9,0),(2,3,5,0),
                                                            (3,0,6,0),(3,1,1,0),(3,2,7,0),(3,3,7,0)
                                                            INSERT @t values
                                                            (0,0,9,1),(0,1,5,1),(0,2,1,1),(0,3,2,1),
                                                            (1,0,7,1),(1,1,7,1),(1,2,3,1),(1,3,4,1),
                                                            (2,0,1,1),(2,1,2,1),(2,2,8,1),(2,3,3,1),
                                                            (3,0,3,1),(3,1,4,1),(3,2,6,1),(3,3,1,1)

                                                            -- query
                                                            SELECT iif(exists
                                                            (
                                                            SELECT *
                                                            FROM
                                                            (
                                                            SELECT string_agg(v,'')within group(order by x,y)s,m
                                                            FROM @t
                                                            GROUP BY x/@,y/@,m
                                                            ) x
                                                            GROUP BY s
                                                            HAVING max(m)=min(m)or sum(m-.5)<>0
                                                            ),0,1)


                                                            Try it out







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Jan 15 at 8:52

























                                                            answered Jan 14 at 12:50









                                                            t-clausen.dkt-clausen.dk

                                                            1,834314




                                                            1,834314























                                                                4












                                                                $begingroup$

                                                                JavaScript (ES6), 88 bytes





                                                                (n,a,b)=>(g=a=>a.map((r,y)=>r.map((v,x)=>o[y/n<<7|x/n]+=[v]),o=)&&o.sort()+o)(a)==g(b)


                                                                Try it online!



                                                                How?



                                                                This code is:




                                                                • extracting all sub-matrices in each input matrix as a concatenation of cells

                                                                • sorting the sub-matrices in lexicographical order

                                                                • testing whether the result is the same for both input matrices


                                                                It is taking advantage of the limits described in the challenge:




                                                                • A matrix consists of single digits, so we can just concatenate all cells of a sub-matrix without any separator and still get a unique representation of it (e.g. [[1,2],[3,4]] can be stored as "1234").



                                                                • The width of the input matrices is less than or equal to $100$. To convert the coordinates $(x,y)$ in an input matrix into a unique slot index $I$ in our storage area, we can do:



                                                                  $$I=leftlfloorfrac{y}{n}rightrfloortimes128+leftlfloorfrac{x}{n}rightrfloor$$



                                                                  or as JS code: y / n << 7 | x << n




                                                                Commented



                                                                (n, a, b) =>           // n, a, b = input variables (integer, matrix 1, matrix 2)
                                                                (g = a => // g = helper function taking one of the two matrices
                                                                a.map((r, y) => // for each row r at position y in a:
                                                                r.map((v, x) => // for each value v at position x in r:
                                                                o[ // update o:
                                                                y / n << 7 | // the position of the slot is computed by taking advantage
                                                                x / n // of the limit on the matrix width (see above)
                                                                ] += [v] // coerce v to a string and append it to o[slot]
                                                                // all slots are initially undefined, so all resulting strings
                                                                // are going to start with "undefined", which is harmless
                                                                ), // end of inner map()
                                                                o = // start with o = empty array
                                                                ) && // end of outer map()
                                                                o.sort() + o // sort o and coerce it to a string by concatenating it with itself
                                                                )(a) == g(b) // test whether g(a) is equal to g(b)





                                                                share|improve this answer











                                                                $endgroup$


















                                                                  4












                                                                  $begingroup$

                                                                  JavaScript (ES6), 88 bytes





                                                                  (n,a,b)=>(g=a=>a.map((r,y)=>r.map((v,x)=>o[y/n<<7|x/n]+=[v]),o=)&&o.sort()+o)(a)==g(b)


                                                                  Try it online!



                                                                  How?



                                                                  This code is:




                                                                  • extracting all sub-matrices in each input matrix as a concatenation of cells

                                                                  • sorting the sub-matrices in lexicographical order

                                                                  • testing whether the result is the same for both input matrices


                                                                  It is taking advantage of the limits described in the challenge:




                                                                  • A matrix consists of single digits, so we can just concatenate all cells of a sub-matrix without any separator and still get a unique representation of it (e.g. [[1,2],[3,4]] can be stored as "1234").



                                                                  • The width of the input matrices is less than or equal to $100$. To convert the coordinates $(x,y)$ in an input matrix into a unique slot index $I$ in our storage area, we can do:



                                                                    $$I=leftlfloorfrac{y}{n}rightrfloortimes128+leftlfloorfrac{x}{n}rightrfloor$$



                                                                    or as JS code: y / n << 7 | x << n




                                                                  Commented



                                                                  (n, a, b) =>           // n, a, b = input variables (integer, matrix 1, matrix 2)
                                                                  (g = a => // g = helper function taking one of the two matrices
                                                                  a.map((r, y) => // for each row r at position y in a:
                                                                  r.map((v, x) => // for each value v at position x in r:
                                                                  o[ // update o:
                                                                  y / n << 7 | // the position of the slot is computed by taking advantage
                                                                  x / n // of the limit on the matrix width (see above)
                                                                  ] += [v] // coerce v to a string and append it to o[slot]
                                                                  // all slots are initially undefined, so all resulting strings
                                                                  // are going to start with "undefined", which is harmless
                                                                  ), // end of inner map()
                                                                  o = // start with o = empty array
                                                                  ) && // end of outer map()
                                                                  o.sort() + o // sort o and coerce it to a string by concatenating it with itself
                                                                  )(a) == g(b) // test whether g(a) is equal to g(b)





                                                                  share|improve this answer











                                                                  $endgroup$
















                                                                    4












                                                                    4








                                                                    4





                                                                    $begingroup$

                                                                    JavaScript (ES6), 88 bytes





                                                                    (n,a,b)=>(g=a=>a.map((r,y)=>r.map((v,x)=>o[y/n<<7|x/n]+=[v]),o=)&&o.sort()+o)(a)==g(b)


                                                                    Try it online!



                                                                    How?



                                                                    This code is:




                                                                    • extracting all sub-matrices in each input matrix as a concatenation of cells

                                                                    • sorting the sub-matrices in lexicographical order

                                                                    • testing whether the result is the same for both input matrices


                                                                    It is taking advantage of the limits described in the challenge:




                                                                    • A matrix consists of single digits, so we can just concatenate all cells of a sub-matrix without any separator and still get a unique representation of it (e.g. [[1,2],[3,4]] can be stored as "1234").



                                                                    • The width of the input matrices is less than or equal to $100$. To convert the coordinates $(x,y)$ in an input matrix into a unique slot index $I$ in our storage area, we can do:



                                                                      $$I=leftlfloorfrac{y}{n}rightrfloortimes128+leftlfloorfrac{x}{n}rightrfloor$$



                                                                      or as JS code: y / n << 7 | x << n




                                                                    Commented



                                                                    (n, a, b) =>           // n, a, b = input variables (integer, matrix 1, matrix 2)
                                                                    (g = a => // g = helper function taking one of the two matrices
                                                                    a.map((r, y) => // for each row r at position y in a:
                                                                    r.map((v, x) => // for each value v at position x in r:
                                                                    o[ // update o:
                                                                    y / n << 7 | // the position of the slot is computed by taking advantage
                                                                    x / n // of the limit on the matrix width (see above)
                                                                    ] += [v] // coerce v to a string and append it to o[slot]
                                                                    // all slots are initially undefined, so all resulting strings
                                                                    // are going to start with "undefined", which is harmless
                                                                    ), // end of inner map()
                                                                    o = // start with o = empty array
                                                                    ) && // end of outer map()
                                                                    o.sort() + o // sort o and coerce it to a string by concatenating it with itself
                                                                    )(a) == g(b) // test whether g(a) is equal to g(b)





                                                                    share|improve this answer











                                                                    $endgroup$



                                                                    JavaScript (ES6), 88 bytes





                                                                    (n,a,b)=>(g=a=>a.map((r,y)=>r.map((v,x)=>o[y/n<<7|x/n]+=[v]),o=)&&o.sort()+o)(a)==g(b)


                                                                    Try it online!



                                                                    How?



                                                                    This code is:




                                                                    • extracting all sub-matrices in each input matrix as a concatenation of cells

                                                                    • sorting the sub-matrices in lexicographical order

                                                                    • testing whether the result is the same for both input matrices


                                                                    It is taking advantage of the limits described in the challenge:




                                                                    • A matrix consists of single digits, so we can just concatenate all cells of a sub-matrix without any separator and still get a unique representation of it (e.g. [[1,2],[3,4]] can be stored as "1234").



                                                                    • The width of the input matrices is less than or equal to $100$. To convert the coordinates $(x,y)$ in an input matrix into a unique slot index $I$ in our storage area, we can do:



                                                                      $$I=leftlfloorfrac{y}{n}rightrfloortimes128+leftlfloorfrac{x}{n}rightrfloor$$



                                                                      or as JS code: y / n << 7 | x << n




                                                                    Commented



                                                                    (n, a, b) =>           // n, a, b = input variables (integer, matrix 1, matrix 2)
                                                                    (g = a => // g = helper function taking one of the two matrices
                                                                    a.map((r, y) => // for each row r at position y in a:
                                                                    r.map((v, x) => // for each value v at position x in r:
                                                                    o[ // update o:
                                                                    y / n << 7 | // the position of the slot is computed by taking advantage
                                                                    x / n // of the limit on the matrix width (see above)
                                                                    ] += [v] // coerce v to a string and append it to o[slot]
                                                                    // all slots are initially undefined, so all resulting strings
                                                                    // are going to start with "undefined", which is harmless
                                                                    ), // end of inner map()
                                                                    o = // start with o = empty array
                                                                    ) && // end of outer map()
                                                                    o.sort() + o // sort o and coerce it to a string by concatenating it with itself
                                                                    )(a) == g(b) // test whether g(a) is equal to g(b)






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited Jan 15 at 11:59

























                                                                    answered Jan 14 at 11:01









                                                                    ArnauldArnauld

                                                                    73.7k689309




                                                                    73.7k689309























                                                                        3












                                                                        $begingroup$


                                                                        Charcoal, 54 49 bytes



                                                                        1FθF⪪ιηF÷L§κ⁰η⊞υEκ§⪪μηλW∧υ⊟υ¿№✂υ⁰⊘⊕Lυ¹ι≔Φυ⁻⌕υιλυ⎚


                                                                        Try it online! Link is to verbose version of code. Takes input as an array of equal-sized two-dimensional arrays. Outputs 1 on success, nothing on failure. Explanation:



                                                                        1


                                                                        Assume success.



                                                                        Fθ


                                                                        Loop over the arrays.



                                                                        F⪪ιη


                                                                        Divide the array into n-sized row chunks.



                                                                        F÷L§κ⁰η


                                                                        Loop over each column chunk.



                                                                        ⊞υEκ§⪪μηλ


                                                                        Extract the column chunk for each row of the row chunk and save the resulting submatrix in a list.



                                                                        W∧υ⊟υ


                                                                        While the list is nonempty, remove the last chunk of the list, which under normal circumstances comes from the second array.



                                                                        ¿№✂υ⁰⊘⊕Lυ¹ι


                                                                        Count the number of occurrences of that chunk in the first half of the list, which under normal circumstances contains the remaining chunks from the first array.



                                                                        ≔Φυ⁻⌕υιλυ


                                                                        If nonzero then remove the first occurrence of that chunk from the list.






                                                                        If zero then clear the output, making it falsy.






                                                                        share|improve this answer











                                                                        $endgroup$


















                                                                          3












                                                                          $begingroup$


                                                                          Charcoal, 54 49 bytes



                                                                          1FθF⪪ιηF÷L§κ⁰η⊞υEκ§⪪μηλW∧υ⊟υ¿№✂υ⁰⊘⊕Lυ¹ι≔Φυ⁻⌕υιλυ⎚


                                                                          Try it online! Link is to verbose version of code. Takes input as an array of equal-sized two-dimensional arrays. Outputs 1 on success, nothing on failure. Explanation:



                                                                          1


                                                                          Assume success.



                                                                          Fθ


                                                                          Loop over the arrays.



                                                                          F⪪ιη


                                                                          Divide the array into n-sized row chunks.



                                                                          F÷L§κ⁰η


                                                                          Loop over each column chunk.



                                                                          ⊞υEκ§⪪μηλ


                                                                          Extract the column chunk for each row of the row chunk and save the resulting submatrix in a list.



                                                                          W∧υ⊟υ


                                                                          While the list is nonempty, remove the last chunk of the list, which under normal circumstances comes from the second array.



                                                                          ¿№✂υ⁰⊘⊕Lυ¹ι


                                                                          Count the number of occurrences of that chunk in the first half of the list, which under normal circumstances contains the remaining chunks from the first array.



                                                                          ≔Φυ⁻⌕υιλυ


                                                                          If nonzero then remove the first occurrence of that chunk from the list.






                                                                          If zero then clear the output, making it falsy.






                                                                          share|improve this answer











                                                                          $endgroup$
















                                                                            3












                                                                            3








                                                                            3





                                                                            $begingroup$


                                                                            Charcoal, 54 49 bytes



                                                                            1FθF⪪ιηF÷L§κ⁰η⊞υEκ§⪪μηλW∧υ⊟υ¿№✂υ⁰⊘⊕Lυ¹ι≔Φυ⁻⌕υιλυ⎚


                                                                            Try it online! Link is to verbose version of code. Takes input as an array of equal-sized two-dimensional arrays. Outputs 1 on success, nothing on failure. Explanation:



                                                                            1


                                                                            Assume success.



                                                                            Fθ


                                                                            Loop over the arrays.



                                                                            F⪪ιη


                                                                            Divide the array into n-sized row chunks.



                                                                            F÷L§κ⁰η


                                                                            Loop over each column chunk.



                                                                            ⊞υEκ§⪪μηλ


                                                                            Extract the column chunk for each row of the row chunk and save the resulting submatrix in a list.



                                                                            W∧υ⊟υ


                                                                            While the list is nonempty, remove the last chunk of the list, which under normal circumstances comes from the second array.



                                                                            ¿№✂υ⁰⊘⊕Lυ¹ι


                                                                            Count the number of occurrences of that chunk in the first half of the list, which under normal circumstances contains the remaining chunks from the first array.



                                                                            ≔Φυ⁻⌕υιλυ


                                                                            If nonzero then remove the first occurrence of that chunk from the list.






                                                                            If zero then clear the output, making it falsy.






                                                                            share|improve this answer











                                                                            $endgroup$




                                                                            Charcoal, 54 49 bytes



                                                                            1FθF⪪ιηF÷L§κ⁰η⊞υEκ§⪪μηλW∧υ⊟υ¿№✂υ⁰⊘⊕Lυ¹ι≔Φυ⁻⌕υιλυ⎚


                                                                            Try it online! Link is to verbose version of code. Takes input as an array of equal-sized two-dimensional arrays. Outputs 1 on success, nothing on failure. Explanation:



                                                                            1


                                                                            Assume success.



                                                                            Fθ


                                                                            Loop over the arrays.



                                                                            F⪪ιη


                                                                            Divide the array into n-sized row chunks.



                                                                            F÷L§κ⁰η


                                                                            Loop over each column chunk.



                                                                            ⊞υEκ§⪪μηλ


                                                                            Extract the column chunk for each row of the row chunk and save the resulting submatrix in a list.



                                                                            W∧υ⊟υ


                                                                            While the list is nonempty, remove the last chunk of the list, which under normal circumstances comes from the second array.



                                                                            ¿№✂υ⁰⊘⊕Lυ¹ι


                                                                            Count the number of occurrences of that chunk in the first half of the list, which under normal circumstances contains the remaining chunks from the first array.



                                                                            ≔Φυ⁻⌕υιλυ


                                                                            If nonzero then remove the first occurrence of that chunk from the list.






                                                                            If zero then clear the output, making it falsy.







                                                                            share|improve this answer














                                                                            share|improve this answer



                                                                            share|improve this answer








                                                                            edited Jan 14 at 10:29

























                                                                            answered Jan 14 at 10:13









                                                                            NeilNeil

                                                                            79.9k744178




                                                                            79.9k744178























                                                                                2












                                                                                $begingroup$


                                                                                J, 55 bytes



                                                                                [:-:/[([:/:~([*-@[)],@])"3(((;])@(#@]$1{.~[),;.1])&>])


                                                                                Try it online!



                                                                                A horrible solution, just made it work - I have no power to golf it...






                                                                                share|improve this answer









                                                                                $endgroup$


















                                                                                  2












                                                                                  $begingroup$


                                                                                  J, 55 bytes



                                                                                  [:-:/[([:/:~([*-@[)],@])"3(((;])@(#@]$1{.~[),;.1])&>])


                                                                                  Try it online!



                                                                                  A horrible solution, just made it work - I have no power to golf it...






                                                                                  share|improve this answer









                                                                                  $endgroup$
















                                                                                    2












                                                                                    2








                                                                                    2





                                                                                    $begingroup$


                                                                                    J, 55 bytes



                                                                                    [:-:/[([:/:~([*-@[)],@])"3(((;])@(#@]$1{.~[),;.1])&>])


                                                                                    Try it online!



                                                                                    A horrible solution, just made it work - I have no power to golf it...






                                                                                    share|improve this answer









                                                                                    $endgroup$




                                                                                    J, 55 bytes



                                                                                    [:-:/[([:/:~([*-@[)],@])"3(((;])@(#@]$1{.~[),;.1])&>])


                                                                                    Try it online!



                                                                                    A horrible solution, just made it work - I have no power to golf it...







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Jan 14 at 12:55









                                                                                    Galen IvanovGalen Ivanov

                                                                                    6,56711032




                                                                                    6,56711032























                                                                                        2












                                                                                        $begingroup$

                                                                                        Haskell, 74 73 bytes



                                                                                        import Data.Lists
                                                                                        i#m|c<-chunksOf i=c.transpose=<<c m
                                                                                        (m!n)i=i#m\i#n==


                                                                                        Note: TIO hasn't installed Data.Lists, so I'm using Data.List instead an add the missing function chunksOf: Try it online!



                                                                                        i#m=           -- function '#' makes a list of all transposed jigsaw blocks of matrix 'm'
                                                                                        -- of size 'i'
                                                                                        c<-chunksOf i -- define helper function 'c' that splits it's argument into
                                                                                        -- chunks of site 'i'
                                                                                        c m -- split the matrix into chunks of size 'i'
                                                                                        =<< -- for each chunk
                                                                                        transpose -- transpose
                                                                                        c. -- and split into chunks of size 'i', again
                                                                                        -- flatten one level of nesting ('=<<' is concatMap)

                                                                                        (m!n)i= -- main function
                                                                                        i#m\i#n -- remove every element of i#n from i#m
                                                                                        == -- and check if it results in an empty list





                                                                                        share|improve this answer











                                                                                        $endgroup$


















                                                                                          2












                                                                                          $begingroup$

                                                                                          Haskell, 74 73 bytes



                                                                                          import Data.Lists
                                                                                          i#m|c<-chunksOf i=c.transpose=<<c m
                                                                                          (m!n)i=i#m\i#n==


                                                                                          Note: TIO hasn't installed Data.Lists, so I'm using Data.List instead an add the missing function chunksOf: Try it online!



                                                                                          i#m=           -- function '#' makes a list of all transposed jigsaw blocks of matrix 'm'
                                                                                          -- of size 'i'
                                                                                          c<-chunksOf i -- define helper function 'c' that splits it's argument into
                                                                                          -- chunks of site 'i'
                                                                                          c m -- split the matrix into chunks of size 'i'
                                                                                          =<< -- for each chunk
                                                                                          transpose -- transpose
                                                                                          c. -- and split into chunks of size 'i', again
                                                                                          -- flatten one level of nesting ('=<<' is concatMap)

                                                                                          (m!n)i= -- main function
                                                                                          i#m\i#n -- remove every element of i#n from i#m
                                                                                          == -- and check if it results in an empty list





                                                                                          share|improve this answer











                                                                                          $endgroup$
















                                                                                            2












                                                                                            2








                                                                                            2





                                                                                            $begingroup$

                                                                                            Haskell, 74 73 bytes



                                                                                            import Data.Lists
                                                                                            i#m|c<-chunksOf i=c.transpose=<<c m
                                                                                            (m!n)i=i#m\i#n==


                                                                                            Note: TIO hasn't installed Data.Lists, so I'm using Data.List instead an add the missing function chunksOf: Try it online!



                                                                                            i#m=           -- function '#' makes a list of all transposed jigsaw blocks of matrix 'm'
                                                                                            -- of size 'i'
                                                                                            c<-chunksOf i -- define helper function 'c' that splits it's argument into
                                                                                            -- chunks of site 'i'
                                                                                            c m -- split the matrix into chunks of size 'i'
                                                                                            =<< -- for each chunk
                                                                                            transpose -- transpose
                                                                                            c. -- and split into chunks of size 'i', again
                                                                                            -- flatten one level of nesting ('=<<' is concatMap)

                                                                                            (m!n)i= -- main function
                                                                                            i#m\i#n -- remove every element of i#n from i#m
                                                                                            == -- and check if it results in an empty list





                                                                                            share|improve this answer











                                                                                            $endgroup$



                                                                                            Haskell, 74 73 bytes



                                                                                            import Data.Lists
                                                                                            i#m|c<-chunksOf i=c.transpose=<<c m
                                                                                            (m!n)i=i#m\i#n==


                                                                                            Note: TIO hasn't installed Data.Lists, so I'm using Data.List instead an add the missing function chunksOf: Try it online!



                                                                                            i#m=           -- function '#' makes a list of all transposed jigsaw blocks of matrix 'm'
                                                                                            -- of size 'i'
                                                                                            c<-chunksOf i -- define helper function 'c' that splits it's argument into
                                                                                            -- chunks of site 'i'
                                                                                            c m -- split the matrix into chunks of size 'i'
                                                                                            =<< -- for each chunk
                                                                                            transpose -- transpose
                                                                                            c. -- and split into chunks of size 'i', again
                                                                                            -- flatten one level of nesting ('=<<' is concatMap)

                                                                                            (m!n)i= -- main function
                                                                                            i#m\i#n -- remove every element of i#n from i#m
                                                                                            == -- and check if it results in an empty list






                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited Jan 14 at 16:24

























                                                                                            answered Jan 14 at 15:41









                                                                                            niminimi

                                                                                            31.5k32185




                                                                                            31.5k32185























                                                                                                2












                                                                                                $begingroup$


                                                                                                C# (Visual C# Interactive Compiler), 186 bytes





                                                                                                (a,b,n)=>{strings(intc){int i=0,j,l=a.Length,m=l/n;var r=new string[m*m];for(;i<l;i++)for(j=0;j<l;)r[i/n*m+j/n]+=c[i][j++];Array.Sort(r);return r;}return s(a).SequenceEqual(s(b));}


                                                                                                Try it online!



                                                                                                -1 thanks to @KevinCruijssen!



                                                                                                Less golfed code:



                                                                                                // anonymous function
                                                                                                // a and b are 2d jagged arrays
                                                                                                // n is the size of the sub matrix
                                                                                                (a,b,n)=>{
                                                                                                // helper function that translates
                                                                                                // the sub matrices into strings
                                                                                                // of digits.
                                                                                                strings(intc){
                                                                                                // i and j are loop counters
                                                                                                int i=0,j,
                                                                                                // l is the size of a side of a matrix
                                                                                                l=a.Length,
                                                                                                // m is the number of sub matrices
                                                                                                // per side of a matrix
                                                                                                m=l/n;
                                                                                                // the concatenated digits are
                                                                                                // stored in a single dimension
                                                                                                // array
                                                                                                var r=new string[m*m];
                                                                                                // nested loops build up
                                                                                                // the digit strings
                                                                                                for(;i<l;i++)
                                                                                                for(j=0;j<l;)
                                                                                                r[i/n*m+j/n]+=c[i][j++];
                                                                                                // The resulting array is
                                                                                                // sorted before it is returned for
                                                                                                // ease of comparison.
                                                                                                Array.Sort(r);
                                                                                                return r;
                                                                                                }
                                                                                                return s(a).SequenceEqual(s(b));
                                                                                                }





                                                                                                share|improve this answer











                                                                                                $endgroup$













                                                                                                • $begingroup$
                                                                                                  One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                  $endgroup$
                                                                                                  – Kevin Cruijssen
                                                                                                  Jan 15 at 6:57










                                                                                                • $begingroup$
                                                                                                  Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                  $endgroup$
                                                                                                  – dana
                                                                                                  Jan 15 at 7:02
















                                                                                                2












                                                                                                $begingroup$


                                                                                                C# (Visual C# Interactive Compiler), 186 bytes





                                                                                                (a,b,n)=>{strings(intc){int i=0,j,l=a.Length,m=l/n;var r=new string[m*m];for(;i<l;i++)for(j=0;j<l;)r[i/n*m+j/n]+=c[i][j++];Array.Sort(r);return r;}return s(a).SequenceEqual(s(b));}


                                                                                                Try it online!



                                                                                                -1 thanks to @KevinCruijssen!



                                                                                                Less golfed code:



                                                                                                // anonymous function
                                                                                                // a and b are 2d jagged arrays
                                                                                                // n is the size of the sub matrix
                                                                                                (a,b,n)=>{
                                                                                                // helper function that translates
                                                                                                // the sub matrices into strings
                                                                                                // of digits.
                                                                                                strings(intc){
                                                                                                // i and j are loop counters
                                                                                                int i=0,j,
                                                                                                // l is the size of a side of a matrix
                                                                                                l=a.Length,
                                                                                                // m is the number of sub matrices
                                                                                                // per side of a matrix
                                                                                                m=l/n;
                                                                                                // the concatenated digits are
                                                                                                // stored in a single dimension
                                                                                                // array
                                                                                                var r=new string[m*m];
                                                                                                // nested loops build up
                                                                                                // the digit strings
                                                                                                for(;i<l;i++)
                                                                                                for(j=0;j<l;)
                                                                                                r[i/n*m+j/n]+=c[i][j++];
                                                                                                // The resulting array is
                                                                                                // sorted before it is returned for
                                                                                                // ease of comparison.
                                                                                                Array.Sort(r);
                                                                                                return r;
                                                                                                }
                                                                                                return s(a).SequenceEqual(s(b));
                                                                                                }





                                                                                                share|improve this answer











                                                                                                $endgroup$













                                                                                                • $begingroup$
                                                                                                  One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                  $endgroup$
                                                                                                  – Kevin Cruijssen
                                                                                                  Jan 15 at 6:57










                                                                                                • $begingroup$
                                                                                                  Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                  $endgroup$
                                                                                                  – dana
                                                                                                  Jan 15 at 7:02














                                                                                                2












                                                                                                2








                                                                                                2





                                                                                                $begingroup$


                                                                                                C# (Visual C# Interactive Compiler), 186 bytes





                                                                                                (a,b,n)=>{strings(intc){int i=0,j,l=a.Length,m=l/n;var r=new string[m*m];for(;i<l;i++)for(j=0;j<l;)r[i/n*m+j/n]+=c[i][j++];Array.Sort(r);return r;}return s(a).SequenceEqual(s(b));}


                                                                                                Try it online!



                                                                                                -1 thanks to @KevinCruijssen!



                                                                                                Less golfed code:



                                                                                                // anonymous function
                                                                                                // a and b are 2d jagged arrays
                                                                                                // n is the size of the sub matrix
                                                                                                (a,b,n)=>{
                                                                                                // helper function that translates
                                                                                                // the sub matrices into strings
                                                                                                // of digits.
                                                                                                strings(intc){
                                                                                                // i and j are loop counters
                                                                                                int i=0,j,
                                                                                                // l is the size of a side of a matrix
                                                                                                l=a.Length,
                                                                                                // m is the number of sub matrices
                                                                                                // per side of a matrix
                                                                                                m=l/n;
                                                                                                // the concatenated digits are
                                                                                                // stored in a single dimension
                                                                                                // array
                                                                                                var r=new string[m*m];
                                                                                                // nested loops build up
                                                                                                // the digit strings
                                                                                                for(;i<l;i++)
                                                                                                for(j=0;j<l;)
                                                                                                r[i/n*m+j/n]+=c[i][j++];
                                                                                                // The resulting array is
                                                                                                // sorted before it is returned for
                                                                                                // ease of comparison.
                                                                                                Array.Sort(r);
                                                                                                return r;
                                                                                                }
                                                                                                return s(a).SequenceEqual(s(b));
                                                                                                }





                                                                                                share|improve this answer











                                                                                                $endgroup$




                                                                                                C# (Visual C# Interactive Compiler), 186 bytes





                                                                                                (a,b,n)=>{strings(intc){int i=0,j,l=a.Length,m=l/n;var r=new string[m*m];for(;i<l;i++)for(j=0;j<l;)r[i/n*m+j/n]+=c[i][j++];Array.Sort(r);return r;}return s(a).SequenceEqual(s(b));}


                                                                                                Try it online!



                                                                                                -1 thanks to @KevinCruijssen!



                                                                                                Less golfed code:



                                                                                                // anonymous function
                                                                                                // a and b are 2d jagged arrays
                                                                                                // n is the size of the sub matrix
                                                                                                (a,b,n)=>{
                                                                                                // helper function that translates
                                                                                                // the sub matrices into strings
                                                                                                // of digits.
                                                                                                strings(intc){
                                                                                                // i and j are loop counters
                                                                                                int i=0,j,
                                                                                                // l is the size of a side of a matrix
                                                                                                l=a.Length,
                                                                                                // m is the number of sub matrices
                                                                                                // per side of a matrix
                                                                                                m=l/n;
                                                                                                // the concatenated digits are
                                                                                                // stored in a single dimension
                                                                                                // array
                                                                                                var r=new string[m*m];
                                                                                                // nested loops build up
                                                                                                // the digit strings
                                                                                                for(;i<l;i++)
                                                                                                for(j=0;j<l;)
                                                                                                r[i/n*m+j/n]+=c[i][j++];
                                                                                                // The resulting array is
                                                                                                // sorted before it is returned for
                                                                                                // ease of comparison.
                                                                                                Array.Sort(r);
                                                                                                return r;
                                                                                                }
                                                                                                return s(a).SequenceEqual(s(b));
                                                                                                }






                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                edited Jan 15 at 7:56

























                                                                                                answered Jan 15 at 6:46









                                                                                                danadana

                                                                                                69145




                                                                                                69145












                                                                                                • $begingroup$
                                                                                                  One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                  $endgroup$
                                                                                                  – Kevin Cruijssen
                                                                                                  Jan 15 at 6:57










                                                                                                • $begingroup$
                                                                                                  Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                  $endgroup$
                                                                                                  – dana
                                                                                                  Jan 15 at 7:02


















                                                                                                • $begingroup$
                                                                                                  One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                  $endgroup$
                                                                                                  – Kevin Cruijssen
                                                                                                  Jan 15 at 6:57










                                                                                                • $begingroup$
                                                                                                  Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                  $endgroup$
                                                                                                  – dana
                                                                                                  Jan 15 at 7:02
















                                                                                                $begingroup$
                                                                                                One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                Jan 15 at 6:57




                                                                                                $begingroup$
                                                                                                One minor thing to golf, the j++ can be removed and can be placed at +=c[i][j++]+" "; to save a byte.
                                                                                                $endgroup$
                                                                                                – Kevin Cruijssen
                                                                                                Jan 15 at 6:57












                                                                                                $begingroup$
                                                                                                Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                $endgroup$
                                                                                                – dana
                                                                                                Jan 15 at 7:02




                                                                                                $begingroup$
                                                                                                Thanks for the tip :) Interestingly enough, I came up with almost the exact same solution as the Java one.
                                                                                                $endgroup$
                                                                                                – dana
                                                                                                Jan 15 at 7:02











                                                                                                1












                                                                                                $begingroup$


                                                                                                PHP, 186 163 162 bytes





                                                                                                function($a,$b,$n){$f=function($j,$n){foreach($j as$x=>$r)foreach($r as$y=>$v)$o[count($j)*($x/$n|0)+$y/$n|0].=$v;sort($o);return$o;};return$f($a,$n)==$f($b,$n);}


                                                                                                Try it online!



                                                                                                Like all good challenges, I started off thinking this was fairly easy and it threw me some curves. Nicely done @Kevin Cruijssen!



                                                                                                Chunks the matrix into strings containing the values for each block. Arrays are then sorted and compared for equality.



                                                                                                Ungolfed:



                                                                                                function jigsaw_chunk( $j, $n ) {
                                                                                                foreach( $j as $x => $r ) {
                                                                                                foreach( $r as $y => $v ) {
                                                                                                $o[ count( $j ) * floor( $x/$n ) + floor( $y/$n )] .= $v;
                                                                                                }
                                                                                                }
                                                                                                sort( $o );
                                                                                                return $o;
                                                                                                }

                                                                                                function jigsaw_test( $a, $b, $n ) {
                                                                                                return jigsaw_chunk( $a, $n ) == jigsaw_chunk( $b, $n );
                                                                                                }

                                                                                                // Test 6
                                                                                                var_dump( jigsaw_test( [[1,2],[3,4]], [[2,3],[1,1]], 1 ) );


                                                                                                Output



                                                                                                bool(false)





                                                                                                share|improve this answer











                                                                                                $endgroup$


















                                                                                                  1












                                                                                                  $begingroup$


                                                                                                  PHP, 186 163 162 bytes





                                                                                                  function($a,$b,$n){$f=function($j,$n){foreach($j as$x=>$r)foreach($r as$y=>$v)$o[count($j)*($x/$n|0)+$y/$n|0].=$v;sort($o);return$o;};return$f($a,$n)==$f($b,$n);}


                                                                                                  Try it online!



                                                                                                  Like all good challenges, I started off thinking this was fairly easy and it threw me some curves. Nicely done @Kevin Cruijssen!



                                                                                                  Chunks the matrix into strings containing the values for each block. Arrays are then sorted and compared for equality.



                                                                                                  Ungolfed:



                                                                                                  function jigsaw_chunk( $j, $n ) {
                                                                                                  foreach( $j as $x => $r ) {
                                                                                                  foreach( $r as $y => $v ) {
                                                                                                  $o[ count( $j ) * floor( $x/$n ) + floor( $y/$n )] .= $v;
                                                                                                  }
                                                                                                  }
                                                                                                  sort( $o );
                                                                                                  return $o;
                                                                                                  }

                                                                                                  function jigsaw_test( $a, $b, $n ) {
                                                                                                  return jigsaw_chunk( $a, $n ) == jigsaw_chunk( $b, $n );
                                                                                                  }

                                                                                                  // Test 6
                                                                                                  var_dump( jigsaw_test( [[1,2],[3,4]], [[2,3],[1,1]], 1 ) );


                                                                                                  Output



                                                                                                  bool(false)





                                                                                                  share|improve this answer











                                                                                                  $endgroup$
















                                                                                                    1












                                                                                                    1








                                                                                                    1





                                                                                                    $begingroup$


                                                                                                    PHP, 186 163 162 bytes





                                                                                                    function($a,$b,$n){$f=function($j,$n){foreach($j as$x=>$r)foreach($r as$y=>$v)$o[count($j)*($x/$n|0)+$y/$n|0].=$v;sort($o);return$o;};return$f($a,$n)==$f($b,$n);}


                                                                                                    Try it online!



                                                                                                    Like all good challenges, I started off thinking this was fairly easy and it threw me some curves. Nicely done @Kevin Cruijssen!



                                                                                                    Chunks the matrix into strings containing the values for each block. Arrays are then sorted and compared for equality.



                                                                                                    Ungolfed:



                                                                                                    function jigsaw_chunk( $j, $n ) {
                                                                                                    foreach( $j as $x => $r ) {
                                                                                                    foreach( $r as $y => $v ) {
                                                                                                    $o[ count( $j ) * floor( $x/$n ) + floor( $y/$n )] .= $v;
                                                                                                    }
                                                                                                    }
                                                                                                    sort( $o );
                                                                                                    return $o;
                                                                                                    }

                                                                                                    function jigsaw_test( $a, $b, $n ) {
                                                                                                    return jigsaw_chunk( $a, $n ) == jigsaw_chunk( $b, $n );
                                                                                                    }

                                                                                                    // Test 6
                                                                                                    var_dump( jigsaw_test( [[1,2],[3,4]], [[2,3],[1,1]], 1 ) );


                                                                                                    Output



                                                                                                    bool(false)





                                                                                                    share|improve this answer











                                                                                                    $endgroup$




                                                                                                    PHP, 186 163 162 bytes





                                                                                                    function($a,$b,$n){$f=function($j,$n){foreach($j as$x=>$r)foreach($r as$y=>$v)$o[count($j)*($x/$n|0)+$y/$n|0].=$v;sort($o);return$o;};return$f($a,$n)==$f($b,$n);}


                                                                                                    Try it online!



                                                                                                    Like all good challenges, I started off thinking this was fairly easy and it threw me some curves. Nicely done @Kevin Cruijssen!



                                                                                                    Chunks the matrix into strings containing the values for each block. Arrays are then sorted and compared for equality.



                                                                                                    Ungolfed:



                                                                                                    function jigsaw_chunk( $j, $n ) {
                                                                                                    foreach( $j as $x => $r ) {
                                                                                                    foreach( $r as $y => $v ) {
                                                                                                    $o[ count( $j ) * floor( $x/$n ) + floor( $y/$n )] .= $v;
                                                                                                    }
                                                                                                    }
                                                                                                    sort( $o );
                                                                                                    return $o;
                                                                                                    }

                                                                                                    function jigsaw_test( $a, $b, $n ) {
                                                                                                    return jigsaw_chunk( $a, $n ) == jigsaw_chunk( $b, $n );
                                                                                                    }

                                                                                                    // Test 6
                                                                                                    var_dump( jigsaw_test( [[1,2],[3,4]], [[2,3],[1,1]], 1 ) );


                                                                                                    Output



                                                                                                    bool(false)






                                                                                                    share|improve this answer














                                                                                                    share|improve this answer



                                                                                                    share|improve this answer








                                                                                                    edited Jan 15 at 19:17

























                                                                                                    answered Jan 15 at 18:23









                                                                                                    gwaughgwaugh

                                                                                                    45113




                                                                                                    45113























                                                                                                        1












                                                                                                        $begingroup$


                                                                                                        Red, 148 147 142 bytes



                                                                                                        func[a b n][g: func[m][
                                                                                                        sort collect[loop k:(length? m)/ n[i: 0
                                                                                                        loop k[keep/only
                                                                                                        collect[loop n[keep
                                                                                                        take/part m/(i: i + 1) n]]]]]](g a)= g b]


                                                                                                        Try it online!






                                                                                                        share|improve this answer











                                                                                                        $endgroup$


















                                                                                                          1












                                                                                                          $begingroup$


                                                                                                          Red, 148 147 142 bytes



                                                                                                          func[a b n][g: func[m][
                                                                                                          sort collect[loop k:(length? m)/ n[i: 0
                                                                                                          loop k[keep/only
                                                                                                          collect[loop n[keep
                                                                                                          take/part m/(i: i + 1) n]]]]]](g a)= g b]


                                                                                                          Try it online!






                                                                                                          share|improve this answer











                                                                                                          $endgroup$
















                                                                                                            1












                                                                                                            1








                                                                                                            1





                                                                                                            $begingroup$


                                                                                                            Red, 148 147 142 bytes



                                                                                                            func[a b n][g: func[m][
                                                                                                            sort collect[loop k:(length? m)/ n[i: 0
                                                                                                            loop k[keep/only
                                                                                                            collect[loop n[keep
                                                                                                            take/part m/(i: i + 1) n]]]]]](g a)= g b]


                                                                                                            Try it online!






                                                                                                            share|improve this answer











                                                                                                            $endgroup$




                                                                                                            Red, 148 147 142 bytes



                                                                                                            func[a b n][g: func[m][
                                                                                                            sort collect[loop k:(length? m)/ n[i: 0
                                                                                                            loop k[keep/only
                                                                                                            collect[loop n[keep
                                                                                                            take/part m/(i: i + 1) n]]]]]](g a)= g b]


                                                                                                            Try it online!







                                                                                                            share|improve this answer














                                                                                                            share|improve this answer



                                                                                                            share|improve this answer








                                                                                                            edited Jan 16 at 4:51

























                                                                                                            answered Jan 15 at 8:19









                                                                                                            Galen IvanovGalen Ivanov

                                                                                                            6,56711032




                                                                                                            6,56711032






























                                                                                                                draft saved

                                                                                                                draft discarded




















































                                                                                                                If this is an answer to a challenge…




                                                                                                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                More generally…




                                                                                                                • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                draft saved


                                                                                                                draft discarded














                                                                                                                StackExchange.ready(
                                                                                                                function () {
                                                                                                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178728%2fmatrix-jigsaw-puzzles%23new-answer', 'question_page');
                                                                                                                }
                                                                                                                );

                                                                                                                Post as a guest















                                                                                                                Required, but never shown





















































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown

































                                                                                                                Required, but never shown














                                                                                                                Required, but never shown












                                                                                                                Required, but never shown







                                                                                                                Required, but never shown







                                                                                                                Popular posts from this blog

                                                                                                                Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                                                                                                                ComboBox Display Member on multiple fields

                                                                                                                Is it possible to collect Nectar points via Trainline?