0
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:
235234Output:
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.
- x
0.9
if you include mod (%
) and pow (^
). - x
0.8
if you parse numbers in base 36 (0-9A-Z
). - x
0.7
if you parse strings (each character of the string will be pushed as separate numbers)"Hi"
pushes72
and105
, which will output72105
.
3Duplicate? – Martin Ender – 2015-07-28T19:41:24.897
Is there another stack question? Everything I found related to SE. @MartinBüttner – phase – 2015-07-28T19:42:00.287
@AlexA. Yes, the input is the program. – phase – 2015-07-28T19:42:26.837
@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. – Martin Ender – 2015-07-28T19:43:32.287
Ouch, I forgot I had [tag:code-golf] mod hammer. Well if @MartinBüttner thinks its a dup too, then I think this is the right thing to do here. – Digital Trauma – 2015-07-28T19:47:04.360