aspose file tools*
The moose likes Java in General and the fly likes Reversh polish calculator behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reversh polish calculator behaviour" Watch "Reversh polish calculator behaviour" New topic
Author

Reversh polish calculator behaviour

Jack Higgs
Greenhorn

Joined: Jan 02, 2007
Posts: 5
Ok, it's a reverse polish calculator I'm analysing.

When I input:

1234
2345
3456
d
+
d
+
d
=

I get an output:

1234
2345
3456
d
1234
2345
3456
+
d
1234
5801
+
d
7035
=
7035

I'm unsure as to what the behaviour of d is. I need to be able to program what d does to do this question on a past exam paper (I'm revising). Any ideas how to represent what d does?

Cheers
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Are you comforatable with how RPN works? Do this sequence with pencil and paper; write out the stack after each operation and see if the meaning of "d" jumps out at you.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jack Higgs
Greenhorn

Joined: Jan 02, 2007
Posts: 5
I can see what it's doing (sort of!), I just don't know how to express it mathematically or as an algorithm.
Joel Jorgensen
Greenhorn

Joined: Oct 13, 2006
Posts: 22
When I am trying to figure out how to express something algorithmically, I often find it helps for me to write out what I think it does in language that I am most familiar with (sort of like pseudo-code) with gaps to be filled in later for the parts that I'm not sure about.

You say that you can sort of see what d is doing--what is it that you can see, and where are the gaps that you can't see yet?


Go is to the fountain.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
What happens if you repeat the "d" two or three times in a row? Does this have any effect on subsequent results? Or, what if you omit some (or all) of the "d" commands? I would suggest that what the "d" does is fairly simple, but much of the interesting action here occurs on "+" instead.

I'm also a bit mystified about why an RPN calculator would need a "=" at all. But that's mostly a side issue at the moment, I think.


"I'm not back." - Bill Harding, Twister
 
 
subject: Reversh polish calculator behaviour