SetDirectory["C:\\drorbn\\AcademicPensieve\\2022-09\\KnottedGraphs"];
Once[<<KnotTheory`]

epd=EPD[Bottom[20,11,10,1],
Xp[9,12,10,11],Xm[1,12,2,13],Xm[8,19,9,20],Xm[13,2,14,3],Xm[18,7,19,8], Xp[14,5,15,4],Xp[5,16,6,15], Xp[16,7,17,6],
Top[3,4,17,18]]

front={1,12,9,20};
Length[LongestCommonSubsequence[List@@#,front]]&/@epd

SequenceReplace[{1,2,3,4,5,6,7,8,9}, {3,4,5}->Sequence[22,33]]

SequenceReplace[{},{}->7]

Complement[{5,4,3,2,1},{3,2}]

Draw[epd_EPD]:=Module[{kill=30,front={},left=List@@epd,do,com},
While[Length[left]>0∧--kill>0,
do=RandomChoice@MaximalBy[left,
v|->Length[LongestCommonSubsequence[List@@v,front]]+Switch[Head[v],
Bottom,+1,
Top,-1,
_,0
]
];
left=DeleteCases[left,do];
com=LongestCommonSubsequence[List@@do,front];
If[Length[com]>0,
front=SequenceReplace[front,com->Sequence@@Reverse[SequenceReplace[List@@do,com->Nothing]]],
front=Reverse[List@@do];
];
Echo@{do,front}
]
]

Draw[epd]