. ( .)
char* fc = NULL;
int fclen = 0;
void appendtofc(const char* str)
{
if (!str)
return;
int len = strlen(str);
fc = realloc(fc, fclen + len + 1);
if (!fc)
;
strcpy(fc + fclen, str);
fclen += len;
}
const char* match3(const char** arr, int n, char c1, char c2, char c3)
{
for (int i = 0; i < n; i++)
{
int needc = 7;
for (const char* p = arr[i]; *p; p++)
{
if (*p == c1)
needc &= ~1;
else if (*p == c2)
needc &= ~2;
else if (*p == c3)
needc &= ~4;
if (!needc)
return arr[i];
}
}
return NULL;
}
const char* match2plus4n(const char** arr, int n, char c1, char c2)
{
for (int i = 0; i < n; i++)
{
int needc = 3, needn = 4;
for (const char* p = arr[i]; *p; p++)
{
if (*p == c1)
needc &= ~1;
else if (*p == c2)
needc &= ~2;
if (*p == 'n')
needn--;
if (!needc && !needn)
return arr[i];
}
}
return NULL;
}
void appendcubies(const char** cubies, int ncubies)
{
appendtofc(match3(cubies, ncubies, 'y', 'b', 'o'));
appendtofc(match2plus4n(cubies, ncubies, 'y', 'o'));
appendtofc(match3(cubies, ncubies, 'y', 'o', 'g'));
appendtofc(match2plus4n(cubies, ncubies, 'y', 'b'));
appendtofc(match2plus4n(cubies, ncubies, 'y', 'g'));
appendtofc(match3(cubies, ncubies, 'y', 'b', 'r' ));
appendtofc(match2plus4n(cubies, ncubies, 'y', 'r'));
appendtofc(match3(cubies, ncubies, 'y', 'r' , 'g' ));
appendtofc(match2plus4n(cubies, ncubies, 'o', 'b'));
appendtofc(match2plus4n(cubies, ncubies, 'o', 'g'));
appendtofc(match2plus4n(cubies, ncubies, 'b', 'r'));
appendtofc(match2plus4n(cubies, ncubies, 'g', 'r'));
appendtofc(match3(cubies, ncubies, 'w', 'b' , 'o' ));
appendtofc(match2plus4n(cubies, ncubies, 'w', 'o'));
appendtofc(match3(cubies, ncubies, 'w', 'o' , 'g' ));
appendtofc(match2plus4n(cubies, ncubies, 'w', 'b'));
appendtofc(match2plus4n(cubies, ncubies, 'w', 'g'));
appendtofc(match3(cubies, ncubies, 'w', 'b' , 'r' ));
appendtofc(match2plus4n(cubies, ncubies, 'w', 'r'));
appendtofc(match3(cubies, ncubies, 'w', 'r' , 'g' ));
}