# Calculate an Average in RPN (Reverse Polish Notation)

To calculate an average in reverse polish notation (RPN) is the following correct (assuming a-j are variables representing numbers):

a,b,+,c,+,d,+,e,+,f,+,g,+,h,+,i,+,j,+,10,/


If it is correct, are there other ways that this could be expressed in RPN?

-
It's much easier to read if you use space instead of comma. – TonyK Feb 6 '11 at 17:00

This is correct. There are more ways to compute this but I would call your solution fairly canonical. For example, you could have started like this:

a,b,c,+,+,...


or like this:

10,1/x,a,b,+,...,*


However, these are fairly obvious variants and you are probably looking for a completely different way.

-

It does work as correct, and if Zev is correct here (I think he is) there exist 4862 different ways of writing this average in RPN or PN, since there exist 4862 different ways of parenthesizing the part which just involves the addition symbols in infix notation.

-