From the Wikipedia article:
Location arithmetic (Latin arithmeticæ localis) is the additive (non-positional) binary numeral systems, which John Napier explored as a computation technique in his treatise Rabdology (1617), both symbolically and on a chessboard-like grid.
Location numerals is a way of writing numbers using letters of the alphabet.
Binary notation had not yet been standardized, so Napier used what he called location numerals to represent binary numbers. Napier's system uses sign-value notation to represent numbers; it uses successive letters from the English alphabet to represent successive powers of two: a = 2^0 = 1, b = 2^1 = 2, c = 2^2 = 4, d = 2^3 = 8, e = 2^4 = 16 and so on.
ab = 1+2 = 3 in base 10
aabb = 1+1+2+2 = 6 in base 10
aabb can be shortened to
bc by replacing any 2 instances of a letter by a higher one.
You just concatenate the two numbers and simplify.
39 in base 10
Just remove all digits appearing equally in both parts of the subtraction. Expanding (converting
aa) may be necessary
be = 18 in base 10
This is a bit harder.
Lets say we want to multiply
acd (13) by
def (56). First you arrange
a c d
Then you add
def after the first
a def c d
Now, c is 2 positions later in the alphabet than a, so we add 2 positions in the alphabet to
def to make
fgh. That is added to the second row.
a def c fgh d
Lastly, d is 1 position later in the alphabet than c, so we add 1 position in the alphabet to
fgh to make
ghi. That is added to the third row.
a def c fgh d ghi
Then you take the sum of the right:
Another example of multiplication
bc * de
b ef c
b ef c fg
Note that we wrote down
ef on the first line. That's because
bc starts with
b is the second letter in the alphabet, so we need to shift
de by 1 letter, so it becomes
This is not part of this challenge, because it can get very complex.
Your actual challenge
Your program or function must take input as a string that looks like this:
a + b
And you must output:
Of course, your program or function must support numbers of arbitrary length (up to the string or input limit of your language) with any of the operators
*. Some more examples:
ab + bd
d - ab
ab * cd
- The order of letters in the output doesn't matter, but you can always assume that the order of letters in numbers in the input will be ascending (a before z).
- You may take input with a trailing newline and output with a trailing newline.
- You may not take input as a list of
ab * bd.
- The english alphabet is used (
- Your output must be simplified (
aais not allowed,
- The input will be simplified (
- You may require a space before and the operator (
*), or you may require there to be none.
- There will only be one operator per input.
- You may assume that the output and the input will never go over 2^27-1 (
- This is code-golf, so the shortest answer in bytes wins!