41
\$\begingroup\$

The Challenge

Your task is to create a program that takes any given string input, and outputs the input in a squared format. Empty strings should return an empty string.

Examples

Given the input:

golf

Your program should output:

golf
o  l
l  o
flog

Input:

123

Output:

123
2 2
321

Input:

a

Output:

a

Input:

Hello, world!

Output (notice the space between the , and w - the gap is not just a newline):

Hello, world!
e           d
l           l
l           r
o           o
,           w

w           ,
o           o
r           l
l           l
d           e
!dlrow ,olleH

Scoring

This is , so the shortest answer in each language wins.

\$\endgroup\$
9
  • \$\begingroup\$ @DJMcMayhem Yes, my apologies I had forgotten to add that. \$\endgroup\$ Jul 20, 2017 at 21:47
  • 2
    \$\begingroup\$ No worries, just double checking. Nice first challenge BTW! Welcome to the site :) \$\endgroup\$
    – DJMcMayhem
    Jul 20, 2017 at 21:47
  • \$\begingroup\$ @SpookyGengar Would you add a test case for a one-letter input? \$\endgroup\$ Jul 20, 2017 at 21:58
  • \$\begingroup\$ @musicman523 don't I already have one? The third example involving just the letter 'a'. \$\endgroup\$ Jul 20, 2017 at 21:59
  • 1
    \$\begingroup\$ @SpookyGengar my bad, I'm blind apparently \$\endgroup\$ Jul 20, 2017 at 22:01

32 Answers 32

1
2
0
\$\begingroup\$

Mathematica, 138 91 bytes

(b=Outer[" "&,#,#];Do[l={{1,k},{k,1}};b=ReplacePart[b,Join[l,-l]->#[[k]]],{k,Length@#}];b)&

You can try it online with by pasting the following at the Wolfram Cloud Sandbox and clicking "evaluate cell" or hitting Shift+Enter or Numpad Enter:

(b=Outer[" "&,#,#];Do[l={{1,k},{k,1}};b=ReplacePart[b,Join[l,-l]->#[[k]]],{k,Length@#}];b)&@{"g","o","l","f","y"}//MatrixForm
\$\endgroup\$
0
\$\begingroup\$

><> (Fish) - 153 bytes

l:>:?v;l$-[r:or].
-$/-$>$: ?vao~1-l1
  ^1vv?(2:<
 1^\:>$:&05&60. >$:&04&60.
o 1^\l3-=?v$:2(?^:l3-=?v$' '
 $^/$-3l:$<   /1-$-3l:$<
   \-1+&05&60.\+&04&60.

Try it

Make sure the initial stack setting is set to "chars", occasinally it bugs out and switches itself to numbers.

Summary

enter image description here

The blue bar at the top l$-[r:or] prints the n-th letter. The rest of the code is mostly branches leading to &04&60. that jump to the nth letter printer.

\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.