Challenges

Define a mathematical expression in English

+2
−0

This challenge is currently under beta release. If given enough positivity, it will remain here and stand as a fully released challenge. Otherwise, it will be deleted and put back in the sandboxed post. Please fix the errors there instead.

Challenge

Write a program that translates a mathematical expression using English with the following specifications:

• The expression can only take in numbers, letters from the English alphabet, the equal sign, and the arithmetic operators. No, exponents aren't arithmetic.
• If the target character(s) is a/are number(s):
• The number range can only be from -999 up to 999.
• When in the tens place, use the dash (-) when there are spaced numberings. For example, 21 is twenty-one.
• When in the hundreds place, add and to the string if the tens and/or the ones place aren't empty. For example, 125 is one hundred and twenty-five.
• If the number is negative, use negative before the number. For example, -13 is negative thirteen.
• If the target character is a letter:
• The input should only take 1 letter.
• When put on the result, the letter must be capitalized.
• If the target character is a symbol:
• + is plus.
• - is minus.
• * is times.
• / is divided by.
• = is equals or is equal to.
• Parentheses shouldn't be inputted.
• Whitespaces are ignored.
• This is code-golf, so the shortest program for each language wins!

Test Cases

// Input
# Output

14
fourteen

1+2
one plus two

53 /3
fifty-three divided by three

6 +2* 7 =20
six plus two times seven equals twenty

8*8*8 * 8 * 8 -1
eight times eight times eight times eight times eight minus one

= 4
is equal to four

x + y = z
X plus Y equals Z

-5 +- 6
negative five plus negative six

Why does this post require moderator attention?
Why should this post be closed?

This community is part of the Codidact network. We have other communities too — take a look!