0

Programming up a pattern matching game.

We have 135 symbols. Of those 135, a subset of 108 symbols is used. From the subset of 108, either 18, 21, or 24 symbols are chosen at random. For simplicity, let's stick with 18.

When a symbol is chosen, it can't be used again.

Using groups of 27 symbols at a time, we need to generate the minimum number of groups of 27, making sure that when 18 symbols are chosen at random from the subset of 108, we are guaranteed that 1 of them will match at least 12 other symbols from the 18 randoms in at least 1 of the groups of 27.

Question is, what is the programming logic (we're using C#) to generate the groups of 27 making sure to meet the symbol matching requirements?

If we didn't care about having to match things up, it would be a straight combination/factorial calculation.

Eg, along the lines of: (135 * 134 * 133 * ... * 27) / (27 * 26 * ... * 1)

But am totally stumped on the best approach to fulfil the matching requirements.

Pseudo logic and/or sample code would be greatly appreciated!

EDIT: trying this example as requested. Hopefully it clears things up. Am going to use numbers since it wouldn't be practical to try and upload 135 image symbols.

So let's say our 135 symbols are the numbers 1-135 inclusive. Of those 135 numbers, a subset of 108 is chosen. For simplicity, let's use the numbers 1-108.

Pick 18 random numbers from the subset 1-108: let's use 1-18 inclusive in place of symbols.

We need to come up with the minimum number of groups of 27 symbols (numbers in this example) so that at least one group of 27 (from amongst all our groups of 27), will have at least 12 of the 18 random numbers (symbols).

That is, one group will possibly look like: 1,2,3,5,6,7,77,9,10,13,15,30,40,50,60,70,56,43,100,4,103,99,66,8,78,44,55 as it matches 12 of the 18 random symbols (numbers).

Note that the 18 random symbols are chosen after the groups of 27 are chosen. There can be as many groups of 27 as needed.

Free Coder 24
  • 933
  • 9
  • 12
  • I'm having a hard time following the problem statement. Can you simplify the problem (perhaps by reducing the number of symbols) and post an example of the groups you're trying to generate? – BJ Myers Mar 16 '15 at 01:50
  • Updated with an example. Hopefully this helps? Had to use numbers in place of symbols as it's impractical to upload a dozen different graphical elements. – Free Coder 24 Mar 16 '15 at 02:17
  • Are the groups of 27 symbols chosen randomly or do you have control over it? If randomly, then there is no way to guarantee that one group will have at least 12 of the 18 random symbols -- you can only make a *probabilistic* guarantee (e.g., be 99% sure that one group will have ...). If you have control over the groups, then you can just choose 12 of the 18 symbols and then 15 more arbitrary symbols. So, I think your problem is not well defined -- more clarification would help. – LarrySnyder610 Mar 17 '15 at 02:38
  • We can choose the 27 symbols in the groups. However, as my example states, the groups are chosen from a subset of 108 symbols. After the groups are chosen, 18 random symbols are chosen. So there should be a way to find the minimum number of groups of 27 needed to make sure that at least 1 of them has at least 12 of the 18 random symbols chosen because there's only a finite set of random symbol combinations that can be chosen. – Free Coder 24 Mar 17 '15 at 09:21
  • Oh, I see. You tagged this as integer-programming. Are you willing to solve an IP in your code using an off-the-shelf IP solver? Or do you need an algorithm? – LarrySnyder610 Mar 18 '15 at 01:17
  • Tagged as integer programming because we may want to adjust the numbers (all ints). Would prefer an algorithm of sorts because we may have to use the code elsewhere with slight changes to suit our gaming challenges. – Free Coder 24 Mar 18 '15 at 02:45

0 Answers0