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

05AB1E, 18 1717 8 bytes

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

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

Try it online or verify all test casesverify all test cases.

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

Ъεε²]²ζø«²ζø¤∍Dª€gà©nи®ô¹ì²ζø®∍

Try it online or verify all test casesTry it online or see the incorrect result for an empty matrixverify all test cases.

D 2F                 # Duplicate the firstLoop (implicit)2 input-matrixtimes:
 ª D                # Append theDuplicate matrixthe tocurrent itselfmatrix
                   # Map over(which eachwill innerbe list:the implicit input-matrix in the first iteration)
   gª               #  PopAppend andthe pushmatrix itsto lengthitself
    à ζ             # Pop and pushZip/transpose; theswapping maximumrows/columns,
     I              # (we now haveusing the dimension of thesecond outputinput-square, whichcharacter isas eitherfiller
        ۬           #  equal to theAnd amountthen ofremove rowsthe orlast amountitem of columns, whichevereach ofrow
                   # (after the twoloop, the resulting matrix is largeroutput implicitly) 

D     ©             # Store this maximum inDuplicate variablethe `®`first (without poppingimplicit) input-matrix
 ª     n            # Square it
  Append the matrix to itself
 и           # Repeat the second (implicit) input that# amountMap ofover timeseach asinner list:
   g     ®ô         # Split# it intoPop partsand ofpush sizeits `®`length
     à     ¹ì       # Prepend the# firstPop input-matrixand atpush the frontmaximum
             ζ     # Zip/transpose; swapping rows/columns,
      # (we now have the dimension ²of the output-square, which is either
 # using the second input-character as filler
            #  øequal to the amount #of Androws thenor zip/transposeamount theof rows/columns, backwhichever of
               ®∍  # Shorten the# matrix to the first `®` amounttwo ofis rowslarger)
      ©             # (afterStore whichthis themaximum resultingin matrixvariable is`®` output(without implicitlypopping)
 
Ð      n            # Triplicate the first (implicit)Square input-matrixit
 ª      и           # AppendRepeat the matrix to itself
  ε             second (implicit) input #that Mapamount overof eachtimes inneras list:
   ε      ®ô         #  MapSplit overit eachinto itemparts of thatsize list:`®`
    ²       ¹ì       #   And simply replace it withPrepend the secondfirst input-character
  ]                #matrix Closeat the nested mapsfront
    ζ         ζ     # 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 poppingShorten the matrix itself)
           ∍       # Shortento the matrix tofirst an`®` amount of rows equal to this row-length
                   # (after which the resulting matrix is output implicitly)

05AB1E, 18 17 bytes

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

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 an empty matrix.

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)

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.

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)
added 14 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
added 1578 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Dª€gà©nи®ô¹ì²ζø®∍Ъεε²]²ζø«²ζø¤∍

Try it onlineTry 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)
Dª€gà©nи®ô¹ì²ζø®∍

Try it online or verify all test cases.

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)
Ъεε²]²ζø«²ζø¤∍

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)
deleted 98 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading
added 1298 characters in body
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading
Source Link
Kevin Cruijssen
  • 131.5k
  • 13
  • 144
  • 384
Loading