Average an array until all numbers are (almost) equal Given an array of numbers, find out how many iterations of averaging* it takes for the average of every element to be no more than 1 higher or lower than the first element (absolute difference between the array's average and the first element is less than or equal to 1).
*Array averaging
To &quot;average&quot; a number in our array, we take the average of itself, the number behind it, and the number ahead of it. The last number of the array assumes the number ahead of it is the first number of the array (wrapping). Do this for all but the first number of the array, it needs to stay constant. The averages should all be applied at the same time (i.e. don't take the average of a number, put it back into the array, then average the next number).
Example:
ITERATION 0: [-1,4,3.5,7]
          1: [-1, 2.1666666666666665, 4.833333333333333, 3.1666666666666665]
          2: [-1, 2.0, 3.388888888888889, 2.3333333333333335]
          3: [-1, 1.462962962962963, 2.5740740740740744, 1.5740740740740742]
          4: [-1, 1.0123456790123457, 1.8703703703703705, 1.049382716049383]
          5: [-1, 0.6275720164609054, 1.3106995884773662, 0.6399176954732511]
          6: [-1, 0.31275720164609055, 0.8593964334705076, 0.3168724279835391]
          7: [-1, 0.057384545038866065, 0.4963420210333791, 0.058756287151348875]
abs(AVERAGE - FIRST_ELEMENT) = 0.903120713306 (IS LESS THAN 1)
OUTPUT: 7

Other I/O
INPUT &gt;&gt; OUTPUT
[-3, 9]  &gt;&gt;  2
[0, 0, 0, 0]  &gt;&gt;  0
[64, -66, -9, 78, -60]  &gt;&gt;  29
[9, 4, 5, 3, 3, 3, 10, 1, 1, 1]  &gt;&gt;  44
[-6, 5, -4, 3, -2, 1, -1, 2, -3, 4, -5, 6]  &gt;&gt;  70
[100000000, 2.11, 0.0, 16.88, 8.44, 6.33, 16.88, 100000000]  &gt;&gt;  348
[-8245, 6832, 9525, -3397, 5595, -9242, 1954, 6427, 36, -9647, -8887, 3062, -4424, -4806, -3803, 3608, -5115, -3725, -3308, -277]  &gt;&gt;  1038

Though not a part of the challenge; technically we are dealing with absolute values therefore complex numbers should also work. Your program does NOT need to handle complex numbers.:
[(20-1j), (5-4j), 7, (-0-100j)]  &gt;&gt;  15

Notes:

Other mathematical methods are accepted
You are to assume there are at least two elements in the array
This is code-golf so the shortest code in bytes wins
Perl 6,  83  82 bytes

-&gt;\a(\b,|c){(c,{[(b,|$_,b).rotor(3=&gt;-2).map: *.sum/3]}...{(b+.sum)/a~~b-1..b+1})-1}


Try it

-&gt;\a(\b,|c){(c,{[(b,|$_,b).rotor(3=&gt;-2).map: *.sum/3]}...{1&gt;abs (b+.sum)/a -b})-1}


Try it (also works for complex numbers

Expanded

-&gt;      # pointy block lambda

  \a    # the input array
  (
    \b, # the first value  
    |c  # all the rest of the values
  )

{
  (
    # generate a sequence

    c,                 # initialize the sequence starting with the second value

    {                  # bare block lambda with implicit parameter ｢$_｣

      [                # turn the result from a Seq into an array

        ( b, |$_, b )  # re-add the first element
                       # and add it to the end

        .rotor(3=&gt;-2)  # grab 3 at a time, backing up 2

        .map: *.sum/3  # return the average for each sub sequence

      ]
    }

    ...                # keep calling that to generate values until

    {
      1 &gt; abs ( b + .sum )/a - b     # they are almost equal
    }

  ) - 1 # count them and reduce by one (ignore initial value)
}