# Continuously expanding code [duplicate]

Your job is to write a program that rewrites and makes itself longer on each run of the program.

# Challenge

The program will print Hello, World!\n (\n denotes a newline). Then, it will modify its own file so that the new program length is exactly 2x the length at runtime. This modified file when run, will print Hello, World!\nHello, World!\n. When run a third time, the file will print Hello, World!\nHello, World!\nHello, World!\nHello, World!\n.

More simply, on the nth run of the program, it will output 2^(n-1) instances of Hello, World!\n, and have a program length of 2^(n-1) the length of the original.

This is , so shortest code (before first run) wins. Please comment if you need something is not clear.

Edit: To get past the restriction of file-rewriting, your program may print the modified source along with the Hello, World!\ns at a +40% penalty.

• "it will modify its own file" can you provide a way to circumvent this? May 14 '16 at 9:48
• What do you mean by circumvent? May 14 '16 at 9:49
• Well, we can't exactly modify our own file in online compilers... May 14 '16 at 9:51
• @KennyLau How about printing something that theoretically would work offline? May 14 '16 at 10:02
• @LegionMammal978 it's more like codegolf.stackexchange.com/q/69504/8478 I guess. May 14 '16 at 12:32

# PHP, 100

<?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,81,20));echo"Hello World\n";  This script is appending an echo"Hello World";, but because you said the size should also vary, and because it's shorter, I'm also having this script: ## Shorter, 100 <?$a=$argv[0];$b=file_get_contents($a);file_put_contents($a,$b.substr($b,2,98));echo"Hello World\n";


This script is appending itself, in a way it adds one Hello World, but this version will overall take more space and takes longer to execute.

## Example

But the scripts don't vary when it comes to the output:

root@raspberrypi:~/stack# php hello_expand.php
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
root@raspberrypi:~/stack# php hello_expand.php
Hello World
Hello World
Hello World

• Umm, the third run of the program should have 4 Hello, Worlds!, not 3. May 14 '16 at 16:19