請問這題誰有其他意見
爬了很多資料很多網站
都還是沒有找到類似的
請求各位幫忙處理
(Programming)
A Gray code is an encoding of numbers so that two contiguous numbers have a single digit differing by 1. The term Gray code is often used to refer to a ”reflected” code, or more specifically still, the binary reflected Gray code. For example, one-bit Gray code is G1 = (0, 1) and two-bit Gray code is G2 = (00, 01, 11, 10). Three-bit Gray code is as follows:
Dec Gray
0 000
1 001
2 011
3 010
4 110
5 111
6 101
7 100
This exercise asks you to list the n-bit Gray code using a stack. Your Python program should read a value n (the number of bits for the Gray code) and use a stack to help you to generate the n-bit Gray codes as well as list them in order.