Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Masem (Monsignor)
on May 21, 2001 at 22:04 UTC ( [id://82035]=note: print w/replies, xml ) Need Help??


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

With the hash that I gave, that solution is correct.

If the hash was, instead

%o = ( '-' => 1, '+' => 2, '*' => 3, '/' => 3 );
then the code would produce the second, correct solution. In other words, the code's correct, the givens are just wrong :-)


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Re: Re: (Golf) Reversing RPN Notation
by MeowChow (Vicar) on May 21, 2001 at 22:27 UTC
    A few problems with this:
    • qw(2 3 4 * /) : you forgot to set '/' to 4
    • qw(2 3 4 - -) : this is the biggie
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Ok, it's probably going to depend on how you decide to pop off the stack. Given "N1 N2 o" in RPN where N1 and N2 are the numbers and o the operation, the LTR should be "N1 o N2".

      Yes, '/' would need to be 4. And yes, the second one poses the problem if there's no indication of order being important on an operation ("a op b" not being equal to "b op a"). Chipmunk's got part of the problem with associtivity in his 171 char solution, but I might need to restate the problem to handle this concept; at the time, I was only aiming for a general solution assuming that order didn't matter.


      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
        Almost. The rule that "a op b" != "b op a" is not the same rule as "a op (b op c)" != "(a op b) op c". The former is commutativity, while the latter is associativity.
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 04:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found