Page 1 of 1

656 - Optimal Programs

Posted: Wed Jan 26, 2005 6:49 pm
by Jer
Can anyone explain the problem to me?

I don't know why the first test data is like that... :(

Code: Select all

4
1 2 3 4
0 -2 -6 -12

Program 1
DUP DUP MUL SUB
:wink: Thanks for your help

_____________________

Posted: Fri Jan 28, 2005 7:33 pm
by Observer
OK. When the input is 1,

Code: Select all

1          <- Initially

1 1 1      <- After two DUPs

1 1        <- Multiply the top 2 entries

0          <- Subtraction of the 2 entries
Or when the input is 2,

Code: Select all

2          <- Initially

2 2 2      <- After two DUPs

2 4        <- Multiply the top 2 entries

-2         <- Subtraction of the 2 entries
I'm sure you know what's going on for input = 3 or 4 :wink:

Hope it helps~