134
\$\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.

DialFrost
5,1892 gold badges15 silver badges58 bronze badges
asked Feb 23, 2014 at 2:43
\$\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\$ 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\$ Commented Feb 23, 2014 at 22:29
  • 6
    \$\begingroup\$ Sorry for destroying your challenge. :^) \$\endgroup\$ Commented Feb 24, 2014 at 5:03
  • 45
    \$\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

63 Answers 63

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.

answered May 5, 2022 at 7:43
\$\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);
# ------------
...
answered Oct 7, 2021 at 8:05
\$\endgroup\$
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())
//...

answered Jan 27, 2023 at 11:18
\$\endgroup\$
1 2
3

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.