Part one is a brute force search and replace of every possibility.
Part two uses the analysis from askalski provided on the Day 19 solution megathread.
askalski