Out dated 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.
This is based offThe most important part of the code is a neat littlemodified square root snippetfunction I wrote some time ago. The original version was
It onlyAnd this works on perfect squares, but that's okwe actually want two copies of the negative square root. Why? We need two copies because we are looping through the input will alwaysstring at two levels, one to make the lines and one to count the number of lines. We want it to be a perfect squarenegative because looping with negatives is cheaper.
Here is an annotated version ofTo make this negative we move around the code[...]
so it looks like this
{([{}([]{})(<{}[()>]))< #}{Get the stack height and put zero under it for the square root rutine}
To make two copies we change when pops occur
{({}[({})(({}[())])))}{} #{Perform the square root}
>]
Now that we have that bit we can put it together with a stack height to get the first chunk of code we need.
([]<>) #{Recall the stack height({}
{}(({}[()])))}{}
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
{({}()< #(({n times}
)<{({}[()]<<<>({}<>)<>>>)}{} #{move n items to the offstack}
<>((()()()()()){})<> #{Put a newline on the other stack}
>)>)} #{End loop}
{}{} #{Cleanup}
<>
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.
{({}<>)<>}<> #{Move everything back}