A Complementary Quine

4

Write a quine that outputs the complement of the source code from the smallest containing power of two. Here's an example:

IN : source
OUT: \r\x11\x0b\x0e\x1d\x1b

The largest code point in the string "source" is the letter u, which is 117. The smallest containing power of 2 would be 128, so all the code points are taken as complements from 128.

  1. s: 128 - 115 = 13. Code point 13 is a carriage return.
  2. o: 128 - 111 = 17. Code point 17 is "device control 1"
  3. u: 128 - 117 = 11. Code point 11 is a vertical tab.

And et cetera. Here's another example:

IN : R¡Ṡ
OUT: ᾮὟƠ

The largest code point is the character , which is 7776. The smallest containing power of 2 is 2^13 (8192), so each character is complemented from 8192.

All of the standard loopholes apply. A program must consist of some explicit data or code. A variable containing some data by default would be considered implicit data, and therefore not allowed.

If your language inevitably outputs a trailing newline, it can be disregarded.

Zach Gates

Posted 2017-09-06T03:00:04.540

Reputation: 6 152

I think it's clear now, removed comment clutter. – Jonathan Allan – 2017-09-06T05:10:01.500

3If there is a 256 code point, would the next largest power of two be 256 or 512? – Dennis – 2017-09-06T05:54:02.993

1If the language automatically ends any output with a newline, can that newline be disregarded for the purposes of the challenge? – Luis Mendo – 2017-09-06T10:13:28.840

@Dennis: 256. The complement would be a null byte. – Zach Gates – 2017-09-06T12:44:35.250

@LuisMendo: If it's unavoidable, it can be disregarded. – Zach Gates – 2017-09-06T12:45:47.610

2@ZachGates That's intuitive in decimal mathematics, but in binary it's less so. For example, it's true that 2^8 is 256, but an 8 bit number is only capable of representing values from 0 to 255. It's your challenge of course, but it seems to implicitly care about binary representations. – Kamil Drakari – 2017-09-06T14:50:06.277

Answers

5

Retina, 2 1 byte

P

Outputs

0

Explained

P actually has no special meaning in retina, but retina treats it like a regex against the input, and counts the matches. As there's no input, there's no matches, so it returns 0, which is the exact inverse of this.

Try it online!

This is using an older version of Retina, which outputs a newline with the zero. This is not the case in the latest version.

ATaco

Posted 2017-09-06T03:00:04.540

Reputation: 7 898

1In the latest commit, you can drop the õ, because Retina no longer prints trailing linefeeds by default. – Martin Ender – 2017-09-06T06:11:31.157

1Can't you use Pv (or P) to the same effect? – Neil – 2017-09-06T08:03:23.120

Also a solution for Jelly. – Khuldraeseth na'Barya – 2017-09-06T23:54:08.547

5

Neim, 1 byte


Try it online!

Uses Neim's code-page, where is byte 0xd0 (208) and the printed result, 0, is byte 0x30 (48) which is as required (256-208).

is an instruction to get the nth element of a list. Both n and the list are implicit since they are missing and neim outputs implicitly too.

Jonathan Allan

Posted 2017-09-06T03:00:04.540

Reputation: 67 804

Missing stack elements default to 0. Therefore, this is getting the 0th element of the list [0] (which is 0 implicitly converted to a digit list), which is 0. – Okx – 2017-09-06T08:37:36.757

I hate Neim, because I can't see most of the characters while on my phone. – caird coinheringaahing – 2017-09-06T21:03:06.060

3

RProgN 2, 17 18 bytes

«` .S{c$256\-o}r. 

Output

U àÒ\x85\x9DÜÎËʤÓ\x91\x83\x8EÒà

Where \x numbers are to be considered literal.

Explained

«` .S{c$256\-o}r. 
«                   # Push a function based on the remainder of the program and run it.
 ` .                # Append a space to the end, which stringifies it. As the stringification removes unnecessary spaces, this re-adds the leading one, making it a valid quine.
    S               # Convert it to a stack of characters.
     {        }r    # Replace each character based on a function.
      c             # Get the character code
       $256         # Push 256 literally.
           \-       # Flip them and subtract, giving 255 - char code, which is equivalent to the bitwise not of the char code.
             o      # Get the character this represents.
                .   # Reduce with Concatenation, turning it back into a string. Implicitely output.

Try it online!

ATaco

Posted 2017-09-06T03:00:04.540

Reputation: 7 898

Oh so RProgN uses cheaty js style source reading assumes – ASCII-only – 2017-09-06T03:42:32.237

@ASCII-only Kind of. « has no idea what the original source code looks like, but it does know the array of 'concepts' that the source code was parsed into. When stringifying it, it just concatenates the stringifications of those concepts, which is why noops like spaces are ignored. – ATaco – 2017-09-06T03:44:26.843

1

C, 178 bytes

char*u,*s="char*u,*s=%c%s%c;main(){char t[256];sprintf(t,s,34,s,34);for(u=t;*u;++u)*u=128-*u;puts(t);}";main(){char t[256];sprintf(t,s,34,s,34);for(u=t;*u;++u)*u=128-*u;puts(t);}

Try it online!

Steadybox

Posted 2017-09-06T03:00:04.540

Reputation: 15 798

0

JavaScript, 121 bytes

f=a=>[...a='f='+f].map(a=>(m=(a=a.charCodeAt())>m?a:m,a),m=0).map(a=>String.fromCharCode(2**-~(Math.log2(m)|0)-a)).join``

Try it online!

user72349

Posted 2017-09-06T03:00:04.540

Reputation:

0

Python 2, 93 bytes

s='s=%r;print"".join(chr(128-ord(i))for i in s%%s)';print"".join(chr(128-ord(i))for i in s%s)

Try it online!

totallyhuman

Posted 2017-09-06T03:00:04.540

Reputation: 15 378