Quantcast
Viewing all articles
Browse latest Browse all 35

Is it a checkered tiling?

Background

A checkered tiling of a rectangular grid is a tiling using some polyominoes, where each region can be colored either black or white so that no two polyominoes sharing an edge has the same color. In graph-theoretic terms, the chromatic number of the adjacency graph is 2.

Terminology adapted from a Fillomino variant recently posted on GMPuzzles.

The following is an example of a checkered tiling, with a possible black-and-white coloring on the right:

+-+-+-+-+-++-+-+-+-+-+|A A A|B|C|   |X X X| |X|++-+-+-++++-+-+-++|A|D D|C C|   |X|   |X X|+-+-+++-++-+-+++-+|E|F|D|C|G|   | |X| |X| |++-+-+-++++-+-+-++|E E|H|G G|   |   |X|   |++++-+-+++++-+-+|E E|H H H|   |   |X X X|+-+-+-+-+-++-+-+-+-+-+

The following is not a checkered tiling, because it is not possible to color E, H, I with two colors.

+-+-+-+-+-+|A A A|B|C|++-+-+-++|A|D D|C C|+-+-+++-+|E|F|D|C|G|++-+-+-++|E E|H|G G|++-++-+-+|E|I|H H H|+-+-+-+-+-+

Task

Given a tiling, test if it is a checkered tiling.

A tiling can be input as a 2D array or string where each region is represented by a unique single alphanumeric character or integer. For example, the top array can be represented as

AAABCADDCCEFDCGEEHGGEEHHH

or

[[0, 0, 0, 1, 2], [0, 3, 3, 2, 2], [4, 5, 3, 2, 6], [4, 4, 7, 6, 6], [4, 4, 7, 7, 7]]

For output, you can choose to

  1. output truthy/falsy using your language's convention (swapping is allowed), or
  2. use two distinct, fixed values to represent true (affirmative) or false (negative) respectively.

Test cases

Truthy

000000120011201322330123456789ABCDEFGHIJ000010002

Falsy

01220012010201234056740011022132443345

Brownie points to the first answer that beats or ties with 17 bytes in Dyalog APL (any version) or 96 bytes in JS (latest browser support, not very well golfed).


Viewing all articles
Browse latest Browse all 35

Trending Articles