130
\$\begingroup\$

You are to write a program that will output source code that is

  1. Larger than the original program (character wise)
  2. 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.

\$\endgroup\$
11
  • 5
    \$\begingroup\$ @Kevin, The definition is recursive. The output should be a program whose output is larger than itself, and an answer to this question. So the output's output should be larger than the output, and the output's output's output should be even larger, etc. \$\endgroup\$
    – ugoren
    Commented Feb 23, 2014 at 10:55
  • 8
    \$\begingroup\$ I think you should clarify your rules. On one hand, any additional code output by such a program is "obviously useless"; on the other hand, all additional code in the output is "useful" in that it furthers the goal of answering this challenge. \$\endgroup\$
    – Jason C
    Commented Feb 23, 2014 at 22:29
  • 6
    \$\begingroup\$ Sorry for destroying your challenge. :^) \$\endgroup\$
    – Justin
    Commented Feb 24, 2014 at 5:03
  • 44
    \$\begingroup\$ Naturally, such a program should be known as a quinine. \$\endgroup\$ Commented Feb 25, 2014 at 5:05
  • 2
    \$\begingroup\$ @facepalm42 Quine challenge answers are forbidden from reading their own source code, which makes comments tricky to use here. \$\endgroup\$ Commented Nov 9, 2019 at 1:02

64 Answers 64

1 2
3
0
\$\begingroup\$

DipDup, 12 bytes

[[_^!]:_:]_:

Try it online!

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.

\$\endgroup\$
0
\$\begingroup\$

Python 2, 31 bytes

s='s=%r;print s%%s*2;';exec s%s

Try it online!

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)

Try it online!

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);
# ------------
...
\$\endgroup\$
0
\$\begingroup\$

Rust, 61 bytes

fn main(){print!("const _:()=();{}",include_str!("main.rs"))}

Is it cheating to use include_str!? :P In any case, it just keeps adding a dummy constant, growing the program larger every time.

\$\endgroup\$
1
0
\$\begingroup\$

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())

//...

\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.