← Back to challenges

Coin Rotations

PythonHardloopsmathphysics

Instructions

A perfectly round coin travels along the given curve by rolling over it. Write a function that computes the number of rotations made by the coin during the trip from point start to point finish. The length of the trip can be approximated as the sum of piece-wise linear intervals.

Alternative Text

Examples

rotations(0, 10, 0.01, 1, lambda x: 2)  ➞  1.59

# Function Input:
# start = 0
# finish = 10
# spacial step along X-axis = 0.01
# coin radius = 1
# curve y(x) = 2 (flat line in this case)

Notes

  • The formula for the coin circumference is known since school.
  • Rounding of the result is not needed as it is done in the Tests.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.