[Question]
  [
## The Challenge
Given a string, output the text in the shape of a square.
You can assume that the text will always fit in a [square](https://oeis.org/A000290), and that it will never be an empty string.
You can also assume it will never have newlines.
### Example
```
Input:
Hi, world
Output:
Hi,
 wo
rld
```
## Test Cases
```
Input:
Hi, world! Hello
Output:
Hi, 
worl
d! H
ello
Input:
Lorem ipsum dolor sit amt
Output:
Lorem
 ipsu
m dol
or si
t amt
Input:
H
Output:
H
```
## Rules
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest answer in bytes wins! Tiebreaker is most upvoted answer.
* Standard loopholes are forbidden.
  
[Answer]
# Vim, ~~59, 57~~, 48 bytes/keystrokes
```
$:let @q=float2nr(sqrt(col('.')))."|li<C-v><cr><C-v><esc>@q"<cr>@q
```
Since V is backwards compatible, you can [Try it online!](https://tio.run/nexus/v#@69ilZNaouBQaJuWk59YYpRXpFFcWFSikZyfo6Gup66pqamnVJOTKcYlJu1QqMTlUPj/v09@UWquQmZBcWmuQkp@Tn6RQnFmiUJibsl/3TIA "V ‚Äì TIO Nexus")
I randomly received an upvote on this answer, so I looked over it again. My vim-golfing skills have greatly increased over the last 7 months, so I saw that this answer was very poorly golfed. This one is much better.
[Answer]
# [Brainfuck](http://esolangs.org/wiki/Brainfuck), ~~116~~ 112 bytes
```
>>>>,[[<]<<+>>>[>],]<[<]<+<[>>+<[-<-<+>>]<<++[->>+<<]>]>[-]>>[<[->.[-]<[->+<]<+[->+<]>>]++++++++++.[-]<[->+<]>>]
```
[Try it online!](http://brainfuck.tryitonline.net/#code=Pj4-LFs-LF08W1stPis8XTxbPF08Kz4-Wz5dPF0rPFs-Pis8Wy08LTwrPj5dPDwrK1stPj4rPDxdPl0-Wy1dPj5bPFstPi5bLV08Wy0-KzxdPCtbLT4rPF0-Pl0rKysrKysrKysrLlstXTxbLT4rPF0-Pl0&input=YWJjZGVmZ2hp)
Safe in flavours of BF that does not mask the cells with `256`, does not support null bytes.
Remove the initial right arrows if the flavour supports negative memory for 4 bytes saved.
## Explanation
The program is divided into 3 stages:
```
Stage 1: >>>>,[[<]<<+>>>[>],]<[<]
Stage 2: <+<[>>+<[-<-<+>>]<<++[->>+<<]>]>[-]>>
Stage 3: [<[->.[-]<[->+<]<+[->+<]>>]++++++++++.[-]<[->+<]>>]
```
### Stage 1
In this stage, we put all the characters onto the tape, while keeping count of the number of characters.
This is the tape for the input `abcdefghi` after this tape:
```
000 009 000 000 095 096 097 098 099 100 101 102 103
             ^
```
The `009` is the count.
For each character, we move the the first zero on the left `[<]` and then add one to the count `<<+>>>`, and then move to the rightmost zero `[>]` to get ready for the next character.
## Stage 2
This stage does the square root of the length stored in the second cell.
It keeps subtracting by `1, 3, 5, 7, ...` until the number reaches zero, while keeping check of the number of iterations.
It works because square numbers can be expressed as `1 + 3 + 5 + ...`.
## Stage 3
Denote the square root of the length found above as `n`.
This stage outputs `n` characters at a time, and then output a newline, until the tape is cleared.
[Answer]
## Python 2, 55 bytes
```
s=input()
n=int(len(s)**.5)
while s:print s[:n];s=s[n:]
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 5 bytes
```
Dgt√¥¬´
```
[Try it online!](http://05ab1e.tryitonline.net/#code=RGd0w7TCqw&input=TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtdAo)
```
D    duplicate a (implicit input)
g    length of a
t    square root of a
√¥    push a split in pieces of b
¬´    join by newlines (implicit output)
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
tnX^e!
```
[**Try it online!**](http://matl.tryitonline.net/#code=dG5YXmUh&input=J0hpLCB3b3JsZCEgSGVsbG8n)
### Explanation
```
t     % Take input implicitly. Push another copy
n     % Get number of elements of the copy
X^    % Take square root
e     % Reshape the input into that number of rows, in column-major order
      % (which means: down, then across)
!     % Transpose so that text reads horizontally. Implicitly display
```
[Answer]
# Jelly, ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
sL√Ü¬Ω$j‚Å∑
```
Saved a byte thanks to @[Dennis](https://codegolf.stackexchange.com/users/12012/dennis).
[Try it online.](http://jelly.tryitonline.net/#code=c0zDhsK9JGrigbc&input=&args=J0xvcmVtIGlwc3VtIGRvbG9yIHNpdCBhbXQn)
## Explanation
```
sL√Ü¬Ω$j‚Å∑  Input: string S
    $    Monadic chain
 L         Get the length of S
  √Ü¬Ω       Take the integer square root of it, call it n
s        Split S into chunks of size n
     j‚Å∑  Join using newline
```
[Answer]
## JavaScript (ES7), 49 bytes
```
s=>s.match(eval(`/.{${s.length**.5}}/g`)).join`
`
```
44 bytes in Firefox Nightly 43-46 only (`**` was introduced some time between Firefox Nightly 42 and 43 and `g` as a separate parameter was removed some time between Firefox Nightly 46 and 47):
```
s=>s.match(`.{${s.length**.5}}`,`g`).join`
`
```
[Answer]
# J, 9 bytes
```
$~,~@%:@#
```
This is a monadic hook over the input string:
```
$~ ,~@%:@#
```
The right tine is a series of compositions:
```
,~ @ %: @ #
```
The left is a shaping verb, switched such that it works in the hook format.
Here are some intermediate results:
```
   # 'hiya'
4
   %:@# 'hiya'
2
   ,~@%:@# 'hiya'
2 2
```
In words:
```
   size =: #
   sqrt =: %:
   dup =: ,~
   on =: @
   shape =: $~
   block =: shape dup on sqrt on size
   block 'Hello, World! :)'
Hell
o, W
orld
! :)
```
[Answer]
# C, 64 bytes
Call `f()` with the string to square.
```
m;f(char*s){for(m=sqrt(strlen(s));*s;s+=m)printf("%.*s\n",m,s);}
```
[Try it on ideone](http://ideone.com/bQlPa9).
[Answer]
## Perl, 23 + 4 (`-pF` flags) = 27 bytes
*-2 bytes thanks to [@DomHastings](https://codegolf.stackexchange.com/users/9365/dom-hastings)*  
*-1 bytes thanks to [@DomHastings](https://codegolf.stackexchange.com/users/9365/dom-hastings)*
```
$==sqrt@F;s/.{$=}/$&
/g
```
[Try it online!](https://tio.run/##BcGxCgIxDADQPV8RoTipnZyk4HR08Cd6XJVCamqSQ1Du143vjSp0dg8p6UvsOl00nr4hbTHsIT7cM1hVgzvzXGQuH8jtgG8WWnaYKxHDjaV2bEPXjgsTC2ozLN1@PKzxU/04pj8 "Perl 5 ‚Äì Try It Online")
**Expanations** : computes the square root (lets call it `S` for the explanation) of the size of the input (it will be always be an integer) (`@F` is used in scalar context, thus returning its size), then add a newline after each bloc of `S` characters.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~8~~ 6 bytes
*Thanks to @quartata for letting me know about the square-root function*
```
Dgt√¥¬∂√Ω
```
[**Try it online!**](http://05ab1e.tryitonline.net/#code=RGd0w7TCtsO9&input=TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtdA)
### Explanation
```
D     Implicit input. Duplicate
g     Number of elements
t     Square root
√¥     Split into chunks of that length
¬∂     Push newline character
√Ω     Join list by newlines. Implicit display
```
[Answer]
# Dyalog APL, 10 bytes
```
‚ä¢‚ç¥‚ç®2‚ç¥.5*‚ç®‚â¢
```
Explanation:
```
         ‚â¢   length of the argument   
     .5*‚ç®    square root 
   2‚ç¥        reshape that to a length-2 vector
‚ä¢‚ç¥‚ç®          reshape the input by that vector
```
Tests:
```
      (‚ä¢‚ç¥‚ç®2‚ç¥.5*‚ç®‚â¢)'Hi, world'
Hi,
 wo
rld
      (‚ä¢‚ç¥‚ç®2‚ç¥.5*‚ç®‚â¢)'Hi, world! Hello'
Hi, 
worl
d! H
ello
      (‚ä¢‚ç¥‚ç®2‚ç¥.5*‚ç®‚â¢)'Lorem ipsum dolor sit amt'
Lorem
 ipsu
m dol
or si
t amt
      (‚ä¢‚ç¥‚ç®2‚ç¥.5*‚ç®‚â¢) 'H'
H
```
[Answer]
# Python, ~~94~~ ~~75~~ ~~71~~ ~~65~~ 63 bytes
```
import re;lambda r:"\n".join(re.findall("."*int(len(r)**.5),r))
```
Old version:
```
lambda r:"\n".join(map("".join,zip(*[iter(r)]*int(len(r)**.5))))
```
[Answer]
## zsh, ~~36~~ 33 bytes
```
fold -`tr -d .<<<$[$#1**.5]`<<<$1
```
[Try it online!](https://tio.run/##qyrO@P8/LT8nRUE3oaRIQTdFQc/GxkYlWkXZUEtLzzQ2AcQz/P//v09@UWquQmZBcWmuQkp@Tn6RQnFmiUJibgkA)
Takes input as a command line argument, outputs to STDOUT.
```
                   $#1             # get the length of the input string
                 $[   **.5]        # take it to the .5 power (sqrt)
              <<<                  # and pass the result to
       tr -d .                     # tr, to delete the trailing decimal point
                                   #    (sqrt(9) is 3. instead of 3)
     -`                    `       # give the result as a command line flag to
fold                               # the fold util, which wraps at nth column
                            <<<$1  # pass the input as input to fold
```
[Answer]
# Cheddar, 27 bytes
```
s->s.chunk(s.len**.5).vfuse
```
I added the `.chunk` function a while ago but I removed it in the transition to the new stdlib format and forgot to re-add it. Cheddar has a dedicated `sqrt` operator but `**.5` is shorter
[Try it online!](http://cheddar.tryitonline.net/#code=cy0-cy5jaHVuayhzLmxlbioqLjUpLnZmdXNl&input=SGksIHdvcmxk)
## Explanation
```
s ->              // Function with argument s
    s.chunk(      // Chunk it into pieces of size...
      s.len ** .5 // Square root of length.
    ).vfuse       // Vertical-fuse. Join on newlines
```
[Answer]
# [CJam](https://sourceforge.net/projects/cjam/), 8 bytes
```
l_,mQ/N*
```
[**Try it online!**](http://cjam.tryitonline.net/#code=bF8sbVEvTio&input=SGksIHdvcmxk)
### Explanation
```
l     e# Read line from input
_,    e# Duplicate. Get length 
mQ    e# Integer square root
/     e# Split into pieces of that size
N*    e# Join by newline. Implicitly display
```
[Answer]
# Pyth, 8 bytes
```
jcs@lQ2Q
```
[Try it online](https://pyth.herokuapp.com/?code=jcs%40lQ2Q&test_suite=1&test_suite_input=%22Hi%2C+world%22%0A%22Lorem+ipsum+dolor+sit+amt%22%0A%22H%22)
### How it works
```
    lQ     length of input
   @  2    square root
  s        floor
 c     Q   chop input into that many equal pieces
j          join on newline
```
[Answer]
# Bash + GNU utilities, 25
```
fold -`dc -e${#1}vp`<<<$1
```
Not so different to [@Doorknob's answer](https://codegolf.stackexchange.com/a/88960/11259), but `dc` is a shorter way to get the square root.
[Answer]
# ùîºùïäùïÑùïöùïü, 11 chars / 14 bytes
```
—®ƒä(√Ø,‚àö √ØÍùà‚∏©ƒñ‚¨Æ
```
`[Try it here (ES6 browsers only).](http://molarmanful.github.io/ESMin/interpreter3.html?eval=false&input=asdfghjkqweruiop&code=%D1%A8%C4%8A(%C3%AF%2C%E2%88%9A%20%C3%AF%EA%9D%88%E2%B8%A9%C4%96%E2%AC%AE)`
Generated using this code (run in the interpreter's browser console):
```
c.value=`—®${alias(_,'chunk')}(√Ø,‚àö √ØÍùà‚∏©${alias(Array.prototype,'mjoin')}‚¨Æ`
```
[Answer]
## Brainfuck, 83 bytes
```
,[>+[>+<-],]
>
[
  >>[<+<-->>-]
  +<[>+<-]
  <-
]
<<
[
  [<]
  >.,
  >[>]
  >>+>-[<]
  <[[>+<-]++++++++++.,<<]
  <
]
```
[Try it online!](http://brainfuck.tryitonline.net/#code=LFs-K1s-KzwtXSxdPls-Pls8KzwtLT4-LV0rPFs-KzwtXTwtXTw8W1s8XT4uLD5bPl0-Pis-LVs8XTxbWz4rPC1dKysrKysrKysrKy4sPDxdPF0&input=TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtdA)
This uses the same idea as Leaky Nun's [answer](https://codegolf.stackexchange.com/a/88968/2537). He asked for help golfing it in chat, then suggested that I add this as a new answer. (Actually what I wrote in chat was an 84-byte solution very similar to this.)
For the sake of comparison, an extra `>` is needed at the beginning for brainfuck implementations that don't allow negative memory addresses.
As expected, this finds the length of the input, then takes the square root, then prints the lines accordingly. It takes advantage of perfect squares being partial sums of `1 + 3 + 5 ...`.
[Answer]
# [Brain-Flak](https://github.com/Flakheads/BrainHack), ~~110~~ 96 bytes
```
([]<>){({}{}(({}[()])))}{}{({}()<(({})<{({}()<<>({}<>)>)}{}((()()()()()){})>)>)}{}{}{({}<>)<>}<>
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v9fIzrWxk6zWqO6trpWA0hGa2jGampqAnkgMQ1NG5Cgpg2UY2MHpIHq7TTByjU0YVATqAgqDNEJVGRjByT///@v5JGpo1CeX5STovRf1xEA "Brain-Flak (BrainHack) ‚Äì Try It Online")
# Second solution, 96 bytes
```
(([]<>)<{({}({})({}[()]))}{}>){({}(({})<{({}()<<>({}<>)>)}{}((()()()()()){})>))}{}{}{({}<>)<>}<>
```
[Try it online!](https://tio.run/##SypKzMzLSEzO/v9fQyM61sZO06Zao7oWiDSBOFpDM1ZTs7a61k4TLAoShshr2tjYAWmgejuQvIaGhiYMagIV2YF1ASFEjY0dkPz//7@SR6aOQnl@UU6K0n9dRwA "Brain-Flak (BrainHack) ‚Äì Try It Online")
## Explanation
Here I explain the first solution, both are the same length but I like the first one because it is cooler and employs some nice tricks.
The most important part of the code is a modified square root function I wrote some time ago. The original version was
```
{({}[({})({}())])}{}
```
And this works, but we actually want two copies of the negative square root.
Why? We need two copies because we are looping through the string at two levels, one to make the lines and one to count the number of lines. We want it to be negative because looping with negatives is cheaper.
To make this negative we move around the `[...]` so it looks like this
```
{({}({})({}[()]))}{}
```
To make two copies we change when pops occur
```
{({}{}(({}[()])))}{}
```
Now that we have that bit we can put it together with a stack height to get the first chunk of code we need.
```
([]<>){({}{}(({}[()])))}{}
```
We move to the offstack because our square root function needs two free zeros for computation, and because it makes stuff a little bit cheaper int he future in terms of stack switching.
Now we construct the main loop
```
{({}()<(({})<{({}()<<>({}<>)>)}{}((()()()()()){})>)>)}{}{}
```
This is pretty straight forward, we loop n times each time moving n items and capping it with a new line (ASCII 10).
Once the loop is done we need to reverse the order of our output so we just tack on a standard reverse construct.
```
{({}<>)<>}<>
```
[Answer]
## PHP, 51 bytes
```
<?=join("
",str_split($x=$argv[1],strlen($x)**.5));
```
[Answer]
# [Perl 6](http://perl6.org), 38 bytes
```
$_=get;.put for .comb: .chars.sqrt.Int
```
### Explanation:
```
$_ = get;          # get a single line of input
$_.put             # print with trailing newline
for                # every one of the following:
$_.comb:           # the input split into
$_.chars.sqrt.Int  # chunks of the appropriate size
```
[Answer]
# Cheddar, 57 bytes
```
n->(m->(|>m).map(i->n.slice(i*m,i*m+m)).vfuse)(n.len**.5)
```
Since variables are broken, I would have to pass in variables through lambda application.
Also, it turns out that even if variables worked, it would still be shorter to use lambda application.
### Usage
```
cheddar> (n->(m->(|>m).map(i->n.slice(i*m,i*m+m)).vfuse)(n.len**.5))("abcd")
"ab
cd"
```
[Answer]
## Pyke, 5 bytes
```
l,fnJ
```
[Try it here!](http://pyke.catbus.co.uk/?code=l%2CfnJ&input=Hi%2C+world)
[Answer]
# Java 1.7, 110 bytes
```
void f(String s){for(int i=-1,k=(int)Math.sqrt(s.length());++i<k;)System.out.println(s.substring(i*k,i*k+k));}
```
[Try it!](http://ideone.com/uXbmnu) (Ideone)
I tried another approach with a function returning the result as a string, but just having to declare the string and the return statement is already more expensive (byte-count-wise) than the print statement.
Gotta love Java's verbosity... :)
[Answer]
# [R](https://www.r-project.org/), ~~59~~ 54 bytes
```
function(s)write(el(strsplit(s,'')),1,nchar(s)^.5,,'')
```
[Try it online!](https://tio.run/##Fco9CoAwDEDh3VN0awpRcHDzAJ5C8KfFQG0liYinr3V8H49LpJUXfuH0euRdXNMEM7Yl3GlTygnEPUzqwUcQZbkiKQha6xz2mLZj4brM3YC/lQB2IjRP5rjX/AA "R ‚Äì Try It Online")
Prints with a trailing newline. Surprisingly short, considering how badly R handles strings.
[Answer]
# PowerShell, 56 ~~58~~ ~~61~~ bytes
```
param($i)$i-replace".{$([Math]::Sqrt($i.Length))}",'$&
'
```
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-p`, ~~40~~ ~~33~~ 30 bytes
-7 bytes from @Jordan.
```
gsub(/#{?.*~/$/**0.5}/){$&+$/}
```
[Try it online!](https://tio.run/##KypNqvz/P724NElDX7naXk@rTl9FX0vLQM@0Vl@zWkVNW0W/9v9/n/yi1FyFzILi0lyFlPyc/CKF4swShcTckn/5BSWZ@XnF/3ULAA "Ruby ‚Äì Try It Online")
[Answer]
# [K (ngn/k)](https://gitlab.com/n9n/k), 11 bytes
```
{(2#%#x)#x}
```
[Try it online!](https://tio.run/##y9bNS8/7/z/NqlrDSFlVuUJTuaL2f5qST35Raq5CZkFxaa5CSn5OfpFCcWaJQmJuidJ/AA "K (ngn/k) ‚Äì Try It Online")
---
the bracketed expression returns list `5 5` for input "Lorem ipsum dolor sit amt". it reads "2 take sqrt count x", where x is the string argument. then `(5 5)#x` means "cut x into 5 lists each of length 5". with this we get:
```
  {(2#%#x)#x}"Lorem ipsum dolor sit amt"
("Lorem";" ipsu";"m dol";"or si";"t amt")
```
]