Skip to main content
2 of 2
Golfed a lot of bytes
DLosc
  • 39.2k
  • 5
  • 83
  • 141

BQN, 23 10 bytes

Massive savings by porting miles's J solution

↕∘≠¨⍋⊸⊏○∾⊢

Anonymous tacit function that takes a list of strings and returns a string. Try it at BQN online!

Explanation

↕∘≠¨⍋⊸⊏○∾⊢
   ¨         For each string in the argument list:
  ≠            Take its length
↕∘             and make a range from 0 to that number (exclusive)
             With that list of lists of indices as the left argument
          ⊢  and the original list of lists of strings as the right argument:
        ○∾     Flatten both lists
      ⊸⊏       Index into the flattened string using
    ⍋          the grade-up of the flattened list of indices

Grade up, for those unfamiliar with APL-related languages, is an operation that takes a list and returns a permutation of its indices, such that if the items in the list were reordered according to the order of the indices, the list would become sorted ascending. For example:

Indices:  0 1 2 3 4 5
List:     3 1 4 1 5 9

Grade up: 1 3 0 2 4 5
Sorted:   1 1 3 4 5 9

This operation is useful for sorting one list according to the values of another list, as seen in the above solution.

DLosc
  • 39.2k
  • 5
  • 83
  • 141