text, a pattern string pattern and a list of rules swaps. A rule swaps[i] = [from, to] means that a character from in the pattern may be replaced with to. Rules only work in one direction.
Replacements happen in the pattern, at any number of positions, but each position of the pattern can be replaced at most once (no chains like a → b → c at one position).
Return True if, after some replacements (possibly none), the pattern becomes a contiguous piece of text, and False otherwise. Letter case matters.text="unitr2d2ok", pattern="rodo", swaps=[["o", "2"], ["d", "x"]] → True
Replace both o characters of the pattern with 2 to get r2d2, which appears in the text.
text="abcde", pattern="xcd", swaps=[["b", "x"]] → False
The rule lets b become x, not the other way round, so the x in the pattern stays x, and no such piece exists in the text.
text="Q7Q7", pattern="q7", swaps=[["q", "Q"]] → True
text="unitr2d2ok", pattern="rodo", swaps=[["o", "2"], ["d", "x"]]
True
Run checks the first 3 tests in your browser. Submit checks all 76 tests on the server, hidden ones included.