Skip to main content
2 of 3
added 104 characters in body
LambdaBeta
  • 2.8k
  • 12
  • 20

C (gcc), 121 113 bytes

i;d;f(s)char**s;{char**_=s,x[255]={0},y[99]={0};for(d=0,i=0;*_;++_)d+=x[y[i++]=*(*_)++]++;d=d?*x?0:f(s):puts(y);}

Try it online!

Ungolfed

void enklactify(char *strings[]) {
    int quit = 0;
    while (!quit) {
        char **arg = strings;      // current row
        int exists[255] = {0};     // which characters exist in the column
        char output[99] = {0};     // will hold output string
        int index = 0;             // where to insert in output
        int duplicates = 0;        // have we found any duplicates?
        while (*arg != NULL) {
            char *word = *arg;     // current word
            char first = *word;    // first letter of current word
            if (exists[first])
                duplicates = 1;    // we found a duplicate
            exists[first] = 1;     // mark it as in our string
            output[index] = first; // add it to our output
            index++;
            (*arg)++;              // advances the current word to the next
                                   // character by reference (chops first char)
            arg++;                 // advance to next whole argument
        }

        if (!duplicates) {         // This is a valid solution
            puts(output);
            quit = 1;
        }

        if (exists[0]) {           // We hit the null terminator of one of the
                                   // input strings, so we failed
            quit = 1;
        }
    }
}

This abuses the ability to just add 1 to a string pointer in C to get the 'tail' of the string. The main byte savers are:

  • d+=x[y[i++]=*(*_)++]++ which appends the first character of the first string of _ to y, advances the first string of _ to remove its first character, adds the x entry at that character to d, and increments said x entry
  • q=d?*x:puts(y) which prints y if d is non-zero while setting q to a non-zero value, or sets q to non-zero if the first element of x is non-zero (if we were at the end of one of the strings then said element would be non-zero)

Edit: Shaved bytes by switching from while loop to recursive tail call and removing brackets from for loop.

LambdaBeta
  • 2.8k
  • 12
  • 20