Skip to Content
 

An Algorithmic Puzzle

14 replies [Last post]
rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Board Puzzle Diagram

If you wish to color two cells out of the six on a 2 column by 3 row grid, there are precisely 6c2 (15) different permutations. Now let's say you have three different colors and you want to create grids each with 2 cells of each of the three colors and no overlap. The question is:

Is there a set of precisely 15 grids such that all 15 permutations of each of the three colors are represented?
If so, what is it (or what are they)?
And, how do you figure it out?

Operationally, this can be imagined by constructing 15 unique permutations for each color with the remaining spaces empty and then layer one from each of the three sets such that none of the colored spaces overlap and you have no redundancies or left over layers. (see image) You could probably write an algorithm that checks all the combinations, but my sense is that given the number of combinations, an exhaustive search might tax computational time. If I'm correct, 6^15 * some constant, number of calculations. And, it is easy to imagine a slightly expanded grid that is computationally impossible. But, an operational solution is a solution.

So for those of you who like puzzles, here's one that I need help with to create the board pieces for my design. And, help in the form of a possible solution would be greatly appreciated.

ichbin
Offline
Joined: 09/21/2010
Is this what you are looking for?

Here is a picture of 5 sets of 3 tiles 2x3 where there is no overlap.

You can find it here

http://www.bgdf.com/sites/default/files/images/colors.JPG

dplepage
Offline
Joined: 08/11/2010
Brute force solution

I think this works:

rg rg gr gb gg bg bg gr rb rr bb br br rb gb
bg gr bb gr rb rr br br rg gb rg rb gg gb bg
br bb rg br br gb rg gb gb gb rg gg br rg rr

I write a quick python script to do this by brute force - it finds a maximal independent set greedily, checks if it's got 15 elements, then discards it, shuffles the candidates, and tries again until it finds the maximum set. I put the code online here: http://paste.pocoo.org/show/271098/ in case you'd like to look at it.

rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Swift and Effective

Beautiful. Thanks.

I had an intuition that a solution was possible, but I didn't know for sure. But, you're quick algorithm put it there. Do you think there is more than just one?

Looking at the list of pairs now, it reminds of Sudoku. Each cell must contain 2 of each color and each row must include each of the 15 permutations of RGB.

Thanks again!

dplepage
Offline
Joined: 08/11/2010
Multiple solutions

There are certainly multiple solutions - you can, for example, take the three that have the same color for the bottom two and cycle the colors of the other four circles to get two other solutions that are almost the same. Running the program repeatedly is likely to generate different solutions.

Your problem is related to sudoku, but harder - it reduces to the Maximum Independent Set problem, which is a known NP-Complete problem (meaning that in general there are no known fast algorithms for solving it). Sudoku, by contast, can be solved in time polynomial in the size of the grid.

rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Fascinating

You're the second person to see this as a "[fill in the blank] problem". I showed the puzzle first to a friend of mine who's a mathematician and he was wondering whether you could use a geometric space to solve the problem. It was a brief conversation that diverted into a discussion about how the grids might be used to construct a method to do random sampling of three drugs across two different dimensions of the population. So, we didn't find a solution. But, essentially, I noticed that he, like you, figured out a way to see the fundamental problem as analogous to a mathematical or computational puzzle with a known solution.

I was hoping at the time, by introducing it to my friend, that we might be able to figure out a formulaic solution, but I guess neither one of us recognized the NP-complete nature of the puzzle. In which case, all bets are off. I guess it's a good thing that I only need a 2x3 grid with 3 colors then.

Thanks again.

dplepage
Offline
Joined: 08/11/2010
I take it back.

I retract what I said about this being NP-complete - my proof was flawed.

While you can treat this as an instance of the Maximum Independent Set problem, which is NP-complete, there's more structure to your problem and this admits several faster techniques.

One is to do what ichbin did - divide the 15 basic tiles into five groups of three such that each tile appears once and each group has no mutually overlapping tiles. You can then color each group in three different ways (r,g,b; g,b,r; b,r,g) and you'll get a solution. Then you just need to solve Independent Set on the 15-node grid; even that is very structured and I'm pretty sure there's a quick solution.

rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Elegant

I must admit, I did not see ichbin's solution until you pointed it out. Simply brilliant!

Thanks, to the both of you.

stubert
Offline
Joined: 01/26/2009
be careful with your calculations...

You actually have far fewer possibilities than you think unless something on the cards orients them in a specific way.

There are actually only 8 possibilities, as the 2x3 unit area has rotational symmetry. In your illustration, the first 7 of the filled-in areas is exactly the same as the last 7 if you turn the cards upside-down (with the 8th being the illustration where the 2 units in the center row are colored).

rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Further Puzzles!

Thanks for the head's up. I was planning to print symbols on the spaces which can only be oriented in one direction (Mayan Glyphs to be precise), so I think I will need all fifteen. But you're absolutely right about the fact that rotating them would destroy the non-redundancy.

However, if it IS de-themed, would the combinatorial mapping of all three colors without redundancy work out in that case?

stubert
Offline
Joined: 01/26/2009
Of course...

Yes, you would only need 8 cards to establish all patterns without redundancy, and there would be exactly 16 distinct solutions. (for a total of 128 cards in 16 sets of 8).

dplepage
Offline
Joined: 08/11/2010
Clarification

I'm not sure what you mean by "would the combinatorial mapping work out", but certainly if you want to create 8 cards the cover all 8 possible distinct tiles in each color, you can do so:

bb gr br br gg gb rg gr
gr bg bg rg rb rr bb br
gr br rg gb br bg gr gb

modified python script: http://paste.pocoo.org/show/271509/

dplepage
Offline
Joined: 08/11/2010
16?

How can there be exactly 16 solutions? For any solution, you can permute the colors (e.g. replace red with green, green with blue, and blue with red) six different ways to get different solutions; it follows that the number of solutions should be a multiple of six.

rcjames14
rcjames14's picture
Offline
Joined: 09/17/2010
Combinatorial Mapping

If you allow for rotation of the boards, then I believe 6 out of the 15 arrangements of each color would be redundant. So, you would need a total of 9 boards to create every single arrangement for each color.

The question is, whether there is a way to combine all the three colors such that you can get every single arrangement of each color on only 9 boards.

stubert
Offline
Joined: 01/26/2009
My mistake...

There are 48 distinct cards that could be made...

The number of distinct combinations of 8 cards that fulfill the criteria of those 48 cards is somewhere in the neighborhood of 124,000.

Syndicate content


forum | by Dr. Radut