hw6 changed pattern matching algorithm for ex3