Gray code generation by subtractive method

Gray code generation by subtractive method

[Problem description] In the encoding of a set of numbers, if any two adjacent codes have only one binary digit difference, this encoding is called Gray Code (Gray Code). Only one digit is different, that is, "end to end", so it is also called cyclic code or reflection code. For n=3, Gray codes of 000, 001, 011, 010, 110, 111, 101, 100 can be obtained. When n=4, Gray codes can be produced on the basis of 3 by subtraction method. The generated method That is, fill in the highest bit from left to right with 0, and then fill in the highest bit from right to left with 1
[Input form] Input an integer n (0<n<10)
[Output form] Output n-bit Gray code
[Sample input 】2
[Sample output]
00
01
11
10
[Sample description]
[Scoring criteria] Please use the method of subtraction to realize the production of n-digit Gray codes. The spanning tree of 3-digit Gray codes is drawn in the title, and dfs technology can be used accomplish.

programming

n=int(

おすすめ

転載: blog.csdn.net/m0_68111267/article/details/130608772