Write a program or function that takes a mathematical expression in Morse code as input, and returns the solution in Morse code.
Valid operations are plus: +
and minus: _
(underscore). You can assume you will only receive non-negative integer input, and that the result will be non-negative.
The expression will contain at least two terms, and maximum ten terms. There won't be two adjacent operators i.e. .----+_-....
, and there won't be parentheses.
Digits are seperated by single spaces. You can choose to have the operators separated from the numbers by a single space on each side (see examples).
The Morse equivalent for the digits 0-9 are:
0 -----
1 .----
2 ..---
3 ...--
4 ....-
5 .....
6 -....
7 --...
8 ---..
9 ----.
Examples:
Input
Output
.----+.---- (1+1=2) Optional input: .---- + .----
..---
-...._...-- (6-3=3) Optional input: -.... _ ...--
...--
..---_...--+..--- (2-3+2=1)
1
..---+...--_....-+---.._..... (2+3-4+8-5=4)
....-
.---- ..---_-....+...-- ...-- (12-6+33=39)
...-- ----.
----. -----+----.+..--- ----._..... .....+---..+-...._.----+----.+----._..--- ----- (90+9+29-55+8+6-1+9+9-20=84)
---.. ....-
Standard rules regarding I/O formats etc. apply. A few trailing spaces, and a single newline are accepted. You can't split the number over several lines. You can't use eval
or equivalent.
This is code golf, so the shortest code in bytes win.