A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Quine in Whitespace page! Here, you'll find the source code for this program as well as a description of how the program works.
Quine in Whitespace was written by:
This article was written by:
If you see anything you'd like to change or update, please consider contributing.
The code listed in the "Current Solution" section looks like a polar bear in a blizzard! In other words, it is nothing but whitespace characters. The reason is two-fold:
At the highest level, the code consists of the following:
The value of P is calculated by representing each whitespace character in R as a base-3 number, least-significant value first, where:
In other words:
where:
P is a very large number: 125 base-10 digits!
So how does this approach generate an output that is identical to the actual program file? The idea is based on a description in RosettaCode (the code is not present since it looks like RosettaCode trims whitespace, and the code is all whitespace). Let's break it down. The rest of the code, R, does this:
Push
instruction as whitespace characters.The Push
instruction consists of the following:
Push
opcode: space, spacePush
instruction: newlineOutputting the Push
instruction consists of the following:
In order to easily translate integers into whitespace characters, memory
(mem
) is set up as follows:
Outputting the value of P as whitespace characters is done like this:
D = 1
Do
D = D * 2
While D < P
While (D = D // 2) != 0
N = P // D
Output mem[N % 2]
End While
where //
means integer division, and %
means modulo.
Outputting the rest of the program as whitespace characters consists of this:
While P != 0
Output mem[P % 3]
P = P // 3
End While
To balance out the stack and end the program, there is a Pop
instruction and
an End
instruction that tells the Whitespace interpreter to end the program,
but those are already accounted for in the value of P.
To see this all together, take a look at the Whitespace Assembly Code that was used to generate this sample. The Whitespace Assembly Language was converted to whitespace characters using the Whitespace Assembler. This sample is the output of the Assembler.
To run this program:
Code
section in the browser window. The size of the code
should be 679 bytes. If it is less, scroll all the way to the bottom and
press Enter.Output
section at the bottom should be identical to the original code.