Refactored the triangle problem.