brute force algorithm for pattern matching