change algorithm for puzzle