It has been proven that the following 13 square Wang tiles always tile the plane aperiodically. This means that when the squares are arranged in a grid with all neighboring sides the same color, a translation of the pattern will never match up with itself.
We'll represent each tile textually by a 3×3 grid filled with spaces at the center and corners, and the numbers 1 through 5 instead of the colors red, green, blue, yellow, grey, at the edges:
2 2 2 1 1 1 4 3 2 2 4 3 2
1 2 1 3 2 3 2 1 3 1 3 2 4 4 4 4 4 5 4 5 5 5 5 5 5 4
3 2 3 2 3 2 1 2 1 4 1 2 2
Goal
Your task is to write a program that takes in a width and height and outputs a valid Wang tile grid with those dimensions. A valid tiling is one in which all the adjacent tile edges have the same color (or number). The smallest program in bytes wins.
Your input should come from stdin or command line arguments and output should go to stdout. The exact input format can be anything reasonably obvious, like >>> wangtiler 3 2
. The width and height are always positive integers.
Example (width = 3, height = 2)
Notice that when we layout the textual tiles the neighboring edges form necessary redundant pairs of digits:
1 2 1
2 11 22 1
2 3 2
2 3 2
4 55 55 4
1 2 2
(This is NOT the proper output format.)
We can compress these horizontally and vertically to get:
1 2 1
2 1 2 1
2 3 2
4 5 5 4
1 2 2
This compressed format is the proper output format you must use. The odd numbered lines must include their trailing space.
Graphical Bonus
Instead of having any textual output, your program may output an image of the tiled grid. The graphical tiles must be made up of four 45-45-90 triangles arranged in a square and use five easily distinguishable colors like the tiles above. The black borders are not required. The graphical tiles must be at least 32×32 pixels in size. No "compression" is applied to them.
Example bonus image: (same grid as example above)
The bonus is worth minus 150 bytes.
Notes
- You must use this set of 13 tiles.
- Tiles may not be rotated.
- Tiles may appear any number of times (including none at all).
- You may assume a valid tiling with any dimensions is possible.