The arithmetic mean is defined as being equal to the sum of the numerical values of each and every observation divided by the total number of observations. Symbolically, if we have a data set containing the values a1,…,an. The arithmetic mean A is defined by the formula

A=\frac{1}{n}\sum_{i=1}^n a_i.


The challenge here is, given a non-empty list of observations, to calculate the arithmetic mean without any built-ins for mean, sum, division, or count. All other operations are allowed, e.g. median, product, multiplication, and sequence generation.

If your language cannot process lists without knowing the number of elements it has, you may use a counting built-in for such (looping, loading, etc.) purpose only, but not for the actual computation.

Test cases


If your language can handle complex numbers:


  • \$\begingroup\$ This is a cut-and-dry Do X without Y challenge. \$\endgroup\$ – Mego May 18 '16 at 7:24
  • 1
    \$\begingroup\$ Possible duplicate of Operations with Lists \$\endgroup\$ – Mego May 18 '16 at 7:25
  • \$\begingroup\$ @Mego How can it be a dup if the other one isn't a Do X without Y? \$\endgroup\$ – Adám May 18 '16 at 8:11
  • \$\begingroup\$ The core challenge is the same, and the "without Y" part doesn't significantly distinguish it. \$\endgroup\$ – Mego May 18 '16 at 8:12
  • \$\begingroup\$ @Mego No the core here isn't list operations. It is alternative ways to do things. \$\endgroup\$ – Adám May 18 '16 at 8:14

Pyth, 13 bytes


Try it online!

Uses exponential arithmetic to replace sum and division.

Uses enumerate to find number of elements.

  • \$\begingroup\$ Perfect, that's the type of substitutions I had in mid. \$\endgroup\$ – Adám May 18 '16 at 8:38

Retina, 46 37 bytes


Try it online!

It's quite a trouble not to use arithmetic...


Not the answer you're looking for? Browse other questions tagged or ask your own question.