Skip to main content
4 of 6
added 1578 characters in body
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

05AB1E, 18 17 bytes

Ъεε²]²ζø«²ζø¤∍

Try it online or verify all test cases.

Could have been 15 bytes if the input-matrix is guaranteed to be non-empty:

Ъεε²]²ζø«²ζø¤∍

Try it online or verify all test cases or see the incorrect result for empty matrices.

Explanation:

D                  # Duplicate the first (implicit) input-matrix
 ª                 # Append the matrix to itself
  €                # Map over each inner list:
   g               #  Pop and push its length
    à              # Pop and push the maximum
                   # (we now have the dimension of the output-square, which is either
                   #  equal to the amount of rows or amount of columns, whichever of
                   #  the two is larger)
     ©             # Store this maximum in variable `®` (without popping)
      n            # Square it
       и           # Repeat the second (implicit) input that amount of times as list
        ®ô         # Split it into parts of size `®`
          ¹ì       # Prepend the first input-matrix at the front
             ζ     # Zip/transpose; swapping rows/columns,
            ²      # using the second input-character as filler
              ø    # And then zip/transpose the rows/columns back
               ®∍  # Shorten the matrix to the first `®` amount of rows
                   # (after which the resulting matrix is output implicitly)

Ð                  # Triplicate the first (implicit) input-matrix
 ª                 # Append the matrix to itself
  ε                # Map over each inner list:
   ε               #  Map over each item of that list:
    ²              #   And simply replace it with the second input-character
  ]                # Close the nested maps
    ζ              # Zip/transpose; swapping rows/columns,
   ²               # using the second input-character as filler
     ø             # And then zip/transpose the rows/columns back
      «            # Merge this matrix to the input-matrix
       ²ζø         # Add fillers again in a similar matter
          ¤        # Push the final row (without popping the matrix itself)
           ∍       # Shorten the matrix to an amount of rows equal to this row-length
                   # (after which the resulting matrix is output implicitly)
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384