Jump to content

Talk:Averages/Pythagorean means

From Rosetta Code

Why all three together?

I know we already have the Averages/Arithmetic mean task. We needed the other two, they all seemed very small and were related, so I created the one task for all three. It will also allow easy comparison of one languages computation of all three, for example Python has to delve into its standard library for the geometric mean. --Paddy3118 05:31, 20 February 2010 (UTC)

A >= G >= H missing?

It is like going back and fixing the question when you got the answer wrong ;-)
On reading the wp article it seemed like a useful little fact about the Pythagorean means, (apart from the nifty little semi-circular diagram), that I want to have in the RC task. I think it should be re-instated and the examples fixed. --Paddy3118 01:35, 22 February 2010 (UTC)

Note that the second element to the task was in the original task description; missed by some, but not others. I decided to move it to make it more prominent. --Paddy3118 01:59, 22 February 2010 (UTC)


Formulae hidden to most browsers by under-tested cosmetic edits at 23:05, 3 June 2016

Under-tested cosmetic edits made to the task page at 23:05, 3 June 2016, including the injection of spaces around expressions in <math> tags, made 3 out of the 4 task description formulae completely invisible to all browsers which display the graphic file version of formulae rather than processing the MathML (this is, in fact, the majority of browsers). The MediaWiki processor does not currently expect such spaces, and generates syntactically ill-formed HTML if they are introduced. Other aspects of these cosmetic edits may further compound the problem. Hout (talk) 10:31, 24 September 2016 (UTC)

Visibility of task description formulae restored Hout (talk) 21:33, 16 November 2016 (UTC)

Re: AWK solution: I do not understand how to execute this code

Re: AWK solution: I do not understand how to execute this code.

What input is to be given to the awk script to match the $1 variable?

What is the meaning of the comment: "value of 1st column"?

Retired Build Engineer (talk)

Hi, AWK parses the input lines into separate fields (which are the columns in the comment) - the default parsing would have spaces as separator. In an AWK program, $0 is the whole input line and the separate fields are $1, $2, ... up to $NF (NF is a builtin variable containing the number of fields on the line) so basically, the program is expecting numbers, one per line.
I ran it with the input:
1
 2
  3
and got:
Arithmethic mean:  2
Geometric mean  :  1.81712
Harmonic mean   :  1.63636
You can put the numbers in a file and name the file on the command-line. Assuming your awk is called gawk, the program is stored in means.awk and the numbers are in numbers.txt, the command line would be: gawk -f means.awk numbers.txt.
Alternatively, you can just run the program without an input file on the command line and type in the numbers - terminating your input with the eof-character.
--Tigerofdarkness (talk) 19:54, 14 November 2024 (UTC)

Thanks for the clarification.

I already knew about awk and command line arguments, but I did not grok the usage.

Thanks to your explanation I now am successfully executing with the following:

cat ./test_it.bash
#!/bin/bash

seq 1 10 | gawk -f averages_pythagorean_means.awk

Retired Build Engineer (talk)

Cookies help us deliver our services. By using our services, you agree to our use of cookies.