I have written a bit of code to brute force generate these codes. However, it starts to struggle at n = 5 (I'm assuming this is because of the complexity, but it may well be because there isactual code in a bugprev. revision of this question).
#include <stdio.h>
#include <stdlib.h>
struct mjc_ll {
const unsigned long int val;
const struct mjc_ll* next;
};
// prints integer val in binary
void mjc_print_bin(const unsigned long int val, const unsigned char sf)
{
if (sf != 0) {
unsigned long int s = (1 << (sf - 1));
while (s != 0) {
printf("%c", ((val & s) != 0) ? '1' : '0');
s >>= 1;
}
}
printf("\n");
}
unsigned long int mjc_power(const unsigned long intFUNCTION base,gen
const unsigned long int exponent)
{
IF height returnof (exponentstack == 0) ? 1 : (base * mjc_power(base, exponent - 1));
}
// returns 1 if transition found in ll, 0 otherwise
int mjc_search_ll(const struct mjc_ll* const ll, const unsigned long int val,
const unsigned long int prev2^bit_width)
{
if (ll->next ==* 0bit_width) {
// reached end of list
returnPRINT 0;ZERO_PATTERN
} else if ((val == ll->val) && (prev == ll->next->val))RETURN {TRUE
IF //the change found
return 1;
}
return mjc_search_ll(ll->next, val, prev);
}
// printsbetween the solution and returns 1 if a solution found, otherwise returns 0
int mjc_next(const struct mjc_ll* const ll, const unsigned long int val,
const unsigned char bit_len, const unsigned long int count,
const unsigned long int limit)
{
if (count == limit) {
//value reachedat the end
mjc_print_bin(0, bit_len);
return 1;
} else if ((ll != 0) &&top (mjc_search_ll(ll,of val,stack ll->val)and !=value 0))does {
occur between other values //on foundthe duplicatestack
returnRETURN 0;FALSE
}
const struct mjc_ll newPUSH =value {val,to ll};stack
unsigned charWHILE ishift =< 0;bit_width
while(i < bit_len) {
IF RECURSE with value ifas (mjc_next(&new, valvalue ^XOR (1 << ishift), bit_len, count + 1, limit) == 1) {
mjc_print_bin(val,returns bit_len);TRUE
returnPRINT 1;value
}
RETURN ++i;TRUE
}
return 0;
}
voidshift mjc(const= unsignedshift char+ bit_len)
{1
(void)mjc_next(0, 0, bit_len, 0, mjc_power(2, bit_len) *RETURN bit_len);
}
FALSE
int main(int argc, char* argv[])
{
SET ifstack (argcto !=an 2)empty {list
printf("mjc takes 1 arg, the bit widthSET ofbit_width theto pattern\n");n
} else {
CALL gen with mjc(strtol(argv[1],value 0,as 0));
}
return 0;
}