Finite state machine application to the pattern recognition problem