0
\$\begingroup\$

This question already has an answer here:

Your mission, if you choose to accept it, is to create a stack that can do basic math operations.

Explanation: Your stack must be able to do basic arithmetic (+-*/) and must support normal base 10 numbers (0123456879); numbers will only be one character long.

Programming: Input from stdin will be loaded as a program. After the program has finished running, the contents of the stack will be printed with no spaces in between after the program runs.

Each character in the program does a different thing to the stack:

  • A number will push itself
  • A math operation will take the top two numbers on the stack and push the output.

Example I/O:

Input:

45+
Output:
9

Input:

235234
Output:
235234

Input:

566*+
Output:
41

Input:

243+-
Output:
-5

Input:

78+243+-
Output:
15-5

Division is shown as a integer if it has .0:

Input:

63/
Output:
2

Repeating Decimals are cut off at 2 places:

Input:

43/
Output:
1.33

Rules:

  • You stack must have a length of least 128.
  • Your stack must be double/float based.
  • No eval-ing!

Scoring: Your score is you byte count with a couple modifiers.

  • x0.9 if you include mod (%) and pow (^).
  • x0.8 if you parse numbers in base 36 (0-9A-Z).
  • x0.7 if you parse strings (each character of the string will be pushed as separate numbers)
    • "Hi" pushes 72 and 105, which will output 72105.
\$\endgroup\$

marked as duplicate by Digital Trauma code-golf Jul 28 '15 at 19:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 3
    \$\begingroup\$ Duplicate? \$\endgroup\$ – Martin Ender Jul 28 '15 at 19:41
  • \$\begingroup\$ Is there another stack question? Everything I found related to SE. @MartinBüttner \$\endgroup\$ – phase Jul 28 '15 at 19:42
  • \$\begingroup\$ @AlexA. Yes, the input is the program. \$\endgroup\$ – phase Jul 28 '15 at 19:42
  • \$\begingroup\$ @phase My comment was a link to another question which asks almost the same. The differences are the bonuses and that the other question doesn't read individual digits but entire (signed floating-point) numbers, which is why I didn't use my mod hammer to close it. \$\endgroup\$ – Martin Ender Jul 28 '15 at 19:43
  • \$\begingroup\$ Ouch, I forgot I had code-golf mod hammer. Well if @MartinBüttner thinks its a dup too, then I think this is the right thing to do here. \$\endgroup\$ – Digital Trauma Jul 28 '15 at 19:47