Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #58179 > unrolled thread

Rosetta: Averages/Pythagorean means

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-04-26 11:17 +0000
Last post2017-04-26 11:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  Rosetta: Averages/Pythagorean means "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-26 11:17 +0000

#58179 — Rosetta: Averages/Pythagorean means

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-04-26 11:17 +0000
SubjectRosetta: Averages/Pythagorean means
Message-ID<odpvku$1gvv$1@gioia.aioe.org>
> Compute all three of the Pythagorean means of the set of
> integers 1 through 10 (inclusive).
> 
> The most common of the three means, the arithmetic mean, is
> the sum of the list divided by its length
> 
> The geometric mean is the n th root of the product of the list
> 
> The harmonic mean is n divided by the sum of the reciprocal of
> each item in the list


r = 1..10
n = r.size.to_f
puts "Values relate correctly." if
  [(r.reduce :+) / n,
   (r.reduce :*)**(1/n),
   n / r.reduce(0){|s,i| s+1.0/i}].
  tap{|a| p a}.each_cons(2).all?{|a,b| a>=b}

 ===>
[5.5, 4.528728688116765, 3.414171521474055]
Values relate correctly.


In Forth?


-- 
That rifle on the wall of the labourer's cottage or working class flat is the
symbol of democracy.  It is our job to see that it stays there.
 --- George Orwell

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web