Averages/Pythagorean means: Difference between revisions

m
no edit summary
(Added solution for Action!)
mNo edit summary
Line 298:
Geometric mean: 4.52872
Harmonic mean: 3.41417
</pre>
 
=={{header|Amazing Hopper}}==
Think about "talk" programming...
<lang Amazing Hopper>
#include <hopper.h>
 
/* An example of definitions in pseudo-natural language, with synonimous.
These definitions can be inside a definition file (xxxx.h) */
#define getasinglelistof(_X_) {_X_},
#synon getasinglelistof getalistof
#define integerrandomnumbers _V1000_=-1,rand array(_V1000_),mulby(10),ceil,
#define randomnumbers _V1000_=-1,rand array(_V1000_)
#define rememberitin(_X_) _X_=0,cpy(_X_)
#synon rememberitin rememberthisnumbersin
#define rememberas(_X_) mov(_X_)
#define remember(_X_) {_X_}
//#synon remember with ---> this exist in HOPPER.H
#defn nowconsiderthis(_X_) #ATOM#CMPLX,print
#synon nowconsiderthis nowconsider,considerthis,consider,nowputtext,puttext,andprint
#define andprintwithanewline {"\n"}print
#synon andprintwithanewline printwithanewline
//#defn andprint(_X_) #ATOM#CMPLX,print
#define putanewline {"\n"}
#define withanewline "\n"
#define andprintit print
#synon andprintit printit,andprint
#define showit show
#define afterdoingit emptystack?,not,do{ {"I cannot continue due to retentive data "},throw(1001) }
#synon afterdoingit secondly,finally
#define then emptystack?do{ {"I cannot continue because data is missing "},throw(1000) }
/* why "#context" and not "#define"?
becose "#context" need a value in the stack for continue.
Internally, "domeanit" tranform to "gosub(calculatearithmeticmean)",
and "gosub" works only if it finds a data in the stack */
#context calculatethegeometricmean
#synon calculatethegeometricmean calculategeometricmean,getgeometricmean
#context calculatetheharmonicmean
#synon calculatetheharmonicmean calculateharmonicmean,getharmonicmean
#context calculatearitmethicmean
#synon calculatearitmethicmean calculatesinglemean,calculatemean,domeanit
 
main:
consider this ("Arithmetic Mean: ")
get a list of '10,10' integer random numbers; remember this numbers in 'list of numbers';
then, do mean it, and print with a new line.
after doing it, consider ("Geometric Mean: "), remember 'list of numbers', calculate the geometric mean;
then, put a new line, and print it.
secondly, now consider ("Harmonic Mean: "), with 'list of numbers', get harmonic mean, and print with a new line.
finally, put text ("Original Array:\n"), and print (list of numbers, with a new line)
exit(0)
.locals
calculate aritmethic mean:
stats(MEAN)
back
calculate the geometric mean:
stats(GEOMEAN)
back
calculatetheharmonicmean:
stats(HARMEAN)
back
</lang>
{{out}}
<pre>
Arithmetic Mean: 5.51
Geometric Mean: 4.47333
Harmonic Mean: 3.29515
Original Array:
4 3 10 6 10 1 1 10 4 1
7 4 5 8 9 7 3 8 1 10
5 5 2 5 8 9 1 5 10 10
6 4 3 5 9 2 6 9 2 9
10 9 3 4 6 2 1 8 10 1
7 5 5 9 9 3 7 9 7 7
9 2 10 1 7 9 3 2 7 4
1 6 2 4 10 7 5 1 5 5
1 2 9 5 10 7 7 6 6 4
3 4 5 2 4 1 10 6 3 7
</pre>
Notice:
<pre>
The line "stats(GEOMEAN)" is identical to:
stats(MULTIPLICATORY),POW BY({1}div by (100))
and...
#defn reciprocalof(_X_) {1},#ATOM#CMPLX,postfix,pow,postfix
then:
stats(MULTIPLICATORY),POW BY( reciprocal of (100) )
or...
#defn N-ROOTof(_DATA_,_N_) #ATOM#CMPLX,{1}div by(_N_),postfix,pow,postfix
#define Multiplicatoryof(_DATA_) {_DATA_}stats(MULTIPLICATORY)
then:
N-ROOT of ( Multiplicatory of (list of numbers), 100)
etc.
</pre>
 
543

edits