7 kyu

Moving Average

Description:


Background

Moving average of a set of values and a window size is a series of local averages.

Example:

Values: [1, 2, 3, 4, 5]
Window size: 3

Moving average is calculated as:


 1, 2, 3, 4, 5
 |     |
 ^^^^^^^
 (1+2+3)/3 = 2
 
 
  1, 2, 3, 4, 5
     |     |
     ^^^^^^^
     (2+3+4)/3 = 3
 
 
  1, 2, 3, 4, 5
        |     |
        ^^^^^^^
        (3+4+5)/3 = 4
 
Here, the moving average would be [2, 3, 4]

Task

Given a list values of integers and an integer n representing size of the window, calculate and return the moving average.

When integer n is equal to zero or the size of values list is less than window's size, return None


Reference: Moving average

Algorithms
Logic
Mathematics
Lists

More By Author:

Check out these other kata created by bradley.mccoy

Stats:

CreatedFeb 25, 2019
PublishedFeb 25, 2019
Warriors Trained1501
Total Skips11
Total Code Submissions4367
Total Times Completed831
Python Completions831
Total Stars22
% of votes with a positive feedback rating92% of 193
Total "Very Satisfied" Votes168
Total "Somewhat Satisfied" Votes21
Total "Not Satisfied" Votes4
Total Rank Assessments33
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • bradley.mccoy Avatar
  • user9644768 Avatar
  • mauro-1 Avatar
Ad