g | x | w | all
Bytes Lang Time Link
006Japt240910T112711ZShaggy
010Zsh190908T094233ZGammaFun
070C gcc180202T161123Zgastropn
030JavaScript ES6180202T122427ZETHprodu
044shortC180205T045934ZMD XF
068SNOBOL4 CSNOBOL4180202T152711ZGiuseppe
074BrainFlak180203T213602ZNitrodon
112tinylisp180204T045601ZDLosc
002Pyth180202T122437ZMr. Xcod
018Ruby180202T224936Zm-chrzan
034brainfuck180202T232302ZJo King
029Julia 0.6180202T215402Zgggg
022Python 2180202T204227Zxnor
068Haskell180202T155408ZLaikoni
028Python 2180202T123209ZRod
030Python 2180202T131029Zovs
044R180202T142445ZGiuseppe
006Charcoal180202T132756ZNeil
025Perl 5180202T131551ZDom Hast
00205AB1E180202T122845ZMr. Xcod

Japt, 6 bytes

P±QOpP

Test it, doubled, tripled

P±QOpP
P          :Initially empty string
 ±         :Append and reassign result
  Q        :  Quotation mark
   OpP     :Output P with trailing newline

Zsh, 10 bytes

s+=0
<<<$s

Try a full test suite online!

...yeah, this is a bit better. Append to string N times, then print N times. Turns out <<<foo<<<foo works just fine.


Zsh, 64 bytes

Character used: (space).

f(){printf '%*s\n' $1}
:<<'E'

E
repeat $[i=LINENO/3];f $i
exit

Try a full test suite online!

The midpoint is between the second E and the newline following it. A heredoc will end when there is an E on a line by itself, which happens right in the middle of the code.

C (gcc), 170 168 96 80 72 70 bytes

Much shorter version. Still wish I could find a solution without the preprocessor.

i;main(n){for(;i++<n;)printf
#if 0

#endif
(" %*c",n=__LINE__/4, 10);}

Try it online!

Old 168 byte version:

#ifndef A
#define A p(c){putchar(c);}j,n;main(i){for(
#else
#define A n++,
#endif
A



#ifndef B
#define B i=++n;i--;p(10))for(j=n;j--;)p(64);}
#else
#define B
#endif
B

Try it online!

JavaScript (ES6), 42 32 30 bytes

s=[this.s]+0;  console.log(s);

Second iteration:

s=[this.s]+0;  s=[this.s]+0;  console.log(s);console.log(s);

This works by appending a 0 to s each time the first half of the code is run, and printing s itself each time the second half is run. Takes advantage of four quirks of JavaScript:

  1. The current environment can be referred to with this. This allows us to do this.s in place of s.
  2. When accessing a property that has not been defined on an object, instead of throwing an error, JavaScript returns undefined.
  3. An array plus a number returns a string. [1,2,3] + 4 === "1,2,34"
  4. When stringifying an array, undefined is converted to the empty string, which means that [undefined] + 0 === "0".

Put together, this means that we can express the first half (generating a string of zeroes) in just 13 bytes. If using alert instead of console.log is allowed, we can save 4 more bytes by shortening the second half.

shortC, 56 44 bytes

-12 bytes: wait duh I'm using shortC why not use some shortened C stuff

s[];A
strcat(s,"@");//
Js);/*filling space*/

I would've used standard C, but that requires a } at the end which messes with replication. shortC inserts it at EOF implicitly.

SNOBOL4 (CSNOBOL4), 130 68 bytes

Now with no comments! See the edit history for an explanation of the old algorithm.

	X =X + 1
	A =ARRAY(X,DUPL(1,X));
I	I =I + 1
	OUTPUT =A<I>	:S(I)
END

Try it online!

Try it doubled and tripled

Explanation:

	X =X + 1		;* increment X
	A =ARRAY(X,DUPL(1,X));	;* create an x-length array with 1 repeated x times for each element
I	I =I + 1		;* for i < x
	OUTPUT =A<I>	:S(I)	;* output a[i]
END

Because an END label is required and anything after the first END label is ignored, we get two advantages for this challenge:

This suggests that we use the repetition for the first half, and then we can use a more "conventional" labeling approach to repeat the output X times.

The first half is

	X =X + 1
	A =ARRAY(X,DUPL(1,X));

which, when repeated, increments X the appropriate number of times, and creates an ARRAY A with indices from 1 to X and where each element of A is the string 1 repeated X times.

Then no matter how many times the program is repeated, the interpreter only sees:

I	I =I + 1
	OUTPUT =A<I>	:S(I)
END

which is a typical SNOBOL program that prints out the elements of A one at a time until the index goes out of bounds, then terminates the program.

; is an optional line terminator usually reserved for one-line EVAL or CODE statements that quite neatly brings the byte count to 68 and marks the halfway point, allowing the code to be appended there.

Brain-Flak, 74 bytes

(((((()()()){}){}){}){})((()()()()()<>){})<>([]){({}[()]<(({})<>)<>>)}{}<>

Try it online!

Try it doubled and tripled.

Explanation

(((((()()()){}){}){}){}) # push 48 ("0") onto first stack
((()()()()()<>){})       # push 10 (\n) onto second stack
<>([]){({}[()]<          # a number of times equal to the height of the first stack:
  (({})<>)<>             #   copy the top of the first stack to the second stack
>)}{}<>                  # cleanup and return to second stack

The break point is in the middle of the <> in the "push 10" section. Breaking this up will leave a 5 on the third stack until we reach the corresponding second half, at which point pushing 10 will resume right where it left off.

While it is possible to push a printable ASCII value (space) in 22 bytes, this would make the central <> be executed after pushing 5. By adding two more bytes, I was able to move the <> so that all of the progress toward pushing 10 was on the third stack. As a bonus, this also made the resulting square more aesthetically pleasing.

tinylisp, 112 bytes

(load library) (d N((q((x)(i x(inc x)1)))(v(h(t(t(h(t(q())))))))))(join(repeat-val(string(repeat-val 42 N))N)nl)

Try it online! Also doubled and fivefold.

The "build a string in the first half, print it in the second half" approach that a lot of languages are taking won't work in tinylisp, since there are no mutable variables. Instead, we do some serious code nesting.

When a second copy of the code is inserted, it is placed inside the (q()), which wraps it in a list. Then (h(t(t(h(t(...)))))) drills into that list to the part after (d N. (v(...)) evaluates it; then we pass it to the unnamed function (q((x)(i x(inc x)1))), which increments the resulting value if it's a number and returns 1 if it's the empty list. The final result in the outermost nested version of the code is assigned to N. In essence, we've set up a weird sort of recursion that counts the number of nesting levels.

The second half of the code then creates a string of N asterisks, then a list of N such strings, then joins the list on newlines. The result is displayed with a trailing newline.

Pyth, 2 bytes


5

Try it online! Also Try it doubled, tripled!

How does that work?

\n is the command that prints its argument with a trailing newline, while returning it simultaneously. So, each time you make an insertion, you turn the integer literal 5 into a number containing N copies of 5 concatenated, and the leading newlines basically make sure it's printed the appropriate number of times, thus keeping it square.

Ruby, 18 bytes

$/=?x+$/;  puts$/;

Try it online! Doubled! Tripled!

brainfuck, 44 34 bytes

crossed out 44 is still regular 44 ;(

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

Try it online!

Try it doubled, tripled. Look, no padding!

Prints squares of U. It splits right down the middle of the 10 +s.

Julia 0.6, 29 bytes

All my ideas were longer than adapting xnor's clever python solution.

i=0;i+=1;    i
println("0"^i)

Becomes

i=0;i+=1;    ii=0;i+=1;    i
println("0"^i)
println("0"^i)

Try it online!

Python 2, 22 bytes

i=0;i+=1; i
print'*'*i

Try it online!

Doubled:

i=0;i+=1; ii=0;i+=1; i
print'*'*i
print'*'*i

Note that the second half starts with a newline character.

Haskell, 68 bytes

let s@(z:n)="0\n"in case lines<$>[]of(h:t):_->(h:h:t)>>(z:h++n);_->s

Try it online once, twice or thrice.

Because of Haskell's laziness an expression like the one above counts as a function which takes no arguments, as per this Meta question.

Python 2, 42 38 28 bytes

id='%s@'%id  ;print id[22:];

Try it online!. You can also try the 2nd and 3rd iterations

Python 2, 30 bytes

False+=1      ;print'*'*False;

Try it online!, 2nd and 3rd iteration

This makes use of the fact that bools in Python are basically ints and the names False and True were reassignable in Python 2.

Python 1, 32 bytes

exit=exit+'*'  ;print exit[30:];

Try it online!, 2nd and 3rd iteration

In Python 1 the builtin strings exit and quit existed to inform the user of the interactive shell how to exit it. The default value is "Use Ctrl-D (i.e. EOF) to exit.".

R, 44 bytes

F=F+1;T=TRUE*TRUE+12;
write(strrep(1,F),"");

Try it online!

Prints with a trailing newline. The T=TRUE*TRUE+12 is just to pad the length.

Try it doubled and Try it tripled.

Charcoal, 6 bytes

⊞υωLυ⸿

Try it online! Explanation:

  ω     Predefined empty string (any variable would do here)
 υ      Predefined initially empty list
⊞       Push

υ ends up with a length of the number of repetitions.

    υ   List
   L    Length
        Implicitly print as a row of `-`s
     ⸿  Move to start of next line

Perl 5, 25 bytes

24 bytes code + 1 for -p.

Appreciate that you might not want to allow commandline flags, please let me know if this is not valid.

$@=0 x++$n;;$_="$@
"x$n;

Try it online!

05AB1E, 2 bytes

5=

Try it online!

Port of my Pyth answer.