Skip to main content
1 of 2
Mitch Schwartz
  • 5.9k
  • 1
  • 27
  • 26

Brainfuck, 83 bytes

,[>+[>+<-],]
>
[
  >>[<+<-->>-]
  +<[>+<-]
  <-
]
<<
[
  [<]
  >.,
  >[>]
  >>+>-[<]
  <[[>+<-]++++++++++.,<<]
  <
]

Try it online!

This uses the same idea as Leaky Nun's answer. 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 ....

Mitch Schwartz
  • 5.9k
  • 1
  • 27
  • 26