• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reversh polish calculator behaviour

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic