String algorithm for fun! Detailed information can be found on my blogger MuTuX.
if __name__ == "__main__":
kmp('abcbabca','abcbabcabcbabcbabcbabcabcbabcbabca')
kmp('abab','ababcabababc')
========================================================
[-1, 0, 0, 0, 0, 1, 2, 3, 1]
0 7
15 22
26 33
[-1, 0, 0, 1, 2]
0 3
5 8
7 10
Have fun!