Pattern Recognition solution