Quantcast
Viewing all articles
Browse latest Browse all 35

Identify the smallest possible tile in the matrix

Challenge

Given a matrix of digits (0-9), find the smallest (in terms of area) rectangular matrix of digits where one or more copies of itself, possibly rotated, can tile the original matrix. Reflection is not allowed (think of a collection of tiles on a wall or floor).

Input can be taken in any reasonable ways to represent a matrix of integers or characters. Output format should be consistent with the input, but output in any orientation (out of four possible rotations) is allowed.

If there are multiple possible tiles of same area, you may output one or all of them. It is guaranteed to be solvable for any possible input, since the entire input matrix is always an option if no smaller tiles can cover it.

Standard rules apply. The shortest code in bytes wins.

Test cases

Input:0 1 2 3 45 6 7 8 90 1 2 3 45 6 7 8 90 1 2 3 45 6 7 8 9Output:0 1 2 3 45 6 7 8 9------------------Input:1 1 11 1 11 1 1Output:1------------------Input:1 2 34 5 67 8 9Output:1 2 34 5 67 8 9------------------Input:1 2 3 4 14 5 6 5 26 5 4 6 33 2 1 3 61 2 3 2 54 5 6 1 4Output:1 2 34 5 6------------------Input:0 0 0 00 1 0 10 0 0 00 0 0 01 0 1 00 0 0 0Valid Output 1:0 0 0 0 1 0Valid Output 2:0 1 00 0 0Invalid Output (because it is an L-shape, not a rectangular matrix):0 1 0 0 00------------------Input: (a hard case, suggested by Arnauld)1 2 1 2 1 11 1 2 1 2 22 1 1 2 1 21 2 2 1 2 12 1 2 1 2 2Output:1 2

Viewing all articles
Browse latest Browse all 35

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>