Skip to main content
-3 bytes
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

05AB1E, 15 15 12 bytes

gI¨„+×.ΛDg;IθsǝgI¨„+×Λ1Iθ8Λ

Try it online.Try it online.

g                # Push the length of the (implicit) input-string
 I               # Push the input-string again
  ¨              # Remove its last character
   „+×           # Push string "+×"
      .Λ         # Use the modifiable Canvas builtin with these three arguments
        D        # Create a copy(after ofwhich the resulting string
result is output immediately as result)
    g   1    # Pop and push# itsPush length1
          ;   # Push the #last Halvecharacter it
of the input
          8   # Push the input, and only leave its last character8
             s Λ  # Swap soUse the length/2 isCanvas atbuiltin thewith topthese ofthree thearguments stackagain,
              ǝ  # Insert the character at thatwriting (floored)on indextop intoof the Canvas-string
 previous Canvas result
              # (after which the result is output implicitlyimmediately as result)

After which we replace the middle a with the last character of the input-string with Dg;Iθsǝ1Iθ8Λ, where Λ is another call of the Canvas builtin with the options: 1 for the length; is the last character of the input; and 8 to reset the direction-option back to the start (although in this case, the 8 could also be any of the eight directions 0-7 for the same result, since it already ended at the center anyway).

05AB1E, 15 bytes

gI¨„+×.ΛDg;Iθsǝ

Try it online.

g                # Push the length of the (implicit) input-string
 I               # Push the input-string again
  ¨              # Remove its last character
   „+×           # Push string "+×"
      .Λ         # Use the modifiable Canvas builtin with these three arguments
        D        # Create a copy of the resulting string
         g       # Pop and push its length
          ;      # Halve it
               # Push the input, and only leave its last character
             s   # Swap so the length/2 is at the top of the stack
              ǝ  # Insert the character at that (floored) index into the Canvas-string
                 # (after which the result is output implicitly)

After which we replace the middle a with the last character of the input-string with Dg;Iθsǝ.

05AB1E, 15 12 bytes

gI¨„+×Λ1Iθ8Λ

Try it online.

g             # Push the length of the (implicit) input-string
 I            # Push the input-string again
  ¨           # Remove its last character
   „+×        # Push string "+×"
      Λ       # Use the Canvas builtin with these three arguments
              # (after which the result is output immediately as result)
       1      # Push 1
            # Push the last character of the input
          8   # Push 8
           Λ  # Use the Canvas builtin with these three arguments again,
              # writing on top of the previous Canvas result
              # (after which the result is output immediately as result)

After which we replace the middle a with the last character of the input-string with 1Iθ8Λ, where Λ is another call of the Canvas builtin with the options: 1 for the length; is the last character of the input; and 8 to reset the direction-option back to the start (although in this case, the 8 could also be any of the eight directions 0-7 for the same result, since it already ended at the center anyway).

Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

05AB1E, 15 bytes

gI¨„+×.ΛDg;Iθsǝ

Try it online.

Explanation:

g                # Push the length of the (implicit) input-string
 I               # Push the input-string again
  ¨              # Remove its last character
   „+×           # Push string "+×"
      .Λ         # Use the modifiable Canvas builtin with these three arguments
        D        # Create a copy of the resulting string
         g       # Pop and push its length
          ;      # Halve it
           Iθ    # Push the input, and only leave its last character
             s   # Swap so the length/2 is at the top of the stack
              ǝ  # Insert the character at that (floored) index into the Canvas-string
                 # (after which the result is output implicitly)

The Canvas Builtin uses three arguments to draw a shape:

  • Character/string to draw: the input minus its last character in this case
  • Length of the lines we'll draw: the length of the input in this case
  • The direction to draw in: the "+×", which translates to directions [0,4,4,0,2,6,6,2,1,5,5,1,3,7,7,3], where each digit represents a certain direction:
7   0   1
  ↖ ↑ ↗
6 ← X → 2
  ↙ ↓ ↘
5   4   3

So the /[0,4,4,0,2,6,6,2,1,5,5,1,3,7,7,3] in this case translates to the directions \$[↑,↓,↓,↑,→,←,←,→,↗,↙,↙,↗,↘,↖,↖,↘]\$.

Here a step-by-step explanation of how it draws for example input abcd with these steps (with the other two Canvas arguments being 4 and "abc"):

Step 1: Draw 4 characters ("abca") in direction 0↑:

a
c
b
a

Step 2: Draw 4-1 characters ("bca") in direction 4↓:

a
b
c
a

Step 3: Draw 4-1 characters ("bca") in direction 4↓:

a
b
c
a
b
c
a

Step 4: Draw 4-1 characters ("bca") in direction 0↑:

a
b
c
a
c
b
a

Step 5: Draw 4-1 characters ("bca") in direction 2→:

a
b
c
abca
c
b
a

Etc., resulting in:

a  a  a
 b b b 
  ccc  
abcacba
  ccc  
 b b b 
a  a  a

After which we replace the middle a with the last character of the input-string with Dg;Iθsǝ.