Math about trigonometric cosine functions
Ad Hoc on strings
Avoid unnecessary loop
KMP algorithm