How to resolve the algorithm Averages/Pythagorean means step by step in the Groovy programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Pythagorean means step by step in the Groovy programming language
Table of Contents
Problem Statement
Compute all three of the Pythagorean means of the set of integers 1 through 10 (inclusive). Show that
A (
x
1
, … ,
x
n
) ≥ G (
x
1
, … ,
x
n
) ≥ H (
x
1
, … ,
x
n
)
{\displaystyle A(x_{1},\ldots ,x_{n})\geq G(x_{1},\ldots ,x_{n})\geq H(x_{1},\ldots ,x_{n})}
for this set of positive integers.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Averages/Pythagorean means step by step in the Groovy programming language
Source code in the groovy programming language
def arithMean = { list ->
list == null \
? null \
: list.empty \
? 0 \
: list.sum() / list.size()
}
def geomMean = { list ->
list == null \
? null \
: list.empty \
? 1 \
: list.inject(1) { prod, item -> prod*item } ** (1 / list.size())
}
def harmMean = { list ->
list == null \
? null \
: list.empty \
? 0 \
: list.size() / list.collect { 1.0/it }.sum()
}
def list = 1..10
def A = arithMean(list)
def G = geomMean(list)
assert A >= G
def H = harmMean(list)
assert G >= H
println """
list: ${list}
A: ${A}
G: ${G}
H: ${H}
"""
You may also check:How to resolve the algorithm Monte Carlo methods step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Environment variables step by step in the FunL programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the Oforth programming language
You may also check:How to resolve the algorithm Euler's identity step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Terminal control/Inverse video step by step in the PicoLisp programming language