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

BQN, 2323 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!Try it at BQN online!

Explanation

@+·×⊸/∘⥊∘⍉∘>(⌈´≠¨)↑¨-⟜@
                     -⟜@  Subtract null byte, converting strings to lists of ints↕∘≠¨⍋⊸⊏○∾⊢
             ¨   ≠¨      For each string Lengthin ofthe eachargument list of codepoints:
              ⌈´           Maximum ofTake theits lengthslength
   ↕∘          (   and )↑make a range from 0 to that Takenumber (^ that manyexclusive) elements, right-padding with 0s
                    ¨      fromWith eachthat list of codepoints
       lists of indices as ∘>the left argument
            Mergeand the original list of lists into a 2D array, and
       of strings ∘⍉as the right argument:
        ○∾     TransposeFlatten it,both andlists
      ∘⥊            ⊸⊏       Reshape itIndex into athe flatflattened list,string andusing
  ·×⊸/                     Keep only the numbersgrade-up thatof arethe greaterflattened thanlist zero,of andindices
@+

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: Add null byte,1 converting1 them3 back4 to5 characters9

The conversion from chars to ints and backThis operation is necessary, because Take pads with spaces rather than null bytes when given auseful for sorting one list according to the values of charsanother list, as seen in the above solution.

BQN, 23 bytes

@+·×⊸/∘⥊∘⍉∘>(⌈´≠¨)↑¨-⟜@

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

Explanation

@+·×⊸/∘⥊∘⍉∘>(⌈´≠¨)↑¨-⟜@
                     -⟜@  Subtract null byte, converting strings to lists of ints
                ≠¨         Length of each list of codepoints
              ⌈´           Maximum of the lengths
             (    )↑       Take (^ that many) elements, right-padding with 0s
                    ¨      from each list of codepoints
           ∘>              Merge the list of lists into a 2D array, and
         ∘⍉                Transpose it, and
      ∘⥊                   Reshape it into a flat list, and
  ·×⊸/                     Keep only the numbers that are greater than zero, and
@+                         Add null byte, converting them back to characters

The conversion from chars to ints and back is necessary, because Take pads with spaces rather than null bytes when given a list of chars.

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.

Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

BQN, 23 bytes

@+·×⊸/∘⥊∘⍉∘>(⌈´≠¨)↑¨-⟜@

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

Explanation

@+·×⊸/∘⥊∘⍉∘>(⌈´≠¨)↑¨-⟜@
                     -⟜@  Subtract null byte, converting strings to lists of ints
                ≠¨         Length of each list of codepoints
              ⌈´           Maximum of the lengths
             (    )↑       Take (^ that many) elements, right-padding with 0s
                    ¨      from each list of codepoints
           ∘>              Merge the list of lists into a 2D array, and
         ∘⍉                Transpose it, and
      ∘⥊                   Reshape it into a flat list, and
  ·×⊸/                     Keep only the numbers that are greater than zero, and
@+                         Add null byte, converting them back to characters

The conversion from chars to ints and back is necessary, because Take pads with spaces rather than null bytes when given a list of chars.