I have explicit permission to post this challenge here from the original author of the competition. Feel free to verify by following the provided link and contacting the author.

Problem

Write a program/function that will reshape a given string or numeric list into the smallest square that will contain all the elements of the input, padding with additional elements if necessary. The pad element should be the default fill element for the given data type, or any one element of your choice. The elements of the square should be in such order that flattening it will give the original order of input data (with trailing padding elements, if any).

\$\begingroup\$Do we have to be able to handle both strings and arrays as input or only one? Can output be a string containing newlines? Should the output for [100] not be [[1,0],[0,0]]? If not, is [[100,1],[2,0]] the expected output for input [100,1,2]?\$\endgroup\$
– ShaggyMay 15 '17 at 7:41

\$\begingroup\$Hi Adám, I have three questions... 1. What does "The pad element should be the default fill element for the given data type, or any one element of your choice." mean, - is it restricted or free (it seems contradictory or redundant)? 2. What should the output be for an input like [1,2,3,4,'O'], or is it guaranteed not to occur? 3. Is the required order after flattening requirement ignoring the pad elements (e.g. could an input of [1,2,3,4,5] yield [[0,0,0],[0,1,2],[3,4,5]] or even [[0,1,0],[2,0,3],[0,4,5]])?\$\endgroup\$
– Jonathan AllanMay 15 '17 at 14:00

1

\$\begingroup\$@JonathanAllan 1. Some languages will automatically pad. Whatever they pad with is fine. If your's don't, choose an element. 2. string or numeric list. 3. The padding elements must be trailing.\$\endgroup\$
– AdámMay 15 '17 at 14:04

\$\begingroup\$@LuisMendo I looked for a way to pass three inputs to reshape and didn't notice the very obvious: $: Specified inputs. And I didn't know you could pass the dimensions as a vector. I knew there had to be a way without having to go through two reshapes. Thanks! :)\$\endgroup\$
– Stewie GriffinMay 15 '17 at 11:23

Takes strings as lists of characters (the asker has confirmed that this is OK).

This is very inefficient on longer inputs, because it brute-forces all possible reshapings of the input, trying progressively more padding, until it finds one that happens to be square.

Explanation

;Ac~c.\l~l
;Ac Append {the shortest list possible}.
~c Split into a list of lists
\l such that it's rectangular, and the number of columns
. ~l equals the number of rows

The padding elements used are Prolog's "any value" value _, which is normally rendered as _G plus some random digits on output (to make it possible for the Prolog engine to express relationships between those general-purpose values).

Incidentally, there was a bug fix to SWI-Prolog only a few days ago that makes this program possible (although it still appears to work on older, buggy versions); the "it's rectangular" constraint implied by \ was previously broken, but it got fixed in time for the challenge.

How?

Appends as many zeros (the padding element) as there are elements in the input and then reshapes to a square, dropping any zeros excess to requirements in the process.

L½Ċẋ€` - Link 1, create a square list of lists of the required size: list a
L - length of a
½ - square root
Ċ - ceiling (the required side length, S)
` - repeat argument (S) for the dyadic operation:
ẋ€ - repeat list for €ach (implicit range [1,2,...,S] on both its left and right)
- note: if the input list has no length then an empty list is yielded here
0ṁ;@ṁÇ - Main link: list a (strings are lists of characters in Jelly)
0 - literal zero
ṁ - mould like a (makes a list of zeros of the same length as the flat list a)
;@ - concatenate a with that
Ç - call the last link (1) as a monad with argument a
ṁ - mould the (possibly oversized) flat array with extra zeros like the square array

Haskell, 87 bytes

The fill element is error[], the shortest value that is of any type (undefined is a little bit longer).

Notes on the TIO link:

you cannot print error, so I concatenate matrices with fill elements back to a list and print its length

TIO doesn't have Data.Lists, only Data.List.Split so it shows 5 more bytes.

How it works: calculate the length c of the c-by-c matrix. Take the first c elements of the list of chunks of length c of the input list followed by a list of fill elements which has the same length as the input list. E.g. :

Your Answer

If this is an answer to a challenge…

…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.

…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.

…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.

More generally…

…Please make sure to answer the question and provide sufficient detail.

…Avoid asking for help, clarification or responding to other answers (use comments instead).

Code Golf Stack Exchange is a site for recreational programming competitions, not general programming questions. Challenges must have an objective scoring criterion, and it is highly recommended to first post proposed challenges in the Sandbox.