65
12
Gaussian integers are complex numbers of the form a+bi
where a
and b
are both integers. In base -1+i, all Gaussian integers can be uniquely represented using the digits 0
and 1
, without the need for a symbol to denote sign.
For instance, 1100
in base -1+i represents the decimal number 2, since
1*(-1+i)^3 + 1*(-1+i)^2 + 0*(-1+i)^1 + 0*(-1+i)^0
= (2+2i) + (-2i) + 0 + 0
= 2
Input will be two Gaussian integers in base -1+i represented using the digits 01
. This can take one of the following forms:
- Two separate digit strings,
- Two decimal integers consisting of
01
representing the base -1+i numbers (e.g.1100
for 2 in base -1+i), - Two binary integers representing the base -1+i numbers (e.g. decimal
12
or0b1100
for 2 in base -1+i) - A single string separating two digit strings/binary integers by a single non-alphanumeric separator (e.g.
1100 1100
or12,12
for 2+2)
Output the sum of the two Gaussian integers, also in base -1+i and represented using the digits 01
(in one of the formats allowed as input, not necessarily the same choice). The output is allowed to contain a finite number of leading zeroes.
Your function or program must terminate within 2 seconds for inputs of at most 30 digits each.
Additional clarifications
- You may assume that the input contains no extraneous leading zeroes. For the special case of 0, you may choose either
0
or the empty string as the representation.
Test cases
0, 0 => 0 # 0 + 0 = 0
0, 1 => 1 # 0 + 1 = 1
1, 1 => 1100 # 1 + 1 = 2
1100, 1100 => 111010000 # 2 + 2 = 4
1101, 1101 => 111011100 # 3 + 3 = 6
110111001100, 1110011011100 => 0 # 42 + (-42) = 0
11, 111 => 0 # i + (-i) = 0
11, 110 => 11101 # i + (-1-i) = -1
10101, 11011 => 10010 # (-3-2i) + (-2+3i) = (-5+i)
1010100101, 111101 => 1110100000100 # (-19+2i) + (3-4i) = (-16-2i)
Longer test cases:
11011011010110101110010001001, 111100010100101001001010010101 => 0
111111111111111111111111111111, 111111111111111111111111111111 => 100100100100100100100100100100
101101110111011101110111011101, 101101110111011101110111011101 => 11101001010001000100010001000100011100
100100010101001101010110101010, 100010011101001011111110101000 => 110000110010101100001100111100010
No digit lists? – CalculatorFeline – 2016-03-23T14:48:23.817
@CatsAreFluffy No digit lists, sorry. – Sp3000 – 2016-03-23T15:09:37.067
@CatsAreFluffy: If you really want a list, you could just use an existing answer to repeatedly add 1. – Tim Pederick – 2016-03-23T15:11:44.500
98You can save one byte by changing
-1+i
toi-1
in the title. – mbomb007 – 2016-03-23T18:11:53.5931Now we need a conversion the other way around. :P – Rɪᴋᴇʀ – 2016-03-23T18:35:22.513
anybody who even attempts doing this in brainf*ck will get an upvote for all that math they probably did. – tox123 – 2016-03-25T22:18:11.400
3There are 1100 types of people in the world. Those who understand binary, those who don't, those who confuse it with ternary, those who confuse it with base 4, those who confuse it with base 5, those who confuse it with base -1+i, those who confuse it with base 6, those who confuse it with base 7, those who confuse it with base 8, those who confuse it with base 9... – wizzwizz4 – 2016-03-27T09:51:55.713
@wizzwizz4 ..., those who confuse it with base i. – user75200 – 2017-12-28T15:40:56.360