Is your feature request related to a problem? Please describe.
Yes, I would like to add a binary algorithm, Gray Codes, in Python, Java, C and C++
Given a number N, generate bit patterns from 0 to 2^N-1 such that successive patterns differ by one bit.
Describe the solution you'd like
n-bit Gray Codes can be generated from list of (n-1)-bit Gray codes using following steps.
Let the list of (n-1)-bit Gray codes be L1. Create another list L2 which is reverse of L1.
Modify the list L1 by prefixing a ‘0’ in all codes of L1.
Modify the list L2 by prefixing a ‘1’ in all codes of L2.
Concatenate L1 and L2. The concatenated list is required list of n-bit Gray codes
Is your feature request related to a problem? Please describe. Yes, I would like to add a binary algorithm, Gray Codes, in Python, Java, C and C++
Given a number N, generate bit patterns from 0 to 2^N-1 such that successive patterns differ by one bit.
Describe the solution you'd like n-bit Gray Codes can be generated from list of (n-1)-bit Gray codes using following steps.
Let the list of (n-1)-bit Gray codes be L1. Create another list L2 which is reverse of L1. Modify the list L1 by prefixing a ‘0’ in all codes of L1. Modify the list L2 by prefixing a ‘1’ in all codes of L2. Concatenate L1 and L2. The concatenated list is required list of n-bit Gray codes
Additional context Input: N = 3 Output: 000 001 011 010 110 111 101 100