Program that creates larger versions of itself (quine-variant)
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 9
s 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
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.
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