Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #58179
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Rosetta: Averages/Pythagorean means |
| Date | 2017-04-26 11:17 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <odpvku$1gvv$1@gioia.aioe.org> (permalink) |
> 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
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Rosetta: Averages/Pythagorean means "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-26 11:17 +0000
csiph-web