Amended n-puzzle cost function to count distance from goal for each element.