Quantcast
Viewing latest article 11
Browse Latest Browse All 35

Simplest Tiling of the Floor

You should write a program or function which receives a string describing the floor as input and outputs or returns the area of the simplest meta-tiling which could create the given pattern of the floor.

The floor is a part of a square grid. Every square tile is colored either azure or black (represented by a and b in the input).

An example floor:

  aaaaabababaaaaa

A meta-tiling

  • is built from an N by M rectangular meta-tile of azure and black squares
  • the used meta-tiles are identical up to translation (you cannot rotate or mirror them)
  • if the sides of two meta-tiles are connected they should connect along their whole length (i.e. meta-tiles tile the space in a grid-like fashion)

An example meta-tile:

baaa

and the meta-tiling created by it:

       .       .       .    babababa    aaaaaaaa... babababa ...    aaaaaaaa        babababa    aaaaaaaa       .       .       .

This meta-tiling creates the upper shown floor as the left letters show:

       .       .       .    ********    ***aaaa*... *ababab* ...    *aaaaa**        ********    ********       .       .       .

A meta-tiling is simpler than another if the area of its meta-tile is smaller. Our example has an area of 2*2 = 4 which is the smallest possible for the example floor. So the output should be 4 for the example.

Input

  • A string consisting of the characters a b space and newline containing at least one a or b.
  • The letters (ab) form one 4-connected (side-by-side connected) shape.
  • There will be no unnecessary spaces at the front of the rows i.e. there will be at least one row starting with a or b.
  • You can choose of two input format:

    • No unnecessary whitespace at the end of rows (as seen in the examples).
    • Spaces on the right side of the rows to make all rows the same length as the longest row.
  • Trailing newline is optional.

Output

  • A single integer, the area of the smallest possible meta-tile whose tiling contains the input floor.

Examples

Examples are delimited by dashes. The three parts of an example are input, output and one of the possible smallest meta-tiles.

a1a----------------- aaaaaaaa1a-----------------aabaababaaaaba6aababa-----------------aabaaba  a aaabab18aabaabaaaaaaaababa-----------------baaaab8baaaaaab----------------- aaaaababbaaaa10aaaaaababb----------------- a aaab ba aba6aaabba----------------- aaaaababaaaa4aaab-----------------ba ba  b4baab-----------------baaabaaab9baaabaaab----------------- aaaaaabaaaaaa6aaaaab

This is code golf so the shortest entry wins.


Viewing latest article 11
Browse Latest Browse All 35

Trending Articles



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