The solution is straightforward. The only tricky part is in computing the "distance" between consecutive characters in the aphorism. Compute the forward distance and the reverse distance and take the minimum.