# Golf the colors of a rug [tag:code-golf] [tag:kolmogorov-complexity] ## Background The challenge is based on this rug: [![Rug][1]][1] Its colors seem very regular, but the pattern isn't obvious. However, it becomes visible when we move vertical stripes of the rug up and down: [![Rug strips][2]][2] All stripes are colored in the same way, but each stripe is offset by some height, except for a few irregularities. Also, the stripes have different widths. First, we need to list all colors: ``` 0: blue-ish white 1: lighter blue 2: darker blue 3: darkest blue 4: green-ish white (the color between the middle orange rows) 5: middle green 6: dark green 7: orange 8: light red 9: dark red ``` Now, we can lay a grid of cells of equal color over this image. I found that using a cell size of 73.5x129 pixels seems to be a good compromise between precision and compactness. This results in a 42x32 grid, which looks like this when overlayed over the rug: [![Rug grid][3]][3] Correcting for some perspective errors, we now can approximate the colors of this rug like this: [![Rug simplified][4]][4] The color scheme shared by all stripes consists, from top to bottom, of these 42 colors: `[3, 3, 2, 3, 3, 2, 2, 0, 2, 2, 1, 1, 3, 1, 1, 5, 5, 6, 5, 5, 6, 6, 7, 6, 6, 7, 7, 4, 7, 7, 8, 8, 7, 8, 8, 9, 9, 8, 9, 9, 9, 9]`. (This already contains the information that some rows have different heights, by having multiple entries of the same color in a row.) There are 18 stripes with widthes `[2, 3, 3, 3, 1, 1, 4, 2, 1, 6, 1, 1, 2, 2, 2, 3, 2, 3]`. Their vertical offsets are `[3, 4, 3, 4, 2, 0, 2, 4, 7, 9, 10, 9, 5, 3, 5, 3, 4, 5]`, which means the first stripe starts at the color at index 3 in the common scheme, the second stripe at index 4 and so on. Starting from the respective start index, the next 32 colors are used; remaining colors (if any) are unused. There are some irregularities in the rug. I didn't find a better way of expressing them except for listing their X and Y coordinates in the grid together with their colors: ``` X [8, 9, 10, 19, 19, 12, 0, 1, 2, 3, 4, 2, 3, 4, 2, 3, 4, 5, 13, 14, 15, 16, 17, 18, 34] Y [18, 18, 18, 23, 24, 27, 31, 31, 29, 29, 29, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31] Color [5, 5, 5, 0, 0, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 8, 8, 9] ``` (TODO why doesn't this align!?) ## Challenge Output this 42x32 grid of numbers from 0-9, each corresponding to the color of one cell of the rug: ``` 333333333332322223302222221222332233333222 332223332223333332221111111122332233322222 222222222223233332221111113100220022222000 220002220002322220013333331322222222200222 002220002222322222211111111122002200022222 222222222220200002231111115111221122222111 221112221112222221115555555511221122211111 111111111112022221115555556533113311111333 113331113331211113356666665611111111133111 331113331111211111155555555511331133311111 111111111113133331165555556555115511111555 115551115551111115556666666655115511155555 555555555551311115556666667666556655555666 556665556665155556667777776755555555566555 665556665555155555566666666655665566655555 555555555556566665576666667666556655555666 556665556665555556667777777766556655566666 666666666665655556667777774777667766666777 667776665556566667774444447466666666677666 776667776666566666677777777766776677766666 666666666667677776647777778777667766666777 667776667776666667778888888877667766677777 777777777776766667778888887844774477777444 774447774447677774407777778777777777744777 447774447777677777708888888877447744477777 777777777774744447778888889888778877777888 778887778887777778889999999988778877788888 888888888887877778889999998977887788888777 887778887778788887798888889888888888877888 779997778888788888899999999988778877788888 889998888887877778889999999999889988888999 998889889998899998899999999999889998899999 ``` ## Rules - The program should not take input. - Formatting doesn't matter. - This is [tag:code-golf], so shortest answer (in bytes) wins. [1]: https://i.sstatic.net/a8uOQm.jpg [2]: https://i.sstatic.net/rhzn2m.jpg [3]: https://i.sstatic.net/7dLMHm.jpg [4]: https://i.sstatic.net/Y6eGgm.png