Write a program that converts a mathematical expression to words, evaluates the expression, and prints how the equation would be spoken aloud.
- The input must only contain numbers and the symbols
/. There cannot be any whitespace in the input.
- The input does not say what the expression is equal to.
- While order of operations must be followed in determining the numerical answer in the expression, it is not necessary to indicate this in the output (for this reason, the input cannot contain parentheses).
- Numbers must be printed in capital letters. Operations must be printed in lower case.
- Numbers must be printed in the order that they appear in the input. Then the word
equalsmust be printed, then the answer.
- Numbers in the output can be negative. The word negative is written in capital letters.
- Operations and numbers must be separated by a space. There cannot be any space after the last letter is printed.
+in the input gets converted to
plusin the output.
-in the input gets converted to
minusin the output.
*in the input gets converted to
timesin the output.
/in the input gets converted to
divided byin the output.
- Division by 0 is not allowed.
- When division results in a decimal, the number should be rounded to three decimal places and read
X POINT X X Xwhere the
Xs are replaced by numbers.
- Negative numbers should have `NEGATIVE in front of them.
- For simplicity, all numbers must have absolute value less than 1000.
ONE plus TWO equals THREE
TWO minus THREE equals NEGATIVE ONE
SIX times TWO minus FOUR divided by ONE equals EIGHT
ONE plus ONE minus ONE times ONE divided by ONE equals ONE
TWO divided by THREE equals ZERO POINT SIX SIX SEVEN
FOUR HUNDRED THIRTEEN minus SIX HUNDRED TWENTY-ONE equals NEGATIVE TWO HUNDRED EIGHT
This is code golf, fellas. Standard CG rules apply. Shortest code in bytes wins.