Pretty ugly start on an implementation of the Z algorithm.