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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Averages/Arithmetic mean step by step in the Common Lisp 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 Common Lisp programming language

Source code in the common programming language

(defun mean (&rest sequence)
  (when sequence
    (/ (reduce #'+ sequence) (length sequence))))


(defun mean (list)
  (when list
    (/ (loop for i in list sum i)
       (length list))))


  

You may also check:How to resolve the algorithm Jump anywhere step by step in the Lua programming language
You may also check:How to resolve the algorithm Sort an integer array step by step in the REBOL programming language
You may also check:How to resolve the algorithm A+B step by step in the Euler programming language
You may also check:How to resolve the algorithm Phrase reversals step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Esthetic numbers step by step in the Ruby programming language