FunctionRacerProblemsRace

Lowest Point

MediumSciPyPython

Return the x that makes (x - a)**2 + b * abs(x - c) as small as possible. Answers within 0.0001 of the right one are accepted.

Example 1

a 3.0
b 0.0
c 9.0
returns 3.0

With b = 0 only the square is left, and it is smallest at x = a.

Example 2

a 0.0
b 2.0
c 5.0
returns 1.0

The pull toward 5 moves the lowest point from 0 to 1.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More SciPy problems