You are to write a program that will output source code that is
- Larger than the original program (character wise)
- Will print another program larger than itself when run (i.e. the new program is also a valid answer to this challenge) indefinitely
This is code-golf, so shortest answer wins.
63 Answers 63
Julia 1.0, 33 bytes
a=[show,print]
".|>$([a;a])
".|>a
prints (79 bytes):
".|>Function[show, print, show, print]\n".|>Function[show, print, show, print]
then, the program is doubled each time:
".|>Function[show, print, show, print]\n".|>Function[show, print, show, print]
".|>Function[show, print, show, print]\n".|>Function[show, print, show, print]
based on this quine:
".|>[show,print]".|>[show,print]
PHP, 38
<?echo fgets(fopen(__FILE__,'r')).';';
It will add a semicolon at each run.
-
\$\begingroup\$ Are the semicolons useless code? \$\endgroup\$Justin– Justin2014年02月23日 18:00:43 +00:00Commented Feb 23, 2014 at 18:00
-
3\$\begingroup\$ @Quincunx They are, you are right. However, what would you consider useful code? \$\endgroup\$ComFreek– ComFreek2014年02月23日 18:03:17 +00:00Commented Feb 23, 2014 at 18:03
-
\$\begingroup\$ Maybe you could put in in the
';'. Then you'd get longer outputs. \$\endgroup\$Justin– Justin2014年02月23日 18:03:56 +00:00Commented Feb 23, 2014 at 18:03 -
1\$\begingroup\$ why not
<?=fgets(fopen(__FILE__,'r')).';';? \$\endgroup\$Ismael Miguel– Ismael Miguel2014年02月24日 23:54:57 +00:00Commented Feb 24, 2014 at 23:54 -
1\$\begingroup\$
;<?echo fgets(fopen(__FILE__,'r'));\$\endgroup\$jimmy23013– jimmy230132014年10月15日 08:59:11 +00:00Commented Oct 15, 2014 at 8:59
BATCH, 26
Place this code in any .bat file and it will continue to execute (in an infinite loop) and the file will grow as well.
echo echo %0 ^>^> %0 >> %0
-
\$\begingroup\$ This doesn't quite work,
%0is the command used to invoke the script, which may not have a.BATextension. You can use%~nx0to get the full filename of the batch file. \$\endgroup\$Jason C– Jason C2014年02月24日 00:06:17 +00:00Commented Feb 24, 2014 at 0:06 -
\$\begingroup\$ @JasonC AFAIK, it doesn't need the
.batto be executed. If the filename isexecute.bat, you can enter eitherexecuteorexecute.bat. Both will work. \$\endgroup\$SameOldNick– SameOldNick2014年02月24日 01:59:48 +00:00Commented Feb 24, 2014 at 1:59 -
\$\begingroup\$ The file itself needs to have a
.batextension to execute but you can leave the extension off when you execute it (when you type a command with no extension, Windows tries.com,.exe, then.batin that order). If the filename ishello.bat, then>> %0will write a file namedhello, which isn't the originalhello.bat(and can't be executed). \$\endgroup\$Jason C– Jason C2014年02月24日 02:40:58 +00:00Commented Feb 24, 2014 at 2:40
Batch
set d=time
copy c:\>loop.bat /B loop%d%.bat
call c:\>loop.bat
Javascript - 46
(function $(){console.log('('+$+'());$()')}())
PYG (6)
P(Q,Q)
Prints it's own source code, separated by newlines. The second generation would be
P(Q,Q)
P(Q,Q)
and so forth.
OIL, 83 bytes
0
0
1
1
1
4
1
11
4
1
11
1
2
2
1
12
18
10
18
1
32
22
1
18
26
4
26
8
18
11
6
17
4
26
It first prints two lines with a zero in them, and then compares each line to line 1, if they're equal (which is the case when the file is exhausted), we print what's in cell 26. The resulting output will look the same, except with an added 33, which doesn't do anything. Next time, another line will be added, and so on.
Help, WarDoq!, 1 byte.
H
Prints Hello, World!.
Other characters than H are valid (and safe) source code (that print other variants of Hello World).
-
\$\begingroup\$ Also works in (variants of) HQ9+. \$\endgroup\$CalculatorFeline– CalculatorFeline2017年01月05日 02:39:31 +00:00Commented Jan 5, 2017 at 2:39
-
\$\begingroup\$ @CalculatorFeline in HQ9+ this wouldn't continue to grow. \$\endgroup\$Martin Ender– Martin Ender2017年04月13日 09:18:24 +00:00Commented Apr 13, 2017 at 9:18
Charcoal, non-competing, 32 bytes
A ́α ́ ́ ́A ́F ́α ́+ ́ ́ ́ ́ ́ι ́αaα ́AFα+ ́ ́ια
Explanation:
first, go check out this answer on the quine challenge and its explanation.
This program is that program, but with the letter a at the end of the string variable.
A α Assign to a
́α ́ ́ ́A ́F ́α ́+ ́ ́ ́ ́ ́ι ́αa "α ́AFα+ ́ ́ιαa", but with ́ escape character with each
character, except a
these are the variable being assigned to, and the
rest of the program that is not the string.
́A Print A to the grid. current grid: "A"
Fα+ ́ ́ι For each character in a, print ́ + character
this results in the escaped version of the string
which is the literal string that is assigned at the
start, plus a escaped. current grid state: "A ́α ́ ́ ́A ́F ́α ́+ ́ ́ ́ ́ ́ι ́α ́a"
α Print a ("α ́AFα+ ́ ́ιαa"), which is the commands after
the string assignment. final grid state vvv:
"A ́α ́ ́ ́A ́F ́α ́+ ́ ́ ́ ́ ́ι ́α ́aα ́AFα+ ́ ́ιαa"
[implicitly print the grid: "A ́α ́ ́ ́A ́F ́α ́+ ́ ́ ́ ́ ́ι ́α ́aα ́AFα+ ́ ́ιαa", the new program]
This new program works in the same way, except for two things:
the "a" is escaped (which has no effect, as "a" escaped is "a")
there is an "a" at the end of the program. this "a" will write an extra "a" after the source is produced. thus the program grows slowly
C, (削除) 116 (削除ここまで) (削除) 149 (削除ここまで) (削除) 197 (削除ここまで) 189 bytes
i;main(a){printf(a="i;main(a){printf(a=%c%s%1$c,34,a,i+2);for(i=%d;i--;)",34,a,i+2);for(i=1;i--;)printf(a="printf(a=%c%s%1$c,34,a,34),",34,a);printf(a="0;printf(a=%c%s%1$c,34,a);}",34,a);}
How it works
main(a){declares the main function with an untyped variablea.- The first
printfprints the existing source code and aforloop. An integer isprintf'd into theforloop. This is how the multi-quine works - each time the quine program is called, it incrementsd, making theforloop run more times. - The second
printfis inside theforloop and prints itself, so each time the quine program is called, there are moreprintf's, therefore generating bigger versions of itself. Be warned that this growth is exponential, due to theforloop incrementation and the multipleprintfs. - The third
printfprints the remaining source code.
Requires POSIX.
Java 8, 92 bytes
v->{String s="v->{String s=%c%s%1$c+1;return s.format(s,34,s);}//";return s.format(s,34,s);}
Outputs (4 bytes larger):
v->{String s="v->{String s=%c%s%1$c+1;return s.format(s,34,s);}//"+1;return s.format(s,34,s);}//
Which outputs (2 bytes larger):
v->{String s="v->{String s=%c%s%1$c+1;return s.format(s,34,s);}//1"+1;return s.format(s,34,s);}//1
Which outputs (2 bytes larger):
v->{String s="v->{String s=%c%s%1$c+1;return s.format(s,34,s);}//11"+1;return s.format(s,34,s);}//11
etc. (2 bytes larger every new program)
Explanation:
quine-part:
- The
String scontains the unformatted source code. %sis used to input this String into itself with thes.format(...).%c,%1$cand the34are used to format the double-quotes.s.format(s,34,s)puts it all together
Challenge part:
- Unformatted source code contains
+1and//to make the output program larger and compilable. +1adds a 1 to both the unformatted and formatted program.
Gol><>, 5 bytes
#H}"'
This, I believe, is the smallest growing quine possible in Gol><>. It duplicates the #H} over and over...
AsciiDots, 20 bytes
($'#a_93ドル#"$_@("_$-.
First run
Sends a dot leftward, printing the characters (@_$ with a literal and ' from the ASCII value 39. The dot then turns around and interprets the path as a string, printing the rest of the line.
(@_$'#a_93ドル#"$_@("_$-.
Subsequent runs
Prints (@_$' again, as well as a 0, thanks to the added @_ from the first run. The 0 ends up on the right side of the ' symbol, which means that all 0s printed in a previous run carry over. The dot safely ignores the additional 0s on its path.
(@_$'0#a_93ドル#"$_@("_$-.
(@_$'00#a_93ドル#"$_@("_$-.
(@_$'000#a_93ドル#"$_@("_$-.
Keg, (削除) 18 (削除ここまで) (削除) 15 (削除ここまで) (削除) 14 (削除ここまで) (削除) 13SBCS (削除ここまで) (削除) 11 (削除ここまで) (削除) 10SBCS (削除ここまで) (削除) 9SBCS (削除ここまで) 6SBCS bytes
`410`410
I've gone and done it now! No more ascii around here now folks. This will print:
`410`410410
Which will print:
`410`410`410`410410
Which prints:
`410`410`410`410`410`410410410
And so on.
Answer History
9 bytes
`::.,`(2)410
This uses the same approach as the 10 byte answer
Explained
`::.,`(2)410
`::.,` #Push the string `::.,`
(2) #Double the string
410 #Print raw then nice without popping
10 bytes
`::.,`(2):.,
This prints:
`::.,::.,`::.,::.,
Which prints:
`::.,::.,`::.,::.,`::.,::.,`::.,::.,
11 bytes
`::.,`6*:.,
This prints:
`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,
Which prints:
`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,
And so on
13 bytes
`::.,`!9*:(.,
This prints:
`::.,::.,`::.,::.,
Which prints:
`::.,::.,`::.,::.,`::.,::.,`::.,::.,
And so on.
14 bytes
`::.,(:.,)`:.,
This will create pretty much the same chain as the previous 15-byter.
15 bytes
`::.,(::.,)`:.,
This prints:
`::.,(::.,)`::.,(::.,)
Which prints:
`::.,(::.,)`::.,(::.,)`::.,(::.,)`::.,(::.,)
And so on.
18 bytes
`:::.,(!2/|.,)`:.,
This will print
`:::.,(!2/|.,)`:::.,(!2/|.,)
Which in turn prints:
`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)
Which then prints:
`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)`:::.,(!2/|.,)
And so on.
JavaScript (ES6/2015), 12 bytes
a=_=>'a=_'+a
with invokation, 23 bytes
(a=_=>'(a=_'+a+')()')()
Every iteration adds an underscore to the parameter name
Wolfram Language (Mathematica), 19 bytes
ToString[10#0][]&[]
Returns 10 (ToString[10 #0][] & )[], which, when run, returns 10*10 (ToString[2 #0][] & )[]. From there, the beginning number is multiplied by 10 at every step, which increases the length of the code by 1.
Batch, 1 byte
a
Add prompt at head every time, error is who cares
><> (Fish), 14 bytes
'rd3*9[r:r]>o<
First iteration duplicates the : in the middle: (it actually duplicates itself):
'rd3*9[r::r]>o<
Then since there are now 2 duplication signs it will duplicate itself twice:
'rd3*9[r::::r]>o<
etc. doubling each time.
><> (Fish), 9 bytes (Boring version)
':rd3*>o<
This simply duplicates the < at the end:
':rd3*>o<<
':rd3*>o<<<
etc. So the functionality of the program won't be effected at all. It's basically a comment.
Pushy, 7 bytes
95&34_"
Non-competing as the language postdates the challenge. This outputs:
95 95 34
__"
which in turn outputs:
95 95 34
95 95 34
__"
and so on. After ~5 runs it looks like this:
95 95 34 95 95 34 95 95 34 95 95 34
95 95 34 95 95 34 95 95 34 95 95 34
__"__"__"__"
95 95 34 95 95 34 95 95 34 95 95 34
95 95 34 95 95 34 95 95 34 95 95 34
__"__"__"__"
k
41 bytes
f:{{(2*#x)#x}"f:",x,";`0:f@$f;"};`0:f@$f;
This program prints a copy of itself, and then doubles it. Thus it grows.
33 bytes
`0:{,//$("`0:";o;"[";x;"1];")}[1]
This program prints itself, but with an ever-growing number as the argument. This works in the closed-source interpreter.
Alice, 14 bytes
" <@o&h:2d+2..
Subsequent versions will have an increasing number of spaces after the ".
Explanation
" <@o&h:2d+2.." Push the code points of the source code, except for the
quotation marks.
< Send the IP back west.
"..2+d2:h&o@< " Push the code points of the source code, except for the
quotation marks, in reverse.
.. Make two copies of the space. One will be the additional
space, one will be turned into the quotation mark.
2+ Add two, to turn 32 (space) into 34 (quote).
d Push the stack depth. This is about twice the number of characters
we want to print, because there's still the first copy of the source
on the stack. But it's two less than twice that number, because the
additional space and the quote aren't duplicated.
2: Halve the value.
h Increment to account for the space and quote.
& Repeat the next command that many times.
o Print that many characters from the top of the stack.
@ Terminate the program.
Python 3, 54 chars
print((lambda s:s%s)('print((lambda s:s%%s)(%r)*2);'))
I simply modified this quine.
You can try it simply doing python this.py | python | python ... | python many times.
Edit: found this problem on the homepage and discovered too late that it is old.
-
1\$\begingroup\$ There's no issue solving old challenges. \$\endgroup\$Christopher King– Christopher King2019年07月16日 00:39:32 +00:00Commented Jul 16, 2019 at 0:39
C (gcc), 132 bytes
It's not often you get to recycle answers from other questions.
x;*s="x;*s=%c%s%c;main(i){for(i=__LINE__;i--;puts(&x));printf(s,34,s,34);}";main(i){for(i=__LINE__;i--;puts(&x));printf(s,34,s,34);}
Haskell, 155 bytes
g=putStrLn("n=1"++show n++('-'<$[1..n]));main=(\s->putStr s>>print s>>g)$"g=putStrLn(\"n=1\"++show n++('-'<$[1..n]));main=(\\s->putStr s>>print s>>g)$"
n=2
W, 15 bytes
A proper quine, except it grows very oddly.
pp34CS+"pp34CS+
Iterations (You can see that the output gets between and after the source code... ):
pp34CS+pp34CS+"pp34CS+
pp34CS+pp34CS+pp34CS+pp34CS+"pp34CS+pp34CS+
C (gcc), 71 bytes
#define a(b)*s=#b;b
a(main(){printf("#define a(b)*s=#b;b\na(%s;)",s);})
Every iteration adds a semicolon after the closing brace of the main function.
Lua, 58 bytes
f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))
Attempt This Online! Repeats the formatted string 9 times. This is the result of iteration 1:
f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))f="f=%qprint(f:format(f):rep(9))"print(f:format(f):rep(9))
:^)\$\endgroup\$