-2
\$\begingroup\$

Introduction

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.

Objective

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

[5]5
[1,-2]-0.5
[6,1,3]3.333333333

If your language can handle complex numbers:

[5,1+3i]3+1.5i

\$\endgroup\$

closed as unclear what you're asking by Mego, xnor, Blue, Rɪᴋᴇʀ, NoOneIsHere May 18 '16 at 15:17

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\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
1
\$\begingroup\$

Pyth, 13 bytes

l@*F^L2Qhe.ek

Try it online!

Uses exponential arithmetic to replace sum and division.

Uses enumerate to find number of elements.

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

Retina, 46 37 bytes

+`x;
;x
;x
;;:x
;
x
^(x+):(\1)*x*
$#2

Try it online!

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

\$\endgroup\$

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