Disclaimer: This challenge is inspired by a coding error I once made.
Okay, time for a maths lesson. A normal mean average looks like this:
Work out the sum of all numbers in a list
then divide by the size of the list.
But what if we don't know all the numbers at the time we're working out the average? We need a way to work out the average which can be added to over time. For this reason, I present the algorithm for a Progressive MeanTM
The running total is the first number in the list
For each of the remaining numbers
Add the number to the running total
Divide the running total by two
So in effect we're averaging each number with the current average. (We could add to this later and get the same result)
BUT
This doesn't give the same result at all. It gives an average, but it differs from the standard methodology for finding the mean. Now the order of the list of numbers is significant.
Of course, being a curious type, I want to work out if the Progressive MeanTM tells us anything about the order of our list of numbers. So for this reason I want to compare Mean with Progressive MeanTM by means of a simple subtraction:
trend = Progressive MeanTM - Standard Mean
The Challenge
- Write a piece of code which accepts a list of numbers (in any format) which then calculates three pieces of information about it:
- Standard Mean
- Progressive MeanTM
- Trend (Progressive - standard)
- Work in any language you like.
- It's golf, attempt to do the challenge in as few bytes as you can.
- Avoid Standard Loopholes
- I want the output to be human-readable numbers.
- Please include a link to an online interpreter such as tio.run
Test Cases:
[1,2,3]
Normal Mean: 2.0
Progressive Mean: 2.25
Trend: 0.25
[3, 2, 1]
Normal Mean: 2.0
Progressive Mean: 1.75
Trend: -0.25
[10, 20, 30]
Normal Mean: 20.0
Progressive Mean: 22.5
Trend: 2.5
[300, 200, 100]
Normal Mean: 200.0
Progressive Mean: 175.0
Trend: -25.0
[10, 100, 10]
Normal Mean: 40.0
Progressive Mean: 32.5
Trend: -7.5
[4, 4, 9, 8, 1, 8, 6, 9, 1, 1]
Normal Mean: 5.1
Progressive Mean: 2.62890625
Trend: -2.4710937499999996
[1, 1, 1, 4, 4, 6, 8, 8, 9, 9]
Normal Mean: 5.1
Progressive Mean: 8.5390625
Trend: 3.4390625000000004
[9, 9, 8, 8, 6, 4, 4, 1, 1, 1]
Normal Mean: 5.1
Progressive Mean: 1.47265625
Trend: -3.6273437499999996
[a,b,c,d] -> [a,b,c,c,d,d,d,d]doesn't match the explanation of the code, it actually transforms[a,b,c,d]to[a,b,b,c,c,c,c,d,d,d,d,d,d,d,d,a](so two of each value in comparison to the example). The example confused me for a moment. But nice answer, +1 from me! I also like that it has all these different types of the letter 'A' in the code:āÅÅAÂÆª. xD \$\endgroup\$