A confused calculator

In a stack s s , TIM is equivalent to s.push(s.pop() * s.pop()) and SUM is equivalent to s.push(s.pop() + s.pop()) . What will the following stack machine evaluate the operations as?

1
2
3
4
5
6
7
8
9
PUSH 1   
PUSH 2   
PUSH 3   
PUSH 4   
PUSH 5   
SUM   
TIM   
SUM   
TIM   

65 = ( 1 + 2 ) × 3 + 4 ) × 5 65 = \left( 1 + 2 ) \times 3 + 4 \right) \times 5 29 = ( ( 5 + 4 ) × 3 + 2 ) × 1 29 = \left( ( 5 + 4 ) \times 3 + 2 \right) \times 1 19 = 1 × 2 + 3 × 4 + 5 19 = 1 \times 2 + 3 \times 4 + 5 27 = 5 × 4 + 3 × 2 + 1 27 = 5 \times 4 + 3 \times 2 + 1

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Zuhaib Ali
Oct 1, 2015

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...