7
\$\begingroup\$

Write a program, in a language of your choice, that will compose a quine program of a requested size. The generated program may be in the same or a different language, if desired.

Programs are scored based on the following formula:

generating_program_length + smallest_supported_size + 512 * number_of_supported_sizes ^ (-3/4)

Halve your score if you support every size between the minimum and maximum supported sizes.

Lowest score wins.

\$\endgroup\$
5
  • \$\begingroup\$ Also, to explain the rather complicated scoring criteria, the point is to ensure trivial "any color as long as it's black" solutions don't work, and to encourage solutions that tend toward supporting all the numbers possible, without penalizing more limited solutions too harshly. \$\endgroup\$ Dec 19, 2013 at 1:44
  • \$\begingroup\$ so wait... more possible supported sizes is penalized?! \$\endgroup\$
    – Doorknob
    Dec 19, 2013 at 1:48
  • \$\begingroup\$ @DoorknobofSnow Sorry, fixed it. \$\endgroup\$ Dec 19, 2013 at 1:51
  • 2
    \$\begingroup\$ Perhaps a little late, but I think there should be a significant bonus here for programs that produce the quines in their own language. Otherwise, everyone's going to be writing quine generators for HQ9+ or languages where quining is similarly simple. \$\endgroup\$
    – Iszi
    Dec 19, 2013 at 15:33
  • \$\begingroup\$ @Iszi I think you're right, also I have another possible change that could eliminate trivial quining solutions: output must not contain any matches of the regex (.+)\1. \$\endgroup\$ Dec 19, 2013 at 23:24

7 Answers 7

9
\$\begingroup\$

GolfScript → GolfScript: (4 + 0 + 0) / 2 = 2

~1`*
  • Program length: 4
  • Minimum supported size: 0
  • Maximum supported size: unbounded
  • All sizes supported: yes

This program simply reads an integer n from its input, and outputs an n-digit integer consisting of n 1 digits. For example, the input 5 yields the output 11111. In GolfScript, any integer literal (without leading zeros) is a quine, and since GolfScript integers can be arbitrarily large, the maximum supported length is only bounded by the amount of memory available.

For the input 0, the code outputs an empty program, which is also a quine in GolfScript.

Ps. The generated quines work for several other languages too, including PHP.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Damn Golfscript and its arbitrary precision. I was going to do the same in PowerShell, but it falls back to scientific notation after a point. Does PHP support arbitrary precision by default also? \$\endgroup\$
    – Iszi
    Dec 19, 2013 at 15:24
  • \$\begingroup\$ @Iszi: No, but PHP will echo back verbatim anything outside <? ?> tags. \$\endgroup\$ Dec 19, 2013 at 15:29
  • \$\begingroup\$ Ah. For PowerShell you'd have to force the integer to a string with quotes if it's too big, at which point that alone is no longer a quine. \$\endgroup\$
    – Iszi
    Dec 19, 2013 at 15:30
  • \$\begingroup\$ Beat me to it in APL, and smaller \$\endgroup\$
    – TwiNight
    Dec 19, 2013 at 23:53
  • \$\begingroup\$ The first character ~ is not even necessary. For me, 1`* works perfectly. \$\endgroup\$
    – ProgramFOX
    Dec 21, 2013 at 18:54
4
\$\begingroup\$

Ruby -> JavaScript, 38

45 character program
31 smallest supported size
Infinity possible sizes
Supports any size in range
(45 + 31 + 512 * Infinity ^ -3/4) / 2 = 38

"function f(){alert(f+'f()')#{?;*(i-31)}}f()"

GolfScript -> JavaScript, 37.5

1 char less :P

"function f(){alert(f+'f()')"";"i 31-*"}f()"

Example output for i = 31:

function f(){alert(f+'f()')}f()

For i = 41:

function f(){alert(f+'f()');;;;;;;;;;}f()

The output quines work on latest Chrome (31.0.1650.63), at least. (Untested for any other browser)

\$\endgroup\$
9
  • \$\begingroup\$ Sorry, fixed it, I meant the exponent to be negative. \$\endgroup\$ Dec 19, 2013 at 1:50
  • \$\begingroup\$ @AJMansfield Yay, now I have a score of negative infinity :P Impossible to beat! \$\endgroup\$
    – Doorknob
    Dec 19, 2013 at 1:51
  • 1
    \$\begingroup\$ No. 512 * x^(-3/4) tends toward 0 as x increases without bound. \$\endgroup\$ Dec 19, 2013 at 1:52
  • \$\begingroup\$ @AJMansfield Whoops, I fail at math. Fixed \$\endgroup\$
    – Doorknob
    Dec 19, 2013 at 1:52
  • 2
    \$\begingroup\$ +1 Solving the problem with "real" programming languages instead of taking advantage of esoteric languages. I'm impressed! \$\endgroup\$
    – Kevin
    Dec 19, 2013 at 6:23
3
\$\begingroup\$

Ruby or GolfScript -> HQ9+, 6

11 character program
1 smallest supported size
Infinity possible sizes
Supports any size in range
(11 + 1 + 512 * Infinity ^ -3/4) / 2 = 6

?Q+?+*(i-1)

Same size program written in GolfScript:

"Q""+"i 1-*

Example output for i = 1:

Q

For i = 10:

Q+++++++++
\$\endgroup\$
3
\$\begingroup\$

Python 2 - 62.6 points

s='s=%r;print(s%%s+s*99)[:input()]#';print(s%s+s*99)[:input()]

This code is both the generator and the core of the quine. It expects you to provide a length on standard input, and prints to standard output a version of itself of that length (larger sizes get a trailing comment full of junk).

So, if you pass it 62, it prints itself (this is the minimum size). If you call it with some longer length (up to the maximum length of 3231), it will produce output of that length. Any version will be a quine if passed its own length.

The length limit was the result of my attempts at minimizing the number of characters used. Supporting more lengths was costing more in points for code length than it was reducing the penalty for a limited range. It's not hard to make a variant that will work for unlimited sizes, but it will need to be longer by about 20 characters (and so score worse).

Note that requesting a shorter length than 62 will produce output of the desired size, but that output will not be working code. Passing a larger length than 3231 will produce the 3231-character version of the quine. Passing something other than an integer will raise an exception.

Scoring:

  • Generator length: 62 characters, 62 points
  • Minimum quine size: 62 characters, 62 points
  • Number of supported sizes: 3169, 1.2 points
  • All sizes between minimum and maximum accepted: Half off all points above.
  • Total: (62+62+1.212)/2 = 62.6 points
\$\endgroup\$
1
  • \$\begingroup\$ Deserves +10 for not trying to dodge the rules by using dummy languages. \$\endgroup\$ Dec 20, 2013 at 1:28
3
\$\begingroup\$

Befunge 98 - (14 + 0 + 0) / 2 = 7

'1&k:$$>,:# _@

Output is in HQ9+ Golfscript (Thanks to Ilmari)

Output for 0:


Output for 1:

1

Output for 10:

1111111111

Explanation:

'1             ;push the character `'1'` onto the stack
  &            ;get the inputted number (`n`), push on stack
'1&k:          ;duplicate the `'1'`, `n + 1` times, leaving `n + 2` of `'1'` on the stack
'1&k:$$        ;drop the top two `'1'`s on the stack
       >,      ;print the top element of the stack
       >,:# _  ;duplicate the next, then check if it is `0`.
             @ ;if it is `0`, execute this, which ends the program.
        , # _  ;otherwise, go back the other way and continue printing
       >       ;turn back to the right.
'1&k:$$>,:# _@
\$\endgroup\$
0
0
\$\begingroup\$

Ruby -> Ruby (79 points)

char: 51
min size: 28
max size: infinite
(0..num){|x|print "eval s=\"print 'eval s=';p s\""}

\$\endgroup\$
-2
\$\begingroup\$

Golf-Basic 84 -> Golf-Basic 84

(54 + 0 + 0) / 2 = 27

  • Program length: 54
  • Minimum supported size: 0
  • Maximum supported size: none
  • All sizes supported: yes

Only limited by the calculator's RAM.

i`A:""_Str1:"1"_Str2l`1:A--A:Str1+Str2_Str1@Ag`1d`Str1
\$\endgroup\$

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.