Question: In Prolog An n - bit Gray code is a sequence of n - bit strings where each binary string only differs from the previous
In Prolog
An nbit Gray code is a sequence of nbit strings where each binary string only differs from the previous by one bit. For example:
Gray
Gray
Gray
Figure out the rules to build the Gray code list and write a Prolog function called grayNX where N if the number of bits and X is the set of strings.
For example:
grayX should yield X
grayX should yield X
grayX should yield X
grayX should yield X
Hints:
You may find the following function useful. It prefixes a list of atoms with a single character.
prefixList
prefixListCHTCHResult:prefixListCTResultconcatCHCH
Example usage:
prefixListX should yield X
You may find the builtin reverse function useful too. For example:
reverseX should yield X
Here is the base case:
gray
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
