Averages/Pythagorean means: Difference between revisions

(New task and python solution.)
 
Line 10:
 
Show that <math>A(x_1,\ldots,x_n) \geq G(x_1,\ldots,x_n) \geq H(x_1,\ldots,x_n)</math> for this set of positive numbers.
 
=={{header|Lua}}==
<lang lua>function fsum(f, a, ...) return a and f(a) + fsum(f, ...) or 0 end
function pymean(t, f, finv) return finv(fsum(f, unpack(t)) / #t) end
nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
 
--arithmetic
print(pymean(nums, function(n) return n end, function(n) return n end))
--geometric
print(pymean(nums, math.log, math.exp))
--harmonic
print(pymean(nums, function(n) return 1/n end, function(n) return 1/n end))</lang>
 
=={{header|Python}}==
Anonymous user