A 3-Day Moving Average
Halcyon Bank's research desk draws a smoothed line over a jumpy price series so that the trend shows through the daily noise. The smoothing is a plain three-day average: each point on the line is the ordinary average of three consecutive closes, all three counting equally. Points where three closes are not available are simply not drawn — the desk refuses to plot an average of two days beside an average of three, because the line's ends would then be noisier than its middle, which is the opposite of the point.
Task: Print the smoothed line.
Input
The first line holds a single integer n, the number of closing prices; n is at least 3. Each of the next n lines holds one closing price, in date order, which may carry decimals.
Output
One line holding n - 2 values, in date order, separated by single spaces, each with two digits after the decimal point. The first value covers the first three closes, the second covers closes two to four, and so on.
Example:
Input:
5
10
20
30
40
50
Output:
20.00 30.00 40.00
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