Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

A square of text

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, 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 , so shortest answer in bytes wins! Tiebreaker is most upvoted answer.
  • Standard loopholes are forbidden.

Answer*

Draft saved
Draft discarded
Cancel
6
  • \$\begingroup\$ Nice use of $@, ;) You can save a byte using y///c instead of length and I think you can use a literal new line as well. I was looking as trying to do something with setting ,ドル and matching, but I think this is much shorter! \$\endgroup\$ Commented Aug 5, 2016 at 22:52
  • 1
    \$\begingroup\$ @DomHastings Yea, I thought you'd like the $@! Thanks for the y///c, I tend to forget that it exists. \$\endgroup\$ Commented Aug 5, 2016 at 23:21
  • 1
    \$\begingroup\$ @DomHastings managed to save 1 byte by using $= instead of $@, which allows to not use -l flag. \$\endgroup\$ Commented Aug 7, 2016 at 12:26
  • \$\begingroup\$ Good going! Good to use the magic variables for genuine reasons too! \$\endgroup\$ Commented Aug 7, 2016 at 14:00
  • \$\begingroup\$ Hey, hope you're doing alright! This got bumped to homepage and I noticed another optimisation for -1: 23 bytes code + 4 for -pF \$\endgroup\$ Commented Oct 5, 2017 at 15:16

AltStyle によって変換されたページ (->オリジナル) /