Quine in Whitespace

Published on 16 April 2025 (Updated: 27 April 2025)

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.

Current Solution

   		  	 				  	    		 		 		  	  			   		 			   	 			 		  		 	  					 				   		 		 			 		   	  					 	 		  	 			      	     		   			 	       	   				  	  		   	    		 		     		 		 						    	  	 		    	 	   	  	 	 	  				 	 	 			   	 	    	    				 			 			      		 	  	  	     	  	 	 	 		    		 	 		 		    		 	 		  	 						 	    	 	  		  		  		 		 				 				 	  	   	 	 	  			 		    	 			  		  	 	    	 	  	 	 	  		 	 
    
   	     
		    	
   	  	
		    	 
   	 	 
		    	     
 
  
 	
  	
  	
     	

   
 
 	    
  	  	 
	  	
		 

  	
   	 
	 	  
 
	   
 	  	
 	  	
	 	    	 
	 						
  
 
	

    
 

   	 	 
	
  
   	
 
    		
	 						
     		
	 	  
 
	 		

 
 	

  		
 





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.

How to Implement the Solution

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:

  1. In Whitespace, the only characters that contain instructions are whitespace characters. Everything else is ignored.
  2. While it is possible to write a program that generates comments or other annotation, it would require a lot more code to do so. It is easier to just generate the whitespace characters that represent the code.

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:

The Push instruction consists of the following:

Outputting 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:

Outputting the rest of the program as whitespace characters consists of this:

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.

How to Run the Solution

To run this program: