Skip to main content
6 of 6
deleted 426 characters in body
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384

05AB1E, 18 17 8 bytes

2FDªI怨

-9 bytes by porting @JonathanAllan's Jelly answer, so make sure to upvote him as well!

Try it online or verify all test cases.

Previous 17 bytes answer:

Dª€gà©nи®ô¹ì²ζø®∍

Try it online or verify all test cases.

Explanation:

2F                 # Loop 2 times:
  D                #  Duplicate the current matrix
                   #  (which will be the implicit input-matrix in the first iteration)
   ª               #  Append the matrix to itself
     ζ             #  Zip/transpose; swapping rows/columns,
    I              #  using the second input-character as filler
      ۬           #  And then remove the last item of each row
                   # (after the loop, the resulting matrix is output implicitly)

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)
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384