A difficult puzzle about filling holes with colored blocks

84 Views Asked by At

This puzzle originated from a very difficult challenge I came across while developing a game. I initially intended to post it on Stack Overflow, but this turned out to be primarily a logic/math issue. I must admit I wasn't able to do a lot of research on it since it's very particular, so I'd be glad if at least someone could point me in the right direction to solve it :)

Now, the puzzle:

Suppose we have colored blocks which we can use to fill some slots/holes, very similar to that classic toy for babies.

There is a set of possible shapes $S$, and set of possible colors $C$.

Each block has a color and a shape. We have infinite copies of a set of available blocks $B$. For example, we might have infinite green squares, blue triangles and green triangles, but no blue squares.

There are $H_s$ holes for every shape $s$ where $s\in S$. $H_s > 0$. A block may only fill a hole of the same shape.

Now, say we must fill those holes with $N_c$ blocks of every color $c$ where $c\in C$. Some holes may be left empty.

1. When is it possible to fulfill this condition, given the values of $B$ and $H_s$?

2. How can we distribute the blocks in the holes such that this condition is always met?

I've tried many times to solve this, to no avail. I've tried comparing the amount of shapes available to each color in the blocks to the required amount of each color, but this fails as it ignores the fact that $H_s > 1$. I then tried multiplying the amount of shapes available to each color by $H_s$, but this also fails as it assumes holes may be filled more than once. I even tried plotting colors and shapes onto a graph to look for patterns but it didn't help. One of the main issues is the fact that there are multiple ways to fill the holes. I'm really stuck here, any help would be appreciated.