day 07
internet protocol version 7
approach
a regex finds the bracketed sections of each address; the text inside them goes into one list and the pieces in between into another. patterns are then looked for with a sliding window over each piece.
part 1 rejects an address if any bracketed section has a four-letter abba window, and otherwise accepts it if any outside piece has one. part 2 collects every three-letter aba window from the outside pieces into a set, then scans the bracketed sections for an aba whose swapped form bab is in that set.
the trick
for part 2, gather the outside abas into a set first, so each inside window is a single lookup of its mirror.
python
def supports_ssl(inside, outside):
abas = set()
for out in outside:
abas |= {w for w in windows(out, 3) if is_aba(w)}
for ins in inside:
for w in windows(ins, 3):
if is_aba(w) and aba_compliment(w) in abas:
return True
return False