Algorithm to solve the mastermind game