I would try to solve your problem in a two-step approach. Since you only have 15 bitstrings, it should be sufficient to compare all pairs of bitstrings (105 comparisons á 16 QWORDS should be doable)
For now, I'll also consider patterns of length 1 valid, we'll see how to get rid of this later. Since you don't mention a programming language, I'll try to keep it general and use C syntax for bit operations. Let a
and b
be two bitstrings.
- Identify the possible patterns: The
i
th bit is part of a pattern if and only if a[i] == b[i]
. We can mark these bits efficiently by computing the bitwise xor (which corresponds to !=
) and negating: patterns = ~(a ^ b)
- Identify longest pattern: After the transformation above has been computed, common patterns between
a
and b
are consecutive 1s in pattern
. Finding such long patterns can e.g. be solved by repeated shifting and AND operations, see this question for details. If you expect really long sequences, I would try to use some dedicated instructions to find non-pattern bits, I'll extend the answer if necessary.
If this is really high-throughput code, you could try doing multiple comparisons simultaneously, i.e. using SIMD instructions, but that's a topic for another question.