How to resolve the algorithm Averages/Arithmetic mean step by step in the Bracmat programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Arithmetic mean step by step in the Bracmat programming language

Table of Contents

Problem Statement

Write a program to find the mean (arithmetic average) of a numeric vector. In case of a zero-length input, since the mean of an empty set of numbers is ill-defined, the program may choose to behave in any way it deems appropriate, though if the programming language has an established convention for conveying math errors or undefined values, it's preferable to follow it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Averages/Arithmetic mean step by step in the Bracmat programming language

Source code in the bracmat programming language

(mean1=
  sum length n
.   0:?sum:?length
  &   whl
    ' ( !arg:%?n ?arg
      & 1+!length:?length
      & !n+!sum:?sum
      )
  & !sum*!length^-1
);

(mean2=
  sum length n
.     0:?sum:?length
    &   !arg
      :   ?
          ( #%@?n
          & 1+!length:?length
          & !n+!sum:?sum
          & ~
          )
          ?
  | !sum*!length^-1
);

( :?test
& 1000000:?Length
& whl'(!Length+-1:?Length:>0&!Length !test:?test)
& out$mean1$!test
& out$mean2$!test
)

  

You may also check:How to resolve the algorithm Playing cards step by step in the Java programming language
You may also check:How to resolve the algorithm Rename a file step by step in the TUSCRIPT programming language
You may also check:How to resolve the algorithm Euler's identity step by step in the C++ programming language
You may also check:How to resolve the algorithm Call a function step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Anonymous recursion step by step in the Ela programming language