5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ I think it's clear now, removed comment clutter. \$\endgroup\$ – Jonathan Allan Sep 6 '17 at 5:10
  • 3
    \$\begingroup\$ If there is a 256 code point, would the next largest power of two be 256 or 512? \$\endgroup\$ – Dennis Sep 6 '17 at 5:54
  • 1
    \$\begingroup\$ If the language automatically ends any output with a newline, can that newline be disregarded for the purposes of the challenge? \$\endgroup\$ – Luis Mendo Sep 6 '17 at 10:13
  • \$\begingroup\$ @Dennis: 256. The complement would be a null byte. \$\endgroup\$ – Zach Gates Sep 6 '17 at 12:44
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Kamil Drakari Sep 6 '17 at 14:50
5
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – Okx Sep 6 '17 at 8:37
  • \$\begingroup\$ I hate Neim, because I can't see most of the characters while on my phone. \$\endgroup\$ – caird coinheringaahing Sep 6 '17 at 21:03
5
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ In the latest commit, you can drop the õ, because Retina no longer prints trailing linefeeds by default. \$\endgroup\$ – Martin Ender Sep 6 '17 at 6:11
  • 1
    \$\begingroup\$ Can't you use Pv (or P) to the same effect? \$\endgroup\$ – Neil Sep 6 '17 at 8:03
  • \$\begingroup\$ Also a solution for Jelly. \$\endgroup\$ – Khuldraeseth na'Barya Sep 6 '17 at 23:54
3
\$\begingroup\$

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!

\$\endgroup\$
  • \$\begingroup\$ Oh so RProgN uses cheaty js style source reading assumes \$\endgroup\$ – ASCII-only Sep 6 '17 at 3:42
  • \$\begingroup\$ @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. \$\endgroup\$ – ATaco Sep 6 '17 at 3:44
1
\$\begingroup\$

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!

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

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!

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

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!

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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