How to resolve the algorithm Averages/Pythagorean means step by step in the Icon and Unicon programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Averages/Pythagorean means step by step in the Icon and Unicon 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 Icon and Unicon programming language
Source code in the icon programming language
link numbers # for a/g/h means
procedure main()
every put(x := [], 1 to 10)
writes("x := [ "); every writes(!x," "); write("]")
write("Arithmetic mean:", a := amean!x)
write("Geometric mean:",g := gmean!x)
write("Harmonic mean:", h := hmean!x)
write(" a >= g >= h is ", if a >= g >= h then "true" else "false")
end
procedure amean(L[]) #: arithmetic mean
local m
if *L = 0 then fail
m := 0.0
every m +:= !L
return m / *L
end
procedure gmean(L[]) #: geometric mean
local m
if *L = 0 then fail
m := 1.0
every m *:= !L
m := abs(m)
if m > 0.0 then
return exp (log(m) / *L)
else
fail
end
procedure hmean(L[]) #: harmonic mean
local m, r
if *L = 0 then fail
m := 0.0
every r := !L do {
if r = 0.0 then fail
else m +:= 1.0 / r
}
return *L / m
end
You may also check:How to resolve the algorithm Rosetta Code/Find unimplemented tasks step by step in the Raku programming language
You may also check:How to resolve the algorithm Halt and catch fire step by step in the Julia programming language
You may also check:How to resolve the algorithm Taxicab numbers step by step in the C# programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Phix programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the AutoHotkey programming language