Objective
Given two non-negative integers encoded in unbounded-length Gray code, add them and output the result, where the result is also encoded in Gray code.
Gray code
There are many equivalent formulations of Gray code, but here's an intuitive one.
The Gray code encodes each non-negative integer as an infinite bit-string. Starting from encoding zero, as the enumeration goes, the least significant bit keeps cycling through "0110"
. Each place of bit keeps cycling through what the previously significant bit cycles through, but doubled entry-wise. To summarize:
0th LSB: Cycles through "0110"
1st LSB: Cycles through "00111100"
2nd LSB: Cycles through "0000111111110000"
3rd LSB: Cycles through "00000000111111111111111100000000"
(And so on)
That gives the encodings of few non-negative integers as:
Integer = Gray code
("..." stands for infinitely many leading zeroes)
0 = "...00000"
1 = "...00001"
2 = "...00011"
3 = "...00010"
4 = "...00110"
5 = "...00111"
6 = "...00101"
7 = "...00100"
8 = "...01100"
9 = "...01101"
Note that, for each pair of integers differing by one, their Gray codes differ by only one bit.
I/O format
Flexible. Standard loopholes apply.
Examples
Here, inputs and outputs are Gray codes with their leading zeroes stripped off.
"" + "" = ""
"1" + "1" = "11"
"1" + "10" = "110"
"10" + "1" = "110"
"10" + "11" = "111"
"111" + "111" = "1111"