Fixed the puzzle generating algorithm