Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reversh polish calculator behaviour

 
Jack Higgs
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jack Higgs
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic