Finding the smallest set of integers which contain at least one number that does not share digits with every integer in a second set

47 Views Asked by At

The following problem is in base 4.

n is the number of base 4 digits within each integer in Set A and Set B

For each number in a set of integers from 0 to 4n-1 (Set A), there must be at least one number in a second set of integers (Set B) with which it does not share any digits (in the same units column). For example, 121 and 023 share a digit but 003 and 321 do not. In other words, if there exists a number in Set A that shares at least one digit with every number in Set B, then Set B is invalid.

Given n digits, how can we find the smallest possible Set B?

When n < 4, Set B can be determined quite simply as seen below.

n=2 example

Set A: 00, 01, 02, 03, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33 (size: 16)
Set B: 00, 11, 22 (size: 3)

n=3 example

Set A: 000, 001, 002, 003, 010, ..., 333 (size: 64)
Set B: 000, 111, 222, 333 (size: 4)

When n >= 4, Set B can become harder to find. The following solutions were found via a genetic algorithm but I am unable to tell if these sets are the smallest possible. Furthermore, such an approach becomes prohibitively slow for significantly larger values of n.

n=4 example

Set A: 0000, 0001, 0002, 0003, 0010, ..., 3333 (size: 256)
Set B: 0011, 0022, 1100, 2200, 1111, 2222, 3333 (size: 7)

n=5 example

Set A: 00000, 00001, 00002, 00003, 00010, ..., 33333 (size: 1024)
Set B: 02213, 03112, 03203, 11330, 12301, 20121, 22100, 23212, 30020, 31031 (size: 10)