| Bytes | Lang | Time | Link |
|---|---|---|---|
| 027 | Ruby | 140223T163542Z | daniero |
| 3327 | JavaScript | 230127T111821Z | EzioMerc |
| 014 | ><> Fish | 230104T093006Z | mousetai |
| 001 | Batch | 221220T062937Z | l4m2 |
| 031 | Python 2 | 211007T080515Z | Jakque |
| 012 | DipDup | 220505T074348Z | alephalp |
| 033 | Julia 1.0 | 220504T085310Z | MarcMush |
| 019 | Wolfram Language Mathematica | 220503T171321Z | Romanp |
| 006 | Microscript II | 161112T011948Z | SuperJed |
| 058 | Lua | 220323T211915Z | twentysi |
| 071 | C gcc | 211007T222622Z | Petr Fie |
| 012 | JavaScript ES6/2015 | 211006T124621Z | Petr Fie |
| 011 | Husk | 201006T073459Z | Jo King |
| 004 | Jelly | 201006T042359Z | Unrelate |
| 012 | Japt | 200630T090416Z | Mukundan |
| 034 | Python 2 | 200118T113543Z | Mukundan |
| 015 | W | 191127T142153Z | user8505 |
| 006 | Keg | 191108T060745Z | lyxal |
| 014 | Bash | 190906T060030Z | mekb |
| 9981 | Evoloop | 190906T022834Z | Sophie S |
| 155 | Haskell | 190811T010450Z | B. Mehta |
| 009 | Underload | 190729T201225Z | Edgex42 |
| 132 | C gcc | 190716T065459Z | gastropn |
| 054 | Python 3 | 190715T001126Z | Andrea C |
| 020 | AsciiDots | 190714T202620Z | Alion |
| 006 | Runic Enchantments | 190214T034353Z | Draco18s |
| 005 | Gol><> | 190210T224357Z | KrystosT |
| 038 | Befunge98 FBBI | 181228T121416Z | Wisław |
| 001 | J | 180907T055027Z | Bubbler |
| 000 | GS2 8636bd8e | 161017T215448Z | Dennis |
| 092 | Java 8 | 180320T162844Z | Kevin Cr |
| 189 | C | 170525T014832Z | MD XF |
| 099 | shortC | 170525T173350Z | MD XF |
| 032 | Charcoal | 170520T003306Z | Destruct |
| 014 | Alice | 170413T185103Z | Martin E |
| nan | 170413T161611Z | zgrep | |
| 001 | Help | 161216T212355Z | n4melyh4 |
| 007 | Pushy | 161216T210711Z | FlipTack |
| 083 | OIL | 161115T084724Z | L3viatha |
| 040 | JavaScript | 140225T011819Z | DocMax |
| 015 | 05AB1E | 161111T062552Z | Oliver N |
| 011 | reticular | 161018T002720Z | Conor O& |
| 011 | dc | 140223T200319Z | daniero |
| 066 | Julia | 150630T004133Z | M L |
| 001 | H9+ | 140223T053511Z | Justin |
| 006 | PYG | 140422T171952Z | ɐɔıʇǝɥʇu |
| nan | 140323T165225Z | Thomas B | |
| 046 | Javascript | 140226T143918Z | ˈvɔlə |
| 016 | Common Lisp | 140226T022007Z | Stuart O |
| 038 | ECMAScript 6 38 Characters | 140225T004129Z | MT0 |
| nan | 140224T164935Z | Daniel | |
| 029 | Lambda Calculus | 140224T160233Z | daniel g |
| 007 | SH script | 140224T005008Z | Jens Era |
| 057 | Smalltalk | 140223T123409Z | blabla99 |
| 000 | Java 7 | 140223T175943Z | Justin |
| 009 | SH script | 140223T224501Z | Jason C |
| 025 | Windows .BAT | 140224T000218Z | Jason C |
| 026 | BATCH | 140223T234445Z | SameOldN |
| 055 | Python 3 | 140223T202854Z | user1547 |
| 038 | PHP | 140223T154912Z | ComFreek |
| 009 | GolfScript | 140223T140018Z | Ilmari K |
| 051 | EcmaScript 6 | 140223T102826Z | Toothbru |
| 002 | HQ9+ | 140223T024844Z | Victor S |
Ruby 27
A very slightly modified version of this (via):
puts <<3*3,3
puts <<3*3,3
3
The number of times that puts-line is printed grows exponentially.
$ ruby quine.rb | ruby | ruby
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
puts <<3*3,3
3
$ ruby quine.rb | ruby | ruby | ruby | ruby | ruby | ruby | ruby | wc -l
3283
JavaScript, 33 bytes (27 if alert)
f=_=>console.log(`f=${f};f(f())`)
Try it:
console.log('First execution');
f=_=>console.log(`f=${f};f(f())`)
f();
console.log('After prev execution');
f=_=>console.log(`f=${f};f(f())`);f(f())
console.log('After prev execution');
f=_=>console.log(`f=${f};f(f())`);f(f())
f=_=>console.log(`f=${f};f(f())`);f(f())
console.log('After prev execution');
f=_=>console.log(`f=${f};f(f())`);f(f())
f=_=>console.log(`f=${f};f(f())`);f(f())
f=_=>console.log(`f=${f};f(f())`);f(f())
f=_=>console.log(`f=${f};f(f())`);f(f())
//...
><> (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.
Batch, 1 byte
a
Add prompt at head every time, error is who cares
Python 2, 31 bytes
s='s=%r;print s%%s*2;';exec s%s
the next iterations are:
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
# ------------------------------------
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
# -------------------------------------
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
s='s=%r;print s%%s*2;';print s%s*2;s='s=%r;print s%%s*2;';print s%s*2;
# ------------
...
Python 3, 33 bytes
a='a=%r;print(a%%a*2);';exec(a%a)
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
# ------------------------------------
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
# -------------------------------------
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
a='a=%r;print(a%%a*2);';print(a%a*2);a='a=%r;print(a%%a*2);';print(a%a*2);
# ------------
...
DipDup, 12 bytes
[[_^!]:_:]_:
The TIO link is the DipDup interpreter written in Haskell.
Based on my DipDup quine: [_:]_:. [_^!]: converts a block [abc] to [[abc]_^!], which is equivalent to [abc] but longer.
This outputs [[_^!]:_:][_^!]:_:. After that, [abc]abc becomes [[abc]_^!][abc]_^! in each step.
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]
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.
Microscript II, 6 bytes
"qp"qp
The first iteration adds an extra qp to the end, and each successive iteration adds an extra copy of this original program to the beginning.
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))
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.
JavaScript (ES6/2015), 12 bytes
a=_=>'a=_'+a
with invokation, 23 bytes
(a=_=>'(a=_'+a+')()')()
Every iteration adds an underscore to the parameter name
Husk, 15 11 bytes
-4 bytes thanks to Unrelated String
S+s"So+uswg
Outputs So+uswg"So+uswg" then S o+uswg"S o + u s w g" then S o+uswg"S o + u s w g"... This is a variant of the usual quine S+s"S+s" but with increasing spaces between each character in the string. Currently there's a bug in the parser that prevents double spaces in the code itself, otherwise this could forgo the unique stripping out spaces in the code section and could be 9 bytes.
Jelly, 4 bytes
⁾ṘȮv
Originally written for a CMC in JHT.
⁾ṘȮ "ṘȮ"
v evaluated with the argument
⁾ṘȮ "ṘȮ".
Ṙ Print a Jelly string representation of the argument,
Ȯ print the argument,
then implicitly print it again.
Japt, 12 bytes
"iQ ²Ä"iQ ²Ä
Based off the Standard Japt quine
Explanation
For first iteration
"iQ ²Ä" // Take this string. iQ ²Ä
iQ // Insert a quote. "iQ ²Ä
² // Double. "iQ ²Ä"iQ ²Ä
Ä // Concatenate 1 to end "iQ ²Ä"iQ ²Ä1
// Implicitly output.
On Each iteration it will concatenate another 1 to the end of the program
Python 2, 38 37 36 34 bytes
-1 bytes thanks to Jo King
s='print"s=%r;exec s;"%s+s';exec s
Python 3.8 (pre-release), 39 38 36 bytes
exec(s:='print("exec(s:=%r);"%s+s)')
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+
Keg, 18 15 14 13SBCS 11 10SBCS 9SBCS 6SBCS bytes
`④⑩`④⑩
I've gone and done it now! No more ascii around here now folks. This will print:
`④⑩`④⑩④⑩
Which will print:
`④⑩`④⑩`④⑩`④⑩④⑩
Which prints:
`④⑩`④⑩`④⑩`④⑩`④⑩`④⑩④⑩④⑩
And so on.
Answer History
9 bytes
`::.,`⑵④⑩
This uses the same approach as the 10 byte answer
Explained
`::.,`⑵④⑩
`::.,` #Push the string `::.,`
⑵ #Double the string
④⑩ #Print raw then nice without popping
10 bytes
`::.,`⑵:.,
This prints:
`::.,::.,`::.,::.,
Which prints:
`::.,::.,`::.,::.,`::.,::.,`::.,::.,
11 bytes
`::.,`6*:.,
This prints:
`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,
Which prints:
`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,`::.,::.,::.,::.,::.,::.,
And so on
13 bytes
`::.,`!⑨*:(.,
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.
Evoloop, 9×9 rectangle (81 cells)
The Evoloop cellular automaton included with Golly supports patterns which replicate themselves in a "quine-like" way. Specifically, these patterns each contain a "program"; a pattern reproduces itself by first executing the program (which creates the "body" of the daughter), and then by copying the program into the daughter.
The above applies to the more famous "Langton's Loops" cellular automaton as well as Evoloop, but Evoloop has an interesting difference, which is that it's easy to create a pattern which grows in each successive generation.
(Much more interesting, in my opinion, is the fact that Evoloop is a simple cellular automaton which contains patterns which reproduce themselves and evolve in a very life-like manner! I think the only known cellular automata which do this are Evoloop and its descendants. A shortcoming of Evoloop, however, is that there is one particular "best" genome; evolution always eventually converges to this one genome.)
Now, there are two shortcomings to this submission. One is that it's not clear what the "output" of a cellular automaton is. But I think that a self-reproducing automaton is "close enough" to being a quine; it's certainly no less interesting! The other shortcoming is that these patterns don't merely create a single copy of themselves; each copy of the original pattern attempts to create infinitely many copies of itself, and these copies end up interacting with each other in a destructive manner. So, I think I've met the requirements of this challenge in spirit, but not in letter.
Without further ado, the pattern is:
022222220
270170172
212222202
202000212
272000272
212000202
202222212
271041032
022222250
Here's the pattern again, in a format that can be copied and pasted into Golly:
x = 9, y = 9, rule = Evoloop
.7B$BG.AG.AGB$BA5B.B$B.B3.BAB$BGB3.BGB$BAB3.B.B$B.5BAB$BGA.DA.CB$.6BE
!
Okay, but what does it look like? It looks like this:
In the above animation, you can see the initial pattern create a larger daughter, which creates a larger granddaughter, then a larger great-granddaughter, and finally an even larger great-great-granddaughter which starts to construct a yet larger third-great-granddaughter. If you ran this pattern for a long time, it would keep going on like this forever (or perhaps they would eventually be overtaken by the evolved organisms, which are capable of reproducing much faster; I'm not sure).
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
Underload, 9 bytes
(:::aSSS):^
Modification on the standard underload quine, which is (:aSS):aSS. First, I changed the second :aSS into :^ since it still runs the same code (by duplicating and then running the top item of the stack, which is the stuff inside the bracket) whilst saving bytes. Then I added another S to make it so the program gets longer, and added two more :s to make it so the program it produces doesn't error.
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);}
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.
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#"$_@("_$-.
Runic Enchantments, 6 bytes
"'<S@>
This one was weird. All I had to do was remove a ~ from the original quine found by Jo King.
Every additional run appends another < to the end, e.g.:
"'<S@><<<<<<<<<
All of which do nothing.
Gol><>, 5 bytes
#H}"'
This, I believe, is the smallest growing quine possible in Gol><>. It duplicates the #H} over and over...
J, 1 byte
'
The open quote gives, obviously, the open quote error:
|open quote
| '
| ^
|[-1] /home/runner/.code.tio
Note that, by the nature of J interpreter, the errors are printed to STDOUT, not STDERR.
When the above is run as code, it prints:
|open quote
| | '
| ^
|[-2] /home/runner/.code.tio
Then
|open quote
| | | '
| ^
|[-2] /home/runner/.code.tio
and so on. Each time the code runs, the second line is left-padded with four bytes | , fulfilling the requirement of this challenge.
J, proper quine variant, 25 bytes
echo,~'echo,:~(,quote)'''
Outputs
echo,:~(,quote)'echo,:~(,quote)'
And then it outputs itself twice, on separate lines:
echo,:~(,quote)'echo,:~(,quote)'
echo,:~(,quote)'echo,:~(,quote)'
then
echo,:~(,quote)'echo,:~(,quote)'
echo,:~(,quote)'echo,:~(,quote)'
echo,:~(,quote)'echo,:~(,quote)'
echo,:~(,quote)'echo,:~(,quote)'
and so on.
The first output is a simple variant of standard J quine. The added ,:~ concatenates itself vertically, where the resulting 2D array is printed as two rows of the same string.
GS2 (8636bd8e), 0 bytes
This prints a single newline, which prints two newlines, which prints three newlines, et cetera.
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.
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.
shortC, 99 bytes
i;ARa="i;ARa=%c%s%c,34,a,34,i+2);Oi=%d;i--;)",34,a,34,i+2);Oi=2;i--;)Ra="Ra=%c%s%c,34,a,34",34,a,34
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
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.
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.
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).
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
__"__"__"__"
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.
JavaScript, 41, 40 chars
function f(){console.log(f+"f(f())")}f()
The first time you run it it outputs itself with another ;f() at the end. Subsequent runs of the output results in each "input" source printed twice.
alert would be shorter than console.log but I don't consider multiple alert dialogs to be "the" output while it seems reasonable to call multiple lines in the console as an output.
05AB1E, 15 bytes, noncompeting
0"DÐ34çý"DÐ34çý
Prints 0"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý,
which prints 0"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý"DÐ34çý,
etc.
reticular, 11 bytes, noncompeting
"'34'coo1o;
This is the standard quine framework, except an extra 1 is printed after each iteration. Try it online!
First few outputs:
"'34'coo1o;
"'34'coo1o;1
"'34'coo1o;11
"'34'coo1o;111
dc 11
Quite simple:
6579792
dfP
The first line is repeated once every generation:
$ dc growing_quine.dc
6579792
6579792
dfP
$ dc growing_quine.dc | dc | dc
6579792
6579792
6579792
6579792
dfP
The last line consists of the following instructions: d duplicates the last value put on the stack (6579792) (so that we get one more copy each time we run it), f prints the whole stack (which is a bunch of that same number) and P prints the number (6579792) out as a byte stream, which displays as dfP.
Julia, 66 chars
x="print(\"x=\$(repr(x))\\n\$x;\"^2)";print("x=$(repr(x))\n$x;"^2)
Output (134 chars):
x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);
Result of executing the result (268 chars):
x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);
next result (536 chars):
x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);
Next result (1072 chars):
x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);x="print(\"x=\$(repr(x))\\n\$x;\"^2)"
print("x=$(repr(x))\n$x;"^2);
I hope this is according to the rules.
It produces larger output, and the output itself is valid source code that produces larger output again.
H9+ : 1 char
9
That's right. One character. Outputs the lyrics to 99 bottles of beer, which is a valid program. All the extraneous data does not count, but there are plenty of 9s in there.
The output of the outputted program is the lyrics to 99 bottles of beer 59 times.
This function gives the number of times the lyrics are outputted if you run the program n times (if my calculation is correct):
f(n) = 59n-1
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.
redcode (recursive solution)
This is the code of the easiest warrior writable in redcode, the famous Imp:
MOV 0, 1
When executed, the code writes a copy of its single instruction at the next address in memory; then executes it, etc.
Javascript - 46
(function $(){console.log('('+$+'());$()')}())
Common Lisp, 16 Characters
(print `(or ,-))
Granted, it's interactive-only, but being able to reference the current top-level form is probably the single best way to minimize a non-trivial program that meets the specification.
What would be really interesting is what blows up the fastest. Maybe something like
(print `(progn ,@(loop repeat (length -) collect -)))
ECMAScript 6 (38 Characters)
(f=_=>'(f='+f+')();(f='+f+')();')();
Which outputs:
(f=_=>'(f='+f+')();(f='+f+')();')();(f=_=>'(f='+f+')();(f='+f+')();')();
Edit
You could do (28 characters):
(f=_=>'(f='+f+')();'+f())();
However it will recurse infinitely and never return anything... but this can be solved by doing something like this (42 characters):
(f=_=>_?'(f='+f+')('+_+');'+f(_-1):'')(3);
Which will output:
(f=_=>_?'(f='+f+')('+_+');'+f(_-1):'')(3);(f=_=>_?'(f='+f+')('+_+');'+f(_-1):'')(2);(f=_=>_?'(f='+f+')('+_+');'+f(_-1):'')(1);
Batch
set d=time
copy c:\>loop.bat /B loop%d%.bat
call c:\>loop.bat
Lambda Calculus - 29
A simple lambda term
(λu.(u u)(u u))(λu.(u u)(u u))
Reducing this term by one beta reduction yields
((λu.(u u)(u u))(λu.(u u)(u u)))((λu.(u u)(u u))(λu.(u u)(u u)))
And so on and so on. It's a simple variant on the classic (λu.u u)(λu.u u) which is a quine in lambda calculus, double self application here means we get twice the output.
SH script, 12 8 7
Store a file with
sed p *
in its own, empty directory and run from this directory using sh [file] or set executable.
Old alternative with 8 characters, but doesn't need its own directory. Store a file with
sed p $0
and run using sh [file] or set executable.
Old alternative with 12 characters:
sed -i- p $0
This will actually output to the program file itself, but where to output was not specified. Replicates itself at an exponential rate.
Smalltalk, 125 61 57
The golf version looks almost unreadable so I'll explain first (and use real identifiers).
This is a variant of the "weirdest-way-to-produce-a-stack-overflow" self modifying method.
The method prints out a hello message, and its current source (for the demonstration only). Then, the code is modified to output a longer string and installed. Finally, the new code is called recursively.
In order to protect myself from an immediate runaway, it lets the user confirm in each cycle.
compile in Object:
eatMe_alice
|msg mySource|
mySource := thisContext method source.
'**** Hello Alice' printCR.
' ---- my current code is:' printCR.
mySource printCR.
' ---------------' printCR.
(UserConfirmation confirm:'Again? ') ifTrue:[
Object compile:
(mySource
copyReplaceString:'Hello ','Alice'
withString:'Hello ','Alice !').
self eatMe_alice
]
start the show by sending "eatMe_alice" to any Object; nil will do:
nil eatMe_alice
A nice variant is to not call the new code recursively, but instead iteratively, by unwindig the call stack and reentering into the new method. This has the advantage of not leading to a recursion exception. To do this, replace the recursive call ("self eatMe_alice") by:
thisContext resend
Golfing:
Obviously, printing and self calling was not asked for, so the shortest (for golf) is to simply append a comment to my own source and return it. As a side effect, it also gets installed for the next call...
x|s|Object compile:(s:=thisContext method source,'""').^s
Java 7: 0 chars
Save as file Blank.java. If you save it as any other file, replace any instance of Blank with the appropriate file name.
Then, run in command line via first compiling, then running. If compiling fails, stop.
I list this as Java 7 because it might output differently for different versions of Java.
First few outputs (outputted to stderr):
Error: Could not find or load main class Blank
Blank.java:1: error: class, interface, or enum expected
Error: Could not find or load main class Blank
^
Blank.java:1: error: reached end of file while parsing
Error: Could not find or load main class Blank
^
2 errors
Blank.java:1: error: class, interface, or enum expected
Blank.java:1: error: class, interface, or enum expected
^
Blank.java:1: error: expected
Blank.java:1: error: class, interface, or enum expected
^
Blank.java:1: error: expected
Blank.java:1: error: class, interface, or enum expected
^
Blank.java:1: error: as of release 5, 'enum' is a keyword, and may not be used as an identifier
Blank.java:1: error: class, interface, or enum expected
^
(use -source 1.4 or lower to use 'enum' as an identifier)
Blank.java:1: error: = expected
Blank.java:1: error: class, interface, or enum expected
^
Blank.java:2: error: expected
Error: Could not find or load main class Blank
^
Blank.java:2: error: ';' expected
Error: Could not find or load main class Blank
^
Blank.java:2: error: = expected
Error: Could not find or load main class Blank
^
Blank.java:2: error: = expected
Error: Could not find or load main class Blank
^
Blank.java:2: error: expected
Error: Could not find or load main class Blank
^
Blank.java:3: error: = expected
^
^
Blank.java:3: error: ';' expected
^
^
Blank.java:4: error: illegal start of type
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: = expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: illegal start of type
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: = expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: illegal start of type
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: = expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: ';' expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: = expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: = expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:4: error: ';' expected
Blank.java:1: error: reached end of file while parsing
^
Blank.java:5: error: expected
Error: Could not find or load main class Blank
^
Blank.java:5: error: ';' expected
Error: Could not find or load main class Blank
^
Blank.java:5: error: = expected
Error: Could not find or load main class Blank
^
Blank.java:5: error: = expected
Error: Could not find or load main class Blank
^
Blank.java:5: error: expected
Error: Could not find or load main class Blank
^
Blank.java:6: error: = expected
^
^
Blank.java:6: error: ';' expected
^
^
Blank.java:7: error: reached end of file while parsing
2 errors
^
30 errors
SH script, 9
cat $0 $0
Grows at exponential rate.
Either run as sh whatever.sh or set it as executable.
Windows version is here.
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
Python 3 - 55
print(open(__file__).read())
f=lambda:print('f()')
f()
This could be made shorter by replacing __ file__ with a single character filename and saving the file as that, but I felt this answer was more in the spirit of the question. After one iteration it outputs:
print(open(__file__).read())
f=lambda:print('f()')
f()
f()
PHP, 38
<?echo fgets(fopen(__FILE__,'r')).';';
It will add a semicolon at each run.
GolfScript, 9 chars
{.'.~'}.~
This code outputs:
{.'.~'}{.'.~'}.~
which outputs:
{.'.~'}{.'.~'}{.'.~'}.~
which outputs:
{.'.~'}{.'.~'}{.'.~'}{.'.~'}.~
and so on.
I believe this is the shortest answer in a "real" Turing-complete programming language so far.
Explanation:
Basically, the original code above is a "quine-layer": it outputs a normal quine followed by itself.
In GolfScript, any code block literal (e.g. {foo}), if left undisturbed on the stack, is a quine. Thus, on its own, {.'.~'} simply outputs itself, just like any other code block would.
The .~ at the end of the code takes the last code block on the stack, duplicates it, and executes the copy. When executed, the code .'.~' inside the code block duplicates the topmost item on the stack (i.e. the copy of itself) and appends the string .~.
At the end of the program, the GolfScript interpreter stringifies and outputs everything on the stack, which, in this case, consists of one more {.'.~'} block than in the input, plus the string .~.
Bonus:
Adding a ] before the first . (to collect all the code blocks on the stack into an array before they're duplicated) makes it grow exponentially:
{].'.~'}.~
outputs:
{].'.~'}{].'.~'}.~
which outputs:
{].'.~'}{].'.~'}{].'.~'}{].'.~'}.~
which outputs:
{].'.~'}{].'.~'}{].'.~'}{].'.~'}{].'.~'}{].'.~'}{].'.~'}{].'.~'}.~
and so on.
EcmaScript 6 (51 bytes):
(_=x=>'(_='+_+Array(x++).join(','+_)+')('+x+')')(2)
It produces a longer version of itself, which can produce a longer version of itself, which can produce a longer version of itself, etc. ...
HQ9+, HQ9++ and similars, 2 characters
QQ
This is the output:
QQQQ
