Averages/Pythagorean means: Difference between revisions

m (added whitespace before the TOC (table of contents), added other whitespace, indentations, and highlights to the task's preamble.)
Line 535:
 
=={{header|Elixir}}==
<lang elixir>defmodule Means do
defmodule Means do
def arithmetic(list) do
Enum.sum(list) / Enum.countlength(list)
end
def geometric(list) do
:math.pow(Enum.reduce(list, &(&1 * &/2)), 1 / Enum.countlength(list))
end
def harmonic(list) do
Line 548 ⟶ 547:
end
 
list = Enum.to_list(1..10)
IO.puts "Arithmetic mean: #{am = Means.arithmetic(1..10)}"
IO.puts "GeometricArithmetic mean: #{gmam = Means.geometricarithmetic(1..10list)}"
IO.puts "HarmonicGeometric mean: #{hmgm = Means.harmonicgeometric(1..10list)}"
IO.puts "(#{am}Harmonic >=mean: #{gm} >= #{hm}) is #{am >= gm and gm >= hmMeans.harmonic(list)}"
IO.puts "(#{am} >= #{gm} >= #{hm}) is #{am >= gm and gm >= hm}"</lang>
</lang>
{{out}}
<pre>
Anonymous user