g | x | w | all
Bytes Lang Time Link
216Tcl250707T170846Zsergiol
112Zsh230727T060854Zroblogic
014Thunno 2 N230722T045927ZThe Thon
011Vyxal C220707T214427ZnaffetS
014Canvas201106T110030ZRazetime
090Julia 1.0201105T171039ZMarcMush
01405AB1E201105T163957ZKevin Cr
015Japt R201105T153355ZShaggy
127JavaScript ES6170705T142729ZSaming
014Charcoal170705T133344ZErik the
163Haskell170705T213152ZMephy
124Python 3170705T153725ZChase
01705AB1E170705T125150ZErik the
131PHP170705T125033ZTitus
095Python 3170705T124044ZMr. Xcod
196Java OpenJDK 8170705T135550ZOlivier
141Mathematica170705T142526ZZaMoC
037APL Dyalog170705T123532ZAdá
018SOGL V0.12170705T120220Zdzaima
021Japt170705T115411ZETHprodu

Tcl, 216 bytes

proc P s {set n -[set m [expr [string le $s]-1]]
time {set x [join [split $s ""] [format %[set b [expr abs([incr n]-1)]]s ""]]
puts [format %[expr $m*($b-$m)]s ""][string ra [string rev $x] 0 end-1]$x} [expr 2*$m+1]}

Try it online!

Zsh, 117 113 109 112 bytes

b=`rev<<<$1`${1:1};j=$#1
for c ({$j..1} {2..$j}){printf %$[(j-1)*(j-c)]s
for x (${(s::)b})printf %-$c\s $x;echo}

Try it online!  109b invalid  113b  117b

b is the palindrome; j is the length of input string $1. Iterate c over the range {j..1..j}. For each c, print a prefixed number of spaces. For every character x in b, print x with c spaces between each.

Thunno 2 N, 14 bytes

ḣı$ṅṣj;ðƬrⱮṬrⱮ

Try it online!

I have absolutely no idea why this works, but it does.

Explanation

ḣı$ṅṣj;ðƬrⱮṬrⱮ  # Implicit input
ḣı    ;         # len(input) - 1 times:
  $  j          #   Join the input by...
   ṅṣ           #   ...loop index spaces
       ðƬ       # Transpose with filler space
         rⱮ     # Reverse and palindromise
           Ṭ    # Tranpose it
            rⱮ  # Reverse and palindromise
                # Implicit output, joined on newlines

I did quite a bit of experimenting, producing a lot of buggy outputs. Here's my favourite:

                                                                        0987654321234567890                                                                        
                                                               0 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 0                                                               
                                                      0  9  8  7  6  5  4  3  2  1  2  3  4  5  6  7  8  9  0                                                      
                                             0   9   8   7   6   5   4   3   2   1   2   3   4   5   6   7   8   9   0                                             
                                    0    9    8    7    6    5    4    3    2    1    2    3    4    5    6    7    8    9    0                                    
                           0     9     8     7     6     5     4     3     2     1     2     3     4     5     6     7     8     9     0                           
                  0      9      8      7      6      5      4      3      2      1      2      3      4      5      6      7      8      9      0                  
         0       9       8       7       6       5       4       3       2       1       2       3       4       5       6       7       8       9       0         
0        9        8        7        6        5        4        3        2        1        2        3        4        5        6        7        8        9        0
         0       9       8       7       6       5       4       3       2       1       2       3       4       5       6       7       8       9       0         
                  0      9      8      7      6      5      4      3      2      1      2      3      4      5      6      7      8      9      0                  
                           0     9     8     7     6     5     4     3     2     1     2     3     4     5     6     7     8     9     0                           
                                    0    9    8    7    6    5    4    3    2    1    2    3    4    5    6    7    8    9    0                                    
                                             0   9   8   7   6   5   4   3   2   1   2   3   4   5   6   7   8   9   0                                             
                                                      0  9  8  7  6  5  4  3  2  1  2  3  4  5  6  7  8  9  0                                                      
                                                               0 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 0                                                               
                                                                        0987654321234567890                                                                        

Vyxal C, 11 bytes

ṪẏṘ∞ƛ?Ṙ∞$Ij

Try it Online!

Explanation

ṪẏṘ∞ƛ?Ṙ∞$Ij
Ṫ           # Remove the last element (removing the first element would be fine too)
 ẏ          # Make a range [0, length)
  Ṙ         # Reverse
   ∞        # Palindromize, a + a[::-1][1:]
    ƛ       # Map, and for each:
     ?Ṙ     #  Push the input reversed
       ∞    #  Palindromize that (call this X)
        $   #  Swap so the current item is at the top
         I  #  Push that many spaces
          j #  Join the characters of X by that
            # C flag centers and joins on newlines

Canvas, 14 bytes

L╷rH ×⁸;*∔}↔↕┼

Try it here!

Explanation

L|rH ×⁸;*∔}↔↕┼
L              length of input
 |r            decrement, make range [0..n-1]
   H           create an empty art object, start a loop with i
     ×         repeat space i times
      ⁸;       swap with the input
        *      join input with i spaces
         ∔     add to the bottom of the previous iteration
          }    close the loop
           ↔↕  mirror horizontally and vertically
             ┼ quad palindromize with 1 character overlap

Julia 1.0, 100 90 bytes

s->(l=length(s)-2;[' '^(-~l*(l-j))*prod(s[abs(i)+1]*' '^j for i=~l:l+1) for j=abs.(-l:l)])

Try it online!

-10 bytes thanks to @KevinCruijssen

05AB1E, 14 bytes

¦ε\RðN×ýû}Rû.c

Input as a list of characters.

Try it online or verify all test cases.

14 bytes alternative:

ā¨RjJíðδÜ€ûû.c

Also takes a list of characters as input.

Try it online or verify all test cases.

Explanation:

¦              # Remove the first item of the (implicit) input-list
               # (could have removed the last as alternative as well)
 ε             # Map over each character:
  \            #  Discard the character
   R           #  Reverse the (implicit) input-list
     N         #  Push the 0-based map-index
    ð ×        #  Repeat a space character that many times as string
       ý       #  Join the reversed input-list with this spaces-string as delimiter
        û      #  Palindromize the entire string
 }R            # After the map: reverse the resulting list
   û           # Palindromize this entire list
    .c         # And centralize it, which also implicitly joins by newlines
               # (after which the result is output implicitly)

ā              # Push a list in the range [1, (implicit) input-length]
 ¨             # Remove the last item to make the range [1, input-length)
  R            # Reverse the list to (input-length, 1]
   j           # Pad each character in the (implicit) input-list with leading spaces so
               # the string lengths become equal to the current integer
    J          # Join each inner list of strings together to a single string
     í         # Reverse each string
       δ       # Map over each string:
      ð Ü      #  And remove all trailing spaces
         €û    # Palindromize each string
           û   # Palindromize the entire list
            .c # And centralize it, which also implicitly joins by newlines
               # (after which the result is output implicitly)

Japt -R, 15 bytes

ÊÆÔ¬qXç)êÃÔÅê û

Try it

ÊÆÔ¬qXç)êÃÔÅê û     :Implicit input of string
Ê                   :Length
 Æ                  :Map each X in the range [0,length)
  Ô                 :  Reverse U
   ¬                :  Split
    q               :  Join with
     Xç             :    X spaces
       )            :  End join
        ê           :  Palindromise
         Ã          :End map
          Ô         :Reverse
           Å        :Slice off first element
            ê       :Palindromise
              û     :Centre pad each element with spaces to the length of the longest
                    :Implicit output joined with newlines

JavaScript (ES6), 159 136 129 127 bytes

f=(i,x=1-(l=i.length-1),y=x<0?-x:x,[,...b]=i)=>l>x?''.padEnd(l*(l+~y))+[...b.reverse(),...i].join(''.padEnd(y))+`
`+f(i,x+1):''

Try it online! Explanation below

// This is a recursive function
// First, inputs and various variable initializations
// by using defaults
let func = (
  // Text input, will not be modified through recursion
  input,

  // Current line, for the first function call we start from -lines to +lines
  // It's roughly equivalent to lines*2 but this helps us computing the spacing
  // Also computing the total amount of lines
  currentLine = 1 - (totalLines = input.length - 1),

  // Getting the absolute value of the current line (like Math.floor)
  absCurrentLine = currentLine < 0 ? -currentLine : currentLine,

  // Getting the input without it's first letter, useful for the palidrome of the input
  [,...slicedInput] = input

// Base case, stopping the recursion if the current line
// is still below the total amount of lines
) => totalLines > currentLine

  // Leading spacing
  ? ''.padEnd(totalLines * (totalLines + ~absCurrentLine)) + 

  // Putting together the palindrome version and adding spaces between the chars
    [...slicedInput.reverse(), ...input].join(''.padEnd(absCurrentLine)) + `

  // Line return + recursion call
` + f(input, currentLine + 1)
  : ''

First entry to codegolf, I apologise in advance for any obvious mistakes.

Thanks to Justin Mariner for saving 23 bytes! Thanks to Craig Ayre for saving 11 bytes and for the bug report.

Charcoal, 14 bytes

E⁻Lθ¹⪫θ× ι‖O←↑

Try it online!

AST:

Program
├Print
│└E: Map
│ ├⁻: Difference
│ │├L: Length
│ ││└θ: Identifier θ
│ │└1: Number 1
│ └⪫: Join
│  ├θ: Identifier θ
│  └×: Product
│   ├' ': String ' '
│   └ι: Identifier ι
└‖O: Reflect overlap
 └Multidirectional
  ├←: Left
  └↑: Up

Haskell, 177 163 bytes

import Data.List
k n=[1..n]>>" "
f s=let n=length s in map(\x->(k(((n-1)*(n-(abs x)))))++(intercalate (k(abs x))$map(\z->[z])$((++)=<<reverse.tail) s))[n,n-1.. -n]

The function f is the challenge function and returns a list of strings ([String]), using unlines on it should provide the same visual output as the test cases (main = putStr $ unlines $ f "test string" to compile it).

Try it online!

-14 bytes thanks to @nimi

Python 3, 134 124 bytes

f=lambda s:'\n'.join([' '*(len(s)-1)*abs(len(s)-abs(i)-2)+(' '*abs(i)).join(s[::-1]+s[1:]) for i in range(2-len(s),len(s)-1)])

Try it online!

First post to PPCG after lurking for a while. Looking for any suggestions/advice!


Thanks to @LyricLy and @Łukasz Rogalski for improvements!

05AB1E, 17 bytes

g<F¹RSðN×ýû})Rû.c

Try it online!

-1 thanks to kalsowerus.

PHP, 145 131 bytes

It took some thinking to golf that additional byte; but it was worth it.

while($y<=2*$e=strlen($a=$argn)-1)echo($p=str_pad)("
",$e*($e-$d=abs($y++-$e))+1),chunk_split($a.substr(strrev($a),1),1,$p("",$d));

prints a leading newline. Run as pipe with -nR or try it online.

breakdown

while($y<=2*$e=strlen($a=$argn)-1)  # $e=length-1, loop through rows
                                        # 1. print linebreak and left padding
    echo($p=str_pad)("\n",$e*($e-$d=abs($y++-$e))+1),
        chunk_split(
            $a.substr(strrev($a),1)     # 2. palindromize input
            ,1,$p("",$d));              # 3. insert $e..0..$e spaces between characters

alternative solution, same length:

for($d=-$e=strlen($a=$argn)-1;$d<$e;)echo($p=str_pad)("
",$e*($e-$b=abs($d++))+1),chunk_split($a.substr(strrev($a),1),1,$p("",$b));

Python 3, 149 141 95 bytes

def f(s):l=len(s)-1;[print((' '*abs(i)).join(s[:0:-1]+s).center(2*l*l+1))for i in range(1-l,l)]

Try it online!

Thanks to @KevinCruijssen and @ETHproductions for saving some bytes

Special thanks to @notjagan for saving 46 bytes!

Java (OpenJDK 8), 201 196 bytes

s->{for(int l=s.length()-1,i=-l,x=0;++i<l;x+=i<0?l:-l)System.out.printf("%1$"+(x<1?"":x)+"s"+s.join("%1$"+(i<0?-i:i>0?i:"")+"s",(new StringBuffer(s.substring(1)).reverse()+s).split(""))+"%n","");}

Try it online!

It's the same idea as the one I used for the previous challenge, except that the generator string is now a tad longer and with more hard to handle cases.

%1$Ns0%1$Ns9%1$Ns8%1$Ns7%1$Ns6%1$Ns5%1$Ns4%1$Ns3%1$Ns2%1$Ns1%1$Ns2%1$Ns3%1$Ns4%1$Ns5%1$Ns6%1$Ns7%1$Ns8%1$Ns9%1$Ns0%n

Mathematica, 141 bytes

Column[Join[Reverse@(s=Row/@Table[Riffle[Reverse@Rest@b~Join~b,""<>Table[" ",i]],{i,0,Length[b=Characters@#]-1}]),Rest@s],Alignment->Center]&

APL (Dyalog), 37 bytes

Requires ⎕IO←0 which is default on many systems.

{⍉m(2-d)↓⍉(m←⊖⍪1↓⊢)↑∊¨(1↓⍳d←≢⍵)↑¨¨⊂⍵}

{} anonymous function where the argument is represented by

()↑¨¨⊂⍵ for each (¨) of the following numbers take () that many characters from each (¨) of the entire () argument, padding with spaces as necessary:

  ≢w the number of characters in the argument

  d← store that in d

   that many ɩndices (0 … d − 1)

  1↓ drop one (the zero)

∊¨ϵnlist (flatten) each

 raise the rank (convert the list of lists into a matrix)

(m←) apply the following tacit function m, defined as:

   the upside-down argument

   on top of

  1 one [row]

   dropped from

   the argument

 transpose

()↓ drop:

  2-d = −(d − 2), i.e. d − 2 rows from the bottom

m apply m

 transpose

Try it online!

SOGL V0.12, 22 18 bytes

ā,⁄H{,čFH@*∑Κ}▓±╬-

Try it Here!

Explanation:

ā                   push an empty array - canvas
 ,⁄H{        }      input length-1 times do
     ,                push the input
      č               chop it into chars
       FH@*           get the current iteration-1 amount of spaces
           ∑          join the chopped input with the spaces
            Κ         prepend it to the array
              ▓     space to a square
               ±    reverse each string in that list
                ╬-  quad-palindromize with 1 X and 1 Y overlap and without swapping characters

Japt, 22 21 bytes

¬Å£¬qYîÃy w ê y w ê ·

Test it online!

Explanation

The first 8 bytes generate the bottom-right quadrant of the pattern:

 ¬ Å  £    ¬ qYîÃ
Uq s1 mXY{Uq qYî} 

Uq                 : Split the input into characters.
   s1              : Slice off the first.
      mXY{      }  : Map each item X and index Y to
          Uq       :   the input split into chars,
             q     :   joined with
              Yî   :     Y spaces.

At this point we have an array of e.g. ["ABCD", "A B C D", "A B C D"]. Unfortunately, it takes 13 bytes to square this:

y w ê y w ê ·
y w ê y w ê qR
y                : Pad each line to the same length with spaces and transpose.
  w              : Reverse the array, and
    ê            : palindromize. Now we have the bottom half of the output transposed.
      y          : Transpose back.
        w ê      : Reverse and palindromize again, giving the full output.
            qR   : Join with newlines.
                 : Implicit: output result of last expression