Building a puzzle game - how to calculate total of combination sets once "invalid" results are excluded?

92 Views Asked by At

Please bear with me on terminology; I am learning! Also, please correct me if I've gotten anything wrong so far.

Context: I am creating a single-player tile-based puzzle game where:

  1. Once tiles (200 in total) have been played in a slot (5 slots/tiles per turn), three or more of them cannot be played again together.
  2. This means any three or more of the initial five tiles, in any combination. If {1 2 3 4 5} has been played, then {1 3 5 10 15} is now an illegal move for the rest of the game; while {1 3 6 10 15} is legal.
  3. Five tiles are played every turn until there are no more legal plays (only five tiles can ever be played; more or fewer than five is not a legal play)

Question: What is the shortest possible length of a game with all legal plays?

My thoughts: So far I have discovered combinatorics seems the place to start, with a simple combination. Letting $n=200$ and $r=5$. Order is not important (tiles can be played in any slot), repetition is not allowed (tiles are unique). The number of sets of five tiles is

$$ C(n,r) = \binom{n}{r} = \frac{n!}{(r!(n-r)!)}. $$

This results in 2535650040 subsets, so as I understand it there are 2535650040 possible opening plays.

Each turn concludes and removes more subsequent options for sets, and this is the part I'm having deep trouble getting my head around turning into a formula.


Edit as requested to show an example for a smaller set: With a set of 7 tiles instead of 200, and 3 slots instead of 5, there are 35 subsets:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Instead of 3-tile combinations unable to be played in future moves, this uses 2-tile combinations unable to be played in future moves:

Move 01: {1,2,3}

Result: {1, 2, * }, {1, 3, * }, and {2, 3, * } are now illegal. 13/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 02: {1,4,5}

Result: {1, 2, * }, {1, 3, * }, {2, 3, * }, {1, 4, * }, {1, 5 * }, and {4, 5, * } are now illegal. 22/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 03: {1,6,7}

Result: {1, 2, * }, {1, 3, * }, {2, 3, * }, {1, 4, * }, {1, 5 * }, {4, 5, * }, {1, 6, * }, {1, 7, * }, and {6, 7, * } are now illegal. 27/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 04: {2,4,6}

Result: {1, 2, * }, {1, 3, * }, {2, 3, * }, {1, 4, * }, {1, 5 * }, {4, 5, * }, {1, 6, * }, {1, 7, * }, {6, 7, * }, {2, 4, * }, {2, 6, * }, and {4, 6, * } are now illegal. 31/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 05: {2, 5, 7}

Result: {1, 2, * }, {1, 3, * }, {2, 3, * }, {1, 4, * }, {1, 5 * }, {4, 5, * }, {1, 6, * }, {1, 7, * }, {6, 7, * }, {2, 4, * }, {2, 6, * }, {4, 6, * }, {2, 5, * }, {2, 7, * }, and {5, 7, * } are now illegal. 33/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 06: {3, 4, 7}

Result: {1, 2, * }, {1, 3, * }, {2, 3, * }, {1, 4, * }, {1, 5 * }, {4, 5, * }, {1, 6, * }, {1, 7, * }, {6, 7, * }, {2, 4, * }, {2, 6, * }, {4, 6, * }, {2, 5, * }, {2, 7, * }, {5, 7, * }, {3, 4, * }, {3, 7, * } and {4, 7 * } are now illegal. 34/35 sets cannot be played:

{1,2,3} {1,2,4} {1,2,5} {1,2,6} {1,2,7} {1,3,4} {1,3,5} {1,3,6} {1,3,7} {1,4,5} {1,4,6} {1,4,7} {1,5,6} {1,5,7} {1,6,7} {2,3,4} {2,3,5} {2,3,6} {2,3,7} {2,4,5} {2,4,6} {2,4,7} {2,5,6} {2,5,7} {2,6,7} {3,4,5} {3,4,6} {3,4,7} {3,5,6} {3,5,7} {3,6,7} {4,5,6} {4,5,7} {4,6,7} {5,6,7}

Move 07: {3, 5, 6} Final move - Result: 35/35 sets cannot be played

Outcome: 7 tiles, 3 slots, 2 matches illegal = 7 moves

200 tiles, 5 slots, 3 matches illegal = ? moves

I'm probably just not using the right terminology to look for what I need but as I've found several similar pages here (although mostly around excluding specific pairs or combinations from the start, while this is more self-referential), it seems like the right place to ask. The closest I've found was this Combinations with limited overlap which is a coding question but did have a similar problem to solve.

Again, I am fairly new to this and - trying to be - self-taught for personal projects (not knowledgeable on real maths at all; in my 40s and have mostly been working in the arts), so any help or direction would be much appreciated. Suggestions on where to research next or naming the formulas/theorems you would use would also be fantastic (as while I'd obviously love a direct answer, it's how to get there that will help me improve on solving this kind of problem in the future). Thank you!

2

There are 2 best solutions below

0
On

Trying to build this up one round at a time (currently working on round 3):

Round 1: $$ C(n,r) = \binom{n}{r} = \frac{n!}{r!(n-r)!} = 2535650040 $$

For the second round, let's start with the possibility that you 2 previous tiles and 3 new ones. That would look like $ \binom{r}{2} \binom{n-r}{r-2} $. The first term chooses 2 of the old ones, the second term chooses 3 new ones. Similarly, you can only have one new one $ \binom{r}{1} \binom{n-r}{r-1} $, and of course 5 new ones $ \binom{r}{0} \binom{n-r}{r-0} $. Since these are all unique to each other we can just add them together. I will introduce a new term $r_\max$ to be the maximum number of legal overlap.

Round 2: $$ \sum_{i = 0}^{r_\max} \binom{r}{i} \binom{n-r}{r-i} = \binom{5}{0} \binom{195}{5} + \binom{5}{1} \binom{195}{4} + \binom{5}{2} \binom{195}{3}= 2535459914 $$

2
On

If I understand correctly, you are looking for the independent domination number of a graph with one node per $r$-subset of $\{1,\dots,n\}$ and an edge for each pair of $r$-subsets that intersect in at least $m$ elements.

For your $n=7$, $r=3$, $m=2$ case, the minimum is $5$, obtained via integer linear programming:

{1,2,3}
{2,4,6}
{1,5,6}
{3,4,7}
{2,5,7}