The Choppiness Score
Halcyon rates a share as choppy or calm before deciding what to charge for hedging it. Two shares can start and finish the month at identical prices having taken completely different journeys, and the desk's crude measure of the journey is the average size of a day-to-day move, with direction thrown away.
Task: Print the average size of a day-to-day move.
Input
The first line holds an integer n, always at least 2. Each of the next n lines holds one day's closing price.
Output
One line with exactly two digits after the decimal point. A run of n days contains n - 1 moves, and the average is taken over those moves rather than over the days. A share that never moved prints 0.00.
Example:
Input:
3
10
13
9
Output:
3.50
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in