Make an almost quine

12

I wanted to fool a friend by giving him a quine that almost worked, but became sloppier and sloppier.

Create a program that, when run, will output the program, but one character off. Either one character can be added, removed or both (one character changes). But only one character.

Your score will be (length of your program) / floor(sqrt(number of times the program almost quines)) (Where / 0 is infinity)

number of times the program almost quines is how many times your program runs while only changing one character in stdout. Your program may not accept input. It may also not print a program it has already printed.

You may also not add a character that you have previously added before, or remove a character from the same index. For example, if you have added 1 before, and you add 1 again, that's where the number of times the program almost quines stops. If you remove the first character, you may not remove the first character again. If you changed the third character into a 2, you may not add a 2 or remove the third character.

user34736

Posted 2015-05-03T21:08:53.877

Reputation:

whats a quine ? – Abr001am – 2015-05-04T16:35:58.470

@Agawa001 A quine is a program that prints itself.

– None – 2015-05-04T16:38:02.360

Answers

7

CJam, 0.000884

{_,6/[{64md}6*](124+\+'�f++`"1$~"}""1$~

Here, � denotes the unprintable character with code point 128. Try it online.

Idea

This approach appends all UCS characters (original specification) with code points between U+4000000 and U+7FFFFFFF to the initially empty string that follows the code block.

We choose UTF-8, which encodes each of these characters using a 6 byte string as follows:

1111110u₂     10vvvvvv₂     10wwwwww₂     10xxxxxx₂     10yyyyyy₂     10zzzzzz₂

252 + u       128 + vvvvvv  128 + wwwwww  128 + xxxxxx  128 + yyyyyy  128 + zzzzzz

Thus, we can encode the nth character in this range by computing its 6 least significant digits in base 64 and adding 252 to the most significant and 128 to the remaining ones.

Scoring

There are 2 ** 31 = 2,147,483,648 6 byte UTF-8 characters and the length of the original code is 39, so the score is 39 / floor(2 ** 15.5) = 39 / 46340 = 0.0008416055243849806.

How it works

{                                }""    e# Push the code block and an empty string.
                                    1$~ e# Execute a copy of the code block.
 _,                                     e# Push the length of the string.
   6/                                   e# Divide by 6 to get the number of chars.
      {64md}6*                          e# Perform modular division six times.
     [        ]                         e# Collect the results in an array.
               (124+\+                  e# Add 124 to the first element.
                      '�f+              e# Add 128 to all and cast each to Char.
                          +             e# Concatenate the strings.
                           `            e# Push a string representation.
                            "1$~"       e# Push '1$~' to complete the quine.

Dennis

Posted 2015-05-03T21:08:53.877

Reputation: 196 637

I am accepting this because of your first (lower) score. I will allow it. – None – 2015-05-05T19:20:51.317

6

CJam, 46 bytes, 65504 add, 65505 del, Score 0.127424

{`-2<_0c#)!{'#/~(_)\+\+S+]'#*}*W<"
}_~"e# 
}_~

Test it here.

The basic form is a standard generalised CJam quine. To "almost quine", there's a comment e# at the end of the quine's block, where I can freely add characters without affecting the code. Note that the comment initially contains a single space.

The program continues adding characters to the front of the comment, starting at ! and then going in order of ASCII value. CJam's character codes wrap around after 216 so at some point, this will add a null byte. Once that happens, the program starts removing bytes from the end of the comment (such that the position of the removed character is always different) until the comment is empty.

Martin Ender

Posted 2015-05-03T21:08:53.877

Reputation: 184 808

5

CJam, 19 bytes, 65536 add, 0 del, Score 0.074219

"a"{\)_)++`\"_~"}_~

Simpler is better.

jimmy23013

Posted 2015-05-03T21:08:53.877

Reputation: 34 042