Optimize n-puzzle solving