Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Re: Re: (Golf) Reversing RPN Notation

by chipmunk (Parson)
on May 21, 2001 at 20:56 UTC ( #82014=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: (Golf) Reversing RPN Notation
in thread (Golf) Reversing RPN Notation

Ouch, that's a good point. Well, I don't think there's any way to solve that problem with the data that's provided. The operator hash would need to specify which operators are commutative and which aren't.

In fact, the problem requirements state:

Operations of the same priority can be considered to be commutative, and can be evaluated in any order.
[fixed spelling]

So, I solved the problem as stated, although the problem as stated doesn't quite reflect actual arithmetic.

Update: Oops, I'm confusing commutative (order doesn't matter) with associative (grouping doesn't matter). Subtraction is neither commutative nor associative, but the problem MeowChow pointed out involves associativity. The operator hash would need to specify which operators are associative. Either way, there's not enough information available for a perfect solution.


Comment on Re: Re: Re: (Golf) Reversing RPN Notation
Re: Re: Re: Re: (Golf) Reversing RPN Notation
by MeowChow (Vicar) on May 21, 2001 at 21:10 UTC
    The purpose of associativity is to resolve ambiguities between operators of equal precedence. Associativity isn't specified on a "yes/no" basis, but on left-to-right, or right-to-left basis. All trivial arithmetic operators excluding exponentiation are left-to-right.
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://82014]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2014-12-26 03:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (164 votes), past polls