Negadecimal, also known as base -10, is a non-standard positional numeral system.
Take the number \$1337_{10}\$. In decimal, this has the value one thousand three hundred thirty seven, and can be expanded to:
$$1\cdot10^3+3\cdot10^2+3\cdot10^1+7\cdot10^0$$
$$(1000)+(300)+(30)+(7)$$
In negadecimal, instead of \$10^n\$, each digit would be multiplied by \$(-10)^n\$:
$$1\cdot(-10)^3+3\cdot(-10)^2+3\cdot(-10)^1+7\cdot(-10)^0$$
$$(-1000)+(300)+(-30)+(7)$$
Thus, \$1337_{-10}\$ is \$-723_{10}\$ in decimal. (An interesting consequence of this is that negative signs are unnecessary in negadecimal; any integer can be represented as /[0-9]+/
.)
In this challenge, your score is the sum of the lengths of two programs or functions:
- One to convert a number in negadecimal to decimal
- One to convert a number in decimal to negadecimal
All inputs will be integers. You must be able to handle negative numbers. You can take input and output in any reasonable way. This is code golf, so the shortest answer in bytes per language wins.
Test cases
Negadecimal to decimal:
1337 -> -723
0 -> 0
30 -> -30
101 -> 101
12345 -> 8265
Decimal to negadecimal:
-723 -> 1337
0 -> 0
1 -> 1
21 -> 181
-300 -> 1700
1000 -> 19000
-38493 -> 179507