<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Darshan A S</title>
    <description>The latest articles on DEV Community by Darshan A S (@darshan-as).</description>
    <link>https://dev.to/darshan-as</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1769266%2F815750c3-7bdb-4f35-8332-3818a30bb77a.jpg</url>
      <title>DEV Community: Darshan A S</title>
      <link>https://dev.to/darshan-as</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/darshan-as"/>
    <language>en</language>
    <item>
      <title>MultiQuine. Weaving the web of Quines</title>
      <dc:creator>Darshan A S</dc:creator>
      <pubDate>Sun, 18 Aug 2024 08:08:56 +0000</pubDate>
      <link>https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me</link>
      <guid>https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me</guid>
      <description>&lt;p&gt;Previously, we've seen how to construct &lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelays&lt;/a&gt; by leveraging the existence of &lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Introns&lt;/a&gt;. Now, prepare to have your minds blown once again as we unlock the next level of Quine wizardry: &lt;a href="https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me"&gt;MultiQuines&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We start by saying what a Bi-Quine (or more generally a MultiQuine) is. To begin, here is what it is not: a Bi-Quine is not a program that prints a second program, which in turn prints the first again (actually, it's that, but things are a bit more subtle). That would just be a QuineRelay and it is too easy to do (we have proved the existence of such, using Introns).&lt;/p&gt;

&lt;p&gt;A Bi-Quine is a very interesting kind of program: when run normally, it is a &lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quine&lt;/a&gt;. But if it is called with a particular command line argument, it will print a different program, its "sibling". Its sibling is also a Quine, but in a different programming language, so its sibling prints its own source code when run normally. But when run with a particular command line argument, the sibling prints the source code of the original program. So in effect, a Bi-Quine is a set of two programs each of which is able to print either of the two.&lt;/p&gt;

&lt;p&gt;Essentially, MultiQuines are set of n programs, in n different languages such that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each program is a valid Quine and outputs itself when executed with no input.&lt;/li&gt;
&lt;li&gt;Each program can output the source of any other program in the set, according to the command line argument it is passed.
Think Fully-Connected-Graph here.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;All MultiQuines are QuineRelays, but all QuineRelays are not MultiQuines.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that cheating is not allowed: the command line arguments must not be too long — passing the full source of a program is considered cheating.&lt;/p&gt;




&lt;h2&gt;
  
  
  5th-order MultiQuine (PentaQuine)
&lt;/h2&gt;

&lt;p&gt;Here's a 5th-order MultiQuine made up of Python, Perl, F#, newLISP, and C.&lt;br&gt;
&lt;a href="https://github.com/rvantonder/pentaquine" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo8lnsqv2a3juy4m0upa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmo8lnsqv2a3juy4m0upa.png" alt="PentaQuine" width="533" height="469"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  25th-order MultiQuine
&lt;/h2&gt;

&lt;p&gt;A MultiQuine consisting of 25 languages, from Ruby, Octave, CoffeScript, JavaScript, Python and 20 more.&lt;br&gt;
&lt;a href="https://github.com/coolwanglu/quine-chameleon" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;One of the characters in  &lt;em&gt;Six Degrees of Separation&lt;/em&gt;, a popular &lt;a href="https://en.wikipedia.org/wiki/Six_Degrees_of_Separation_(play)" rel="noopener noreferrer"&gt;play&lt;/a&gt; and &lt;a href="https://en.wikipedia.org/wiki/Six_Degrees_of_Separation_(film)" rel="noopener noreferrer"&gt;film&lt;/a&gt; by an American playwright &lt;a href="https://en.wikipedia.org/wiki/John_Guare" rel="noopener noreferrer"&gt;John Guare&lt;/a&gt; states:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I read somewhere that everybody on this planet is separated by only six other people. Six degrees of separation between us and everyone else on this planet. The President of the United States, a gondolier in Venice, just fill in the names. I find it extremely comforting that we're so close. I also find it like Chinese water torture, that we're so close because you have to find the right six people to make the right connection... I am bound, you are bound, to everyone on this planet by a trail of six people.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This phenomenon is also called &lt;a href="https://en.wikipedia.org/wiki/Six_degrees_of_separation" rel="noopener noreferrer"&gt;The small world theory&lt;/a&gt;. Facebook's data team released two papers in November 2011 which document that amongst all Facebook users at the time of research (721 million users with 69 billion friendship links) there was an average distance of 4.74&lt;br&gt;
It had come down from 5.28 in 2008. And by 2016, the separation distance was down to 4.57&lt;/p&gt;

&lt;p&gt;Similarly, MultiQuines are a special case of the small world theory. A world where a population of self-sustainable Quines are linked to each other by just one degree of separation.&lt;/p&gt;


&lt;h2&gt;
  
  
  Writing your own MultiQuine
&lt;/h2&gt;

&lt;p&gt;The secret behind MultiQuines lies in the clever use of, you guessed it, Introns - those non-coding regions we explored earlier. Each MultiQuine program contains &lt;code&gt;n&lt;/code&gt; &lt;em&gt;data&lt;/em&gt; sets: one for its own code and one for each of its siblings. When executed with a specific argument, a MultiQuine uses the corresponding data set to generate the source code of the requested sibling. It then uses its own data sets to replicate the introns within the sibling's code, ensuring the cycle of transformation continues seamlessly.&lt;/p&gt;

&lt;p&gt;Let's take the outline of the QuineRelay we build last time:&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of JavaScript&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of Python&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d1 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d2 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we want to read the command line argument and decide to print &lt;code&gt;d1&lt;/code&gt; or &lt;code&gt;d2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In Python, &lt;code&gt;sys.argv&lt;/code&gt; is the array that holds these.&lt;br&gt;
If it says "js" we output the JavaScript MultiQuine&lt;br&gt;
If it says "py" or empty we output the same Python MultiQuine back.&lt;br&gt;
Note. We are choosing to ignore any other values and just output the same Python Quine&lt;br&gt;
Make sure to &lt;code&gt;import sys&lt;/code&gt; and also check if &lt;code&gt;sys.argv&lt;/code&gt; does have an argument passed in.&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of JavaScript&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;js&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Javascript, &lt;code&gt;process.argv&lt;/code&gt; is the array that holds these.&lt;br&gt;
Use the same conditions to modify the JavaScript MultiQuine as below:&lt;/p&gt;

&lt;p&gt;JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of Python&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d1 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d2 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;py&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, all we have to do is, copy the final &lt;em&gt;code&lt;/em&gt; part to each other's &lt;code&gt;d1&lt;/code&gt; and &lt;code&gt;d2&lt;/code&gt; variables:&lt;/p&gt;

&lt;p&gt;Python: &lt;a href="https://tio.run/##xZC9CsIwFEZ3n@KjiGlBCo2bUt0ddHAUQbGxP9QkJEEo4rPHW4u0orvrPR8nh@jGFUrOvM8SpAjKq1bGwTZ2AW1K6ULWAjaFEdqEWRJFPeADwHtA9/KCWsiQNPHJ5LcISyQ4yQzvyz45IE3BKssgaitA5mDUGhGclbSqFnGt8vD4yhrf17vtJraO/Hl5adqOx5Ee/Jzyn1P@PdVGnYXtSmIKzV1BhRyTCYZoz7tI3TCsqBBzkG0RjP75S977yj4B" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt; (Play with argument &lt;code&gt;py&lt;/code&gt; or &lt;code&gt;js&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;import sys; print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(d1)); print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(d2)); print(d2 if len(sys.argv) &amp;gt; 1 and sys.argv[1] == &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;js&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; else d1)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(process.argv.length &amp;gt; 2 &amp;amp;&amp;amp; process.argv[2] == &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;py&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; ? d1 : d2);&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;js&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript: &lt;a href="https://tio.run/##zY6xCsIwFEV3v@JSxLSghWZUqruDDo4iWNpYU2oSkiAU8dvjqyIq@gGu71zOO01xLlxppfETpSsRQpUhRyRPRlsP17kZjJXKx6wHbAwrjI2rLElegL8B/gJ0lwe0QsWkSQtbnxPMkaFQFZ6XbbZDnoM1jkG0ToDM0aA3Iiq1croVaavreH/PGl6Wm/UqdZ78tTx0fcd1Tw8/p/znlH9PjdWlcI@SlEJrf6RCjtEI72jLH5GmY1hQIaYg2ywa/HthCMF0Nw" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt; (Play with argument &lt;code&gt;py&lt;/code&gt; or &lt;code&gt;js&lt;/code&gt;)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;import sys; print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2 if len(sys.argv) &amp;gt; 1 and sys.argv[1] == 'js' else d1)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(process.argv.length &amp;gt; 2 &amp;amp;&amp;amp; process.argv[2] == 'py' ? d1 : d2);&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d1 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d2 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;py&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go. It's a valid 2nd-order MultiQuine (Bi-Quine)&lt;/p&gt;




&lt;p&gt;If you wanna play around more, &lt;a href="http://www.madore.org/~david/" rel="noopener noreferrer"&gt;David Madore&lt;/a&gt; has written a &lt;em&gt;C/Perl&lt;/em&gt; Bi-Quine. For fun, only the &lt;a href="http://www.madore.org/~david/programs/selfrep/biquine.c" rel="noopener noreferrer"&gt;C version&lt;/a&gt; is given out; if you want the &lt;em&gt;Perl&lt;/em&gt; version you will have to run the program with the &lt;a href="http://foldoc.org/xyzzy" rel="noopener noreferrer"&gt;magic word&lt;/a&gt;: &lt;strong&gt;xyzzy&lt;/strong&gt; as the argument. In the C version, &lt;code&gt;c_data&lt;/code&gt; is the main data set and &lt;code&gt;perl_data&lt;/code&gt; is an intron; in the Perl version, of course, things are reversed.&lt;/p&gt;

&lt;p&gt;One peculiar thing, you might notice in the above &lt;em&gt;C/Perl&lt;/em&gt; example, is that the &lt;em&gt;data&lt;/em&gt; section is encoded as an array of numbers. This is a common trick to avoid having to deal with nested quoting problem, while writing Quines. In fact if one wanted to, each data set could use a different coding mechanism, or even an encryption mechanism, although you'd need a key to decrypt it in the &lt;em&gt;code&lt;/em&gt; section.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next post on &lt;a href=""&gt;Radiation-Hardened-Quine&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;Sources and references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.madore.org/~david/computers/quine.html" rel="noopener noreferrer"&gt;Quines (self-replicating programs)&lt;/a&gt;, blog by David Madore.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/rvantonder/pentaquine" rel="noopener noreferrer"&gt;Pentaquine&lt;/a&gt;, GitHub repo by Rijnard van Tonder.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/coolwanglu/quine-chameleon#variants" rel="noopener noreferrer"&gt;Quine Chameleon&lt;/a&gt;, GitHub repo by Lu Wang.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Six_degrees_of_separation" rel="noopener noreferrer"&gt;The small world theory&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=YbRU0b7UOmA" rel="noopener noreferrer"&gt;Six Degrees of Separation - Quote&lt;/a&gt;, Youtube video clip from the movie Six Degrees of Separation.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quine&lt;/a&gt;, &lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Intron&lt;/a&gt;, &lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelay&lt;/a&gt;, &lt;a href="https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me"&gt;MultiQuine&lt;/a&gt;, set of four self-referencing blogs that link to each other in a fully-connected graph.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dna</category>
      <category>selfrep</category>
      <category>quine</category>
      <category>python</category>
    </item>
    <item>
      <title>QuineRelay: Birth of the Quine serpent</title>
      <dc:creator>Darshan A S</dc:creator>
      <pubDate>Wed, 07 Aug 2024 14:13:59 +0000</pubDate>
      <link>https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be</link>
      <guid>https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be</guid>
      <description>&lt;p&gt;In the previous adventures of the Quine blog series, we explored how to write our own &lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quines&lt;/a&gt; and &lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Introns&lt;/a&gt;. Today we will see what &lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelays&lt;/a&gt; are and how you can leverage Introns to create them.&lt;/p&gt;

&lt;p&gt;Imagine a circle of programs, each written in a different language. Each program in this circle has a single purpose: to print the source code of the next program in the sequence. The last program then closes the loop by printing the source code of the very first program.&lt;/p&gt;

&lt;p&gt;Essentially, QuineRelays are a set of n programs, in n different languages such that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each program outputs the source of the next.&lt;/li&gt;
&lt;li&gt;The last program outputs back the source of the first one.
Think Circular-Linked-List here. The last example is a mind-blower!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see some examples to grasp the concept better.&lt;/p&gt;




&lt;h2&gt;
  
  
  2nd-order relay
&lt;/h2&gt;

&lt;p&gt;This 2nd-order &lt;a href=""&gt;QuineRelay&lt;/a&gt; features a JavaScript program that prints a Python program, which then prints the original JavaScript program back. It's a dynamic duo of self-replication.&lt;br&gt;
JavaScript → Python ⥀&lt;/p&gt;

&lt;p&gt;JavaScript: &lt;a href="https://tio.run/##y0osSyxOLsosKNEts/j/Pzk/rzg/J1UvJz9dQ6PQNt7WLqGgKDOvREOl2ivY30@vuATIS89Mq9RIQFOqUl2oHR1bq6mhqZmgWQvEQMb//wA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;`print(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`console.log((q=&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;[]}&lt;/span&gt;&lt;span class="s2"&gt;)())`&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;)())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python: &lt;a href="https://tio.run/##K6gsycjPM/7/v6AoM69EQyk5P684PydVLyc/XUOj0Dbe1i4BIqNS7RXs76dXXALkpWemVWokoClVqS7Ujo6t1dTQ1EzQrAViIENJ8/9/AA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;console.log((q=_=&amp;gt;`print(${JSON.stringify(`console.log((q=${q+[]})())`)})`)())&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3rd-order relay
&lt;/h2&gt;

&lt;p&gt;Things get even more interesting with a 3rd-order &lt;a href=""&gt;QuineRelay&lt;/a&gt;. This one starts with a Haskell program, which outputs a Python program, which outputs a Ruby program, and finally, the Ruby program loops back to the original Haskell program.&lt;br&gt;
Haskell → Python2 → Ruby ⥀&lt;/p&gt;

&lt;p&gt;Haskell: &lt;a href="https://tio.run/##vY89C4MwFEX3/oqHFF5CQlHaqcWxW7eOxSHGFKUaTYzUf2/jFxW6dzvvcLmXl4v2pcpyGAwISEHGTefuzt407P3JGDxcfdVdBVHI0SBHgsmo27x@LwEvv0r@KjErismuEoWODQT/GAsgyNQTDBE85ZKeG1toBymTuSVRSBkagsyqxpLUH3xhuWHhmeLSo0hPwSrXWQ3H08G3sJ7NAEpnl@0WrFtROAVx@RuZmsYmkCuIGebs2BUMwwc" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight haskell"&gt;&lt;code&gt;&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;putStrLn&lt;/span&gt; &lt;span class="o"&gt;$&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;toEnum&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sc"&gt;'q'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sc"&gt;'('&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;','&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;','&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;show&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sc"&gt;')'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="s"&gt;"q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']"&lt;/span&gt; &lt;span class="s"&gt;"def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')'"&lt;/span&gt; &lt;span class="s"&gt;"def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python2: &lt;a href="https://tio.run/##rY6xDoIwFEV3v@KFmLRNGwPqpGF0c3M0DKXUwEBpa4n49bVQiCSubued3Nz79NvVndp7X8kHGMxZyQQ5adsoByUVtcVZSigyGFErtcVlONjMYsU8MEEbg5O/FCVs6pF4IGCl662Cw3EXWuhAI4BU1Xm9BctWlk5B1PJG5QYQldPYBGIBHiFmx66waIBDCSLXvbs5e1WwDSelcHfdRfUtZClDJjyKUTHqZ9295kCQXyV@FY@KoCIh3n8A" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;q&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;q&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;def q(a,b,c):print b+chr(10)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+repr(b)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+repr(c)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+repr(a)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;main=q &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+e(b)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+e(c)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+e(a)+&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;+10.chr end&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;q a b c=putStrLn $ b ++ [toEnum 10,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;q&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;] ++ show b ++ [&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;] ++ show c ++ [&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;] ++ show a ++ [&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;]&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ruby: &lt;a href="https://tio.run/##vY69CsIwFEZ3n@JShJuQIC06KR3d3BylQ5JG2sG0iSnWp69Jf7Dg7nZy@Mg9rpPvYSj1HTTpKTjtO2dgf9ipyrGeTQDalKe4sURwyRWF1tXGg2RZOg7xIWqTW0CmiaQMR1ALiAmmbfxrY0ny55MJTywIkKDytvNX7y4GtuHJGNx8czbdA7KUo0WOBIuon1XzmgdBfpX6VWJSFItwZh19XKJDBcnSEGUJMqdbNzbzmdWKYznFhA7DBw" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;q&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;'main=q '&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chr&lt;/span&gt; &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"def e(x) return 34.chr+x+34.chr end;def q(a,b,c) print b+10.chr+'main=q '+e(b)+' '+e(c)+' '+e(a)+' '+10.chr end"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')'"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4th-order relay
&lt;/h2&gt;

&lt;p&gt;Here's a 4th-order &lt;a href=""&gt;QuineRelay&lt;/a&gt;: Ruby → Java → C# → Python ⥀&lt;br&gt;
&lt;a href="https://github.com/IRus/Quine" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Across cultures, there are several shared symbolisms. One of them is the &lt;a href="https://en.wikipedia.org/wiki/Ouroboros" rel="noopener noreferrer"&gt;Ouroboros&lt;/a&gt;, which has references in Egyptian, Greek, Roman, Hindu, Siberian, Norse, African, and South American mythologies. The Ouroboros is an ancient symbol depicting a serpent or dragon consuming its own tail, representing the eternal cycle of creation and destruction.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseec11007uarwfbk1inl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fseec11007uarwfbk1inl.jpeg" alt="Oroborus symbol" width="781" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In Norse mythology, &lt;a href="https://en.wikipedia.org/wiki/J%C3%B6rmungandr" rel="noopener noreferrer"&gt;Jörmungandr&lt;/a&gt; is a colossal serpent, the middle child of Loki and the giantess Angrboða. Odin cast Jörmungandr into the ocean surrounding Midgard (the realm of humans), where the serpent grew so immense that it encircled the world and grasped its own tail. As a result of it surrounding Midgard (the Earth) it is referred to as the World Serpent - Ouroboros. Jörmungandr releasing its tail is one of the signs of the beginning of &lt;a href="https://en.wikipedia.org/wiki/Ragnar%C3%B6k" rel="noopener noreferrer"&gt;Ragnarök&lt;/a&gt; (the final battle of the world).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Quine relays embody this symbolism quite neatly, as each program in the cycle gives rise to the next, only to be reborn in the end, and hence are nicknamed &lt;em&gt;Ouroboros&lt;/em&gt; programs.&lt;/p&gt;


&lt;h2&gt;
  
  
  128th-order Ouroboros relay
&lt;/h2&gt;

&lt;p&gt;Hold on to your seats. Here's a 128th-order Ouroboros &lt;a href=""&gt;QuineRelay&lt;/a&gt;. Yes, you read that right. 128 !!!&lt;br&gt;
Ruby → Rust → Scala →  ... (120 others) ... → Python → R → Ratfor → rc → REXX ⥀&lt;br&gt;
&lt;a href="https://github.com/mame/quine-relay" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv7keo93h7tyej653mvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flv7keo93h7tyej653mvu.png" alt="128 QuineRelay languages" width="750" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As if this wasn't impressive enough, it includes an easter egg. The original Ruby code when zoomed out contains an Ouroboros dragon!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fueg5g6rmy1q605hbigid.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fueg5g6rmy1q605hbigid.jpeg" alt="128 QuineRelay code snapshot" width="800" height="554"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Writing your own QuineRelay
&lt;/h2&gt;

&lt;p&gt;Let's start the Python intron we wrote earlier and try to turn it into a 2nd-order QuineRelay.&lt;/p&gt;

&lt;p&gt;Python Intron: &lt;a href="https://tio.run/##K6gsycjPM/7/PzOvpCg/T8FWQb28NCkpMQdEpJQmAZE6V0piSSJQRqmgCKhKQx2mVF1HoSi1oEgDwtfUtFaAKoCoh0mDeAhJME@Ji2pG/f8PAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;intron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wubbalubbadubdub&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(intron)); print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intron&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the magic of introns, we can now easily put the &lt;em&gt;code&lt;/em&gt; part of a sibling Quine of a different language into the intron. Producing a program of the form:&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;intron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of sibling&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of self&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intron&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since, each variable is just, acting as &lt;em&gt;data&lt;/em&gt; of a different Quine. Let's rename &lt;code&gt;data&lt;/code&gt; and &lt;code&gt;intron&lt;/code&gt;, into &lt;code&gt;d1&lt;/code&gt; and &lt;code&gt;d2&lt;/code&gt; respectively.&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of self&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of sibling&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, &lt;code&gt;d2&lt;/code&gt; acts as an intron, but the above program still tried to print code part of self. To have it print source of the next, let's &lt;code&gt;print(d2)&lt;/code&gt; instead of &lt;code&gt;print(d1)&lt;/code&gt; at the end.&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of self&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;code part of sibling&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We already know that the contents of &lt;code&gt;d1&lt;/code&gt; is just a copy of line 3. But we don't yet have the contents of &lt;code&gt;d2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Say, we wanted to create a QuineRelay with JavaScript. Let's write a similar intron in JS.&lt;/p&gt;

&lt;p&gt;JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of sibling&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;code part of self&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d1 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d2 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, line 3 of the above JS intron, is the &lt;em&gt;code&lt;/em&gt; of the sibling program we wanted!&lt;br&gt;
Paste each other's &lt;em&gt;code&lt;/em&gt; as introns in the other.&lt;br&gt;
Note. We need to add &lt;code&gt;d1 + ''&lt;/code&gt; in js to avoid some quoting mismatches&lt;/p&gt;

&lt;p&gt;Python: &lt;a href="https://tio.run/##K6gsycjPM/7/P8VQwVZBqaAoM69EQx3EUddRKEotKNJIMdTUtFaASRghSRghJIBsJS6QpIJScn5ecX5Oql5OfrpGAthUlWqvYH8/veISoNL0zLRKkJG1CUC9qEqNsCo1wlQKNFRbQV1d01qJiwL3/v8PAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(d1)); print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(d2)); print(d2)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1 + &lt;/span&gt;&lt;span class="sh"&gt;''&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d1 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d2 =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript: &lt;a href="https://tio.run/##y0osSyxOLsosKNEts/j/P8VQwVZBqaAoM69EQx3EUddRKEotKNJIMdTUtFaASRghSRghJIBsJS6QpIJScn5ecX5Oql5OfrpGAthUlWqvYH8/veISoNL0zLRKkJG1CUC9qEqNsCo1wlQKNFRbQV1d01qJi46W/f8PAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;print('d1 =', repr(d1)); print('d2 =', repr(d2)); print(d2)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;d2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;console.log(`d1 = ${JSON.stringify(d1)}`); console.log(`d2 = ${JSON.stringify(d2)}`); console.log(d1 + '');&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d1 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`d2 = &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d2&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you go. It's a proper 2nd order QuineRelay! A Python program, that prints a JavaScript program, that prints the original Python program back in a cycle.&lt;/p&gt;




&lt;p&gt;Creating a QuineRelay is an exercise in creative coding and understanding how different languages represent and manipulate strings. It involves weaving together introns from various programs, each containing the code to replicate its next neighbour.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At its core, an nth-order relay is a game of n clever ways to escape quotes across n programming languages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Stay tuned for the next post on &lt;a href="https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me"&gt;MultiQuine&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;Sources and references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Quine_(computing)#Ouroboros_programs" rel="noopener noreferrer"&gt;Ouroboros programs&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://blog.sigfpe.com/2008/02/third-order-quine-in-three-languages.html" rel="noopener noreferrer"&gt;A Third Order Quine in Three Languages&lt;/a&gt;, blog by sigfpe.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/IRus/Quine" rel="noopener noreferrer"&gt;Chain Quine&lt;/a&gt;, GitHub repo by Ibragimov Ruslan.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/mame/quine-relay" rel="noopener noreferrer"&gt;128 Quine Relay&lt;/a&gt;, GitHub repo by Yusuke Endoh.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelay: Birth of the Quine serpent&lt;/a&gt;, self-referencing blog where a word in each n-order example hyperlinks to the next, cyclically. (May not work in dev.to; checkout the canonical blog)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/J%C3%B6rmungandr" rel="noopener noreferrer"&gt;Jörmungandr&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Ouroboros" rel="noopener noreferrer"&gt;Ouroboros&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/6avJHaC3C2U?si=zEERK5IyEtrtTD3h" rel="noopener noreferrer"&gt;Art of Code&lt;/a&gt;, talk by Dylan Beattie&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dna</category>
      <category>quine</category>
      <category>selfrep</category>
      <category>python</category>
    </item>
    <item>
      <title>Intron: Junk or not Junk, that is the quine-tion</title>
      <dc:creator>Darshan A S</dc:creator>
      <pubDate>Thu, 25 Jul 2024 05:18:08 +0000</pubDate>
      <link>https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl</link>
      <guid>https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl</guid>
      <description>&lt;p&gt;Last time, we cracked the code of &lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quines&lt;/a&gt;, those clever programs that echo their own source code. We crafted them with surgical precision, including only the bare essentials for self-replication.&lt;/p&gt;

&lt;p&gt;But here's a question: Can we sneak in some extra, even &lt;em&gt;useless&lt;/em&gt;, bits of data into an existing Quine without breaking it?&lt;/p&gt;

&lt;p&gt;Enter the world of &lt;strong&gt;&lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Introns&lt;/a&gt;&lt;/strong&gt;, those sneaky bits of data that can hitch a ride within a Quine. Just like the non-coding regions of DNA in biology, these introns are extra passengers that don't directly contribute to the Quine's function, but they get copied along for the ride nonetheless.&lt;/p&gt;

&lt;p&gt;In the world of biology, Introns are often called "Junk DNA". Only ~2.5% of the genome encodes sequences that make proteins. The functions for the remaining &amp;gt;90% of our genome is not well understood, but seem to play a crucial role in evolution and gene regulation.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Introns are the dark matter of the eukaryotic genome."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Similarly, in the world of programming, introns might seem like a useless thing to do, but the possible existence of introns will be the key feature in making &lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelays&lt;/a&gt; and &lt;a href="https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me"&gt;MultiQuines&lt;/a&gt; possible. (some things we will talk about in the upcoming posts)&lt;/p&gt;




&lt;h2&gt;
  
  
  Writing your own Intron
&lt;/h2&gt;

&lt;p&gt;Let's take our Python Quine from last time and see how to inject an intron.&lt;/p&gt;

&lt;p&gt;Original Python Quine:  &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkGpoCgzr0RDHcJV11EoSi0o0gDxNDWtFSCSYJ4SF7Eq//8HAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's introduce a variable called &lt;code&gt;intron&lt;/code&gt; and set it to a seemingly junk string, such as &lt;code&gt;'wubbalubbadubdub'&lt;/code&gt;. We'll add it to the &lt;em&gt;data&lt;/em&gt; portion of our Quine.&lt;/p&gt;

&lt;p&gt;Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;intron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wubbalubbadubdub&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To maintain the Quine's integrity, we need to mirror this addition in the &lt;em&gt;code&lt;/em&gt; portion. We'll use the &lt;code&gt;repr(intron)&lt;/code&gt; technique to ensure the intron is replicated accurately&lt;br&gt;
Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;intron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wubbalubbadubdub&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intron&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we update the &lt;code&gt;data&lt;/code&gt; variable to hold the latest &lt;em&gt;code&lt;/em&gt; section.&lt;br&gt;
Python: &lt;a href="https://tio.run/##K6gsycjPM/7/PzOvpCg/T8FWQb28NCkpMQdEpJQmAZE6V0piSSJQRqmgCKhKQx2mVF1HoSi1oEgDwtfUtFaAKoCoh0mDeAhJME@Ji2pG/f8PAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;intron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;wubbalubbadubdub&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(intron)); print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;intron =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intron&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's still a valid Quine. And now it's an IntronQuine!&lt;/p&gt;




&lt;p&gt;Imagine a year with only ten months! That's how the Romans initially rolled, with January and February being late additions to the party. Romans were also the reason we have the seemingly random leap days thrown around every few years. And to top it all off, did you know that in 1752, India skipped 11 whole days from its calendar?&lt;/p&gt;




&lt;p&gt;Run the above IntronQuine and notice how the value of the &lt;code&gt;intron&lt;/code&gt;  variable is faithfully reproduced in the output. Try setting &lt;code&gt;intron = 'your name here'&lt;/code&gt;  The program will still work flawlessly, replicating itself along with your custom message.&lt;/p&gt;

&lt;p&gt;The key takeaway is that, quite obviously, an intron can be modified with great ease without breaking the existing Quine; it is a kind of subliminal information that is reproduced with the Quine, although it is not necessary to the Quine. You can change the value of the variable &lt;code&gt;intron&lt;/code&gt; to any arbitrary string (as long as it's syntactically right) and the program continues to be a Quine!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This also means, in principle, you can convert any arbitrary program into a Quine, by just encoding its source code as an intron!&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Oh, and why was the above calendar bit relevant, you might ask? It wasn't. (Or was it?) Much like those seemingly "junk" leap days in a calendar, this is a seemingly "junk" paragraph just hitching a ride on this blog. Sounds familiar? One might even call it an &lt;em&gt;Intron&lt;/em&gt; of this very blog! To learn more about the fascinating and quirky story behind it, checkout &lt;a href="https://dev.to/darshan-as/leap-days-and-the-quest-for-the-perfect-calendar-3hk1"&gt;Leap days, and the quest for the perfect Calendar&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Like I said, Introns might seem like a useless thing to do, but the possible existence of them will open the doors to mind-blowing interactions between several Quines.&lt;/p&gt;

&lt;p&gt;Stay tuned for the next post on &lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelays&lt;/a&gt;!&lt;/p&gt;




&lt;p&gt;Sources and references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Intron" rel="noopener noreferrer"&gt;Intron (Biology)&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/darshan-as/leap-days-and-the-quest-for-the-perfect-calendar-3hk1"&gt;Leap days, and the quest for the perfect Calendar&lt;/a&gt;, blog about quirky history of calendars.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=a-zEbokJAgY" rel="noopener noreferrer"&gt;Self-replicating Python code | Quine&lt;/a&gt;, Youtube video by Lex Fridman.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://mcmanuslab.ucsf.edu/content/illuminating-dark-matter-genome" rel="noopener noreferrer"&gt;Illuminating the Dark Matter of the Genome&lt;/a&gt;, article by McManus Lab.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Intron. Junk or not Junk, that is the quine-tion&lt;/a&gt;, self-referencing blog that contains an Intron.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>quine</category>
      <category>dna</category>
      <category>selfrep</category>
      <category>python</category>
    </item>
    <item>
      <title>Leap days, and the quest for the perfect Calendar</title>
      <dc:creator>Darshan A S</dc:creator>
      <pubDate>Mon, 15 Jul 2024 18:57:29 +0000</pubDate>
      <link>https://dev.to/darshan-as/leap-days-and-the-quest-for-the-perfect-calendar-3hk1</link>
      <guid>https://dev.to/darshan-as/leap-days-and-the-quest-for-the-perfect-calendar-3hk1</guid>
      <description>&lt;p&gt;The story of calendars is a cosmic interplay between astronomy, religion, and history.&lt;br&gt;
And, if you think your schedule is chaotic, just be glad you weren't around when the Romans were messing with time.&lt;/p&gt;

&lt;p&gt;Humans have long relied on the cycle of Day and Night for hunting, gathering, and finding their way home after one too many fermented berries.&lt;/p&gt;

&lt;p&gt;But our ancestors needed more than just day and night; they needed to predict the fickle seasons for planting, harvesting, and knowing when to throw those wild solstice parties. In short, they needed a calendar!&lt;/p&gt;

&lt;p&gt;Enter the Romans!&lt;br&gt;
After all, we all think about the Roman Empire at least once a day, right? RIGHT?&lt;/p&gt;




&lt;h2&gt;
  
  
  Lunar calendar
&lt;/h2&gt;

&lt;p&gt;Anywho, conveniently enough, like the cycle of day and night, nature had given us yet another cyclical clock in the sky. The Moon! and its phases. The moon, waxing and waning like clockwork every 29.5 days seemed like a natural way to track time. That's how the word Month (literally "Moon-th") originated.&lt;/p&gt;

&lt;p&gt;Their first king, &lt;a href="https://en.wikipedia.org/wiki/Romulus" rel="noopener noreferrer"&gt;Romulus&lt;/a&gt;, established a lunar calendar, based on the same idea. It consisted of 10 months, starting with spring (Martius, now March) and ending with the onset of winter (December). The system is usually said to have left the remaining days before the next Spring as an unorganized "winter" since they were irrelevant to the farming cycle.&lt;/p&gt;

&lt;p&gt;They began by naming months after their gods. but by the fifth month, they threw their hands up and just named them after the good old Latin numbers.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;No.&lt;/th&gt;
&lt;th&gt;Months&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;th&gt;Length in days&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Martius&lt;/td&gt;
&lt;td&gt;Month of &lt;em&gt;Mars&lt;/em&gt;, the Roman god of war.&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Aprilis&lt;/td&gt;
&lt;td&gt;Month of goddess &lt;em&gt;Apru&lt;/em&gt;. (Aphrodite)&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Maius&lt;/td&gt;
&lt;td&gt;Month of &lt;em&gt;Maia&lt;/em&gt;, a Roman goddess of growth and fertility.&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Junius&lt;/td&gt;
&lt;td&gt;Month of &lt;em&gt;Juno&lt;/em&gt;, the Roman goddess of marriage and queen of the gods.&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Quintilis&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;quintus&lt;/em&gt; meaning "fifth.&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Sextilis&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;sextus&lt;/em&gt; meaning "sixth".&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;September&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;septem&lt;/em&gt; meaning "seven".&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;October&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;octo&lt;/em&gt; meaning "eight".&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;November&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;novem&lt;/em&gt; meaning "nine".&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;December&lt;/td&gt;
&lt;td&gt;The Latin word &lt;em&gt;decem&lt;/em&gt; meaning "ten".&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Length of the year&lt;/td&gt;
&lt;td&gt;304&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Lunisolar calendar
&lt;/h2&gt;

&lt;p&gt;Problem was, predicting the end of that chaotic "winter" period was about as easy as herding cats.&lt;/p&gt;

&lt;p&gt;So &lt;a href="https://en.wikipedia.org/wiki/Numa_Pompilius" rel="noopener noreferrer"&gt;Numa Pompilius&lt;/a&gt;, the second king of Rome, tried something.&lt;br&gt;
He reasoned that roughly 12 moon (lunar) cycles occurred between springs (solar), giving a year &lt;code&gt;12 * 29.5 = 354&lt;/code&gt; days. But hold on! Even-numbers were considered bad luck in ancient Rome, so Numa tacked an extra day onto the year, making the target length, a peculiar 355 days long. Then, to appease the odd-number-loving gods, he removed a day from the 30-day months, leaving behind &lt;code&gt;304 - 6 = 298&lt;/code&gt; days.&lt;/p&gt;

&lt;p&gt;With 12 moon cycles to cover, Numa still had &lt;code&gt;355 - 298 = 57&lt;/code&gt; days left over. He split these into two new months: one with 29 days and another with the dreaded even number of 28. The first, named &lt;em&gt;Januarius&lt;/em&gt; after &lt;em&gt;Janus&lt;/em&gt;, the god of beginnings and transitions, was strategically placed at the start of the year. As for the other month, stuck with its even-numbered fate, it was dedicated to spiritual purification and shoved to the end. They called it &lt;em&gt;Februarius&lt;/em&gt;, derived from the Latin word "&lt;em&gt;Februa&lt;/em&gt;" meaning "purification."&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;No.&lt;/th&gt;
&lt;th&gt;Months&lt;/th&gt;
&lt;th&gt;Length in days&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Januarius&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Martius&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Aprilis&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Maius&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;Junius&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;Quintilis&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;Sextilis&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;September&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;October&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;November&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;December&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;Februarius&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Length of the year&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;But, each year fell short of a tropical year by a few days, causing the seasons to drift like a ship without a rudder. After some head-scratching and sky-gazing, the Romans realized their calendar was off by a whopping 45 days every four years!&lt;/p&gt;

&lt;p&gt;So Numa decided to throw in an extra, intercalary month, called &lt;em&gt;Mercedonius&lt;/em&gt;, every other year. This bonus month alternated between 22 and 23 days. To make things tidier, and since Feb 23rd was &lt;a href="https://en.wikipedia.org/wiki/Terminalia_(festival)" rel="noopener noreferrer"&gt;Terminalia&lt;/a&gt; (festival of God Terminus, who presided over boundaries), Numa ended Feb on 23rd and moved the remaining 5 days to the intercalating month to make them 27 and 28 days long. And at the same time, Jan and Feb both were moved to the beginning of the year.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;No.&lt;/th&gt;
&lt;th&gt;Months&lt;/th&gt;
&lt;th&gt;Year 1&lt;/th&gt;
&lt;th&gt;Year 2&lt;/th&gt;
&lt;th&gt;Year 3&lt;/th&gt;
&lt;th&gt;Year 4&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Januarius&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Februarius&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;td&gt;23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Mercedonius&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;27&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;28&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Martius&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;Aprilis&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;td&gt;...&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;December&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;td&gt;29&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Length of the year&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;td&gt;377&lt;/td&gt;
&lt;td&gt;355&lt;/td&gt;
&lt;td&gt;378&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Essentially making the average of all 4 years into &lt;code&gt;(355 + 377 + 355 + 378) / 4 = 366.25&lt;/code&gt;&lt;br&gt;
This jumbled mess of intercalary months and shifting start dates became known as the Roman Republican Calendar. It was a far cry from perfect, but hey, it was a start.&lt;/p&gt;

&lt;p&gt;This is still too many days, but it could have worked. Every 19 solar years would line up with 235 lunar months. Add enough leap months and eventually, everything will reset itself. The seasons will be back on track.&lt;/p&gt;

&lt;p&gt;But the leap months weren't added as planned. Politicians would get them to extend leap month when it's their office and to skip the month when it's their opponents. Also, it was a custom that intercalation had to be personally announced by the chief pontiff in Rome. So, during wars, when the king was out of the city, the leap month was forgotten for years.&lt;/p&gt;




&lt;h2&gt;
  
  
  Solar calendar
&lt;/h2&gt;

&lt;p&gt;By the time &lt;a href="https://en.wikipedia.org/wiki/Julius_Caesar" rel="noopener noreferrer"&gt;Julius Caesar&lt;/a&gt; came to power, things were confusing. He had spent a long time in Egypt, where 365-day calendars were all the rage. So in 46 BC he threw the lunisolar calendar away and ordered his scholars to help design a solar calendar. He got rid of the intercalary month of &lt;em&gt;Mercedonius&lt;/em&gt;, leaving the original 355 days long year. Caesar then sprinkled the missing 10 days across various months, reaching a total of 365.&lt;/p&gt;

&lt;p&gt;The year 46 BC was the last of the old system and included three intercalary months, the first inserted in February and two more—&lt;strong&gt;Intercalaris Prior&lt;/strong&gt; and &lt;strong&gt;Posterior&lt;/strong&gt;—before December, coincidentally making the year of Caesar's third consulship last for 446 days!&lt;/p&gt;

&lt;p&gt;But wait! By now, astronomers knew the tropical year was slightly longer—closer to 365.25 (365 days and 6 hours). So, Caesar added a leap day every four years. However, in a move that would baffle future generations, he inserted it after February 23rd, by doubling 24th, right smack in between the month – there were indeed &lt;a href="https://en.wikipedia.org/wiki/Bissextus" rel="noopener noreferrer"&gt;two days dated 24 February&lt;/a&gt;!&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;No.&lt;/th&gt;
&lt;th&gt;Months&lt;/th&gt;
&lt;th&gt;Length in days&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;January&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;February&lt;/td&gt;
&lt;td&gt;28 + (1 every 4 years)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;March&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4&lt;/td&gt;
&lt;td&gt;April&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;May&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6&lt;/td&gt;
&lt;td&gt;June&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7&lt;/td&gt;
&lt;td&gt;July&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;August&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;td&gt;September&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;October&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;11&lt;/td&gt;
&lt;td&gt;November&lt;/td&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;December&lt;/td&gt;
&lt;td&gt;31&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;Length of the year&lt;/td&gt;
&lt;td&gt;365 + (1 every 4 years)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Following Caesar's assassination, the priests mistakenly added the &lt;a href="https://en.wikipedia.org/wiki/Bissextile" rel="noopener noreferrer"&gt;bissextile&lt;/a&gt; leap day every three years due to their inclusive counting. To bring the calendar back to its proper place, &lt;a href="https://en.wikipedia.org/wiki/Augustus" rel="noopener noreferrer"&gt;Augustus&lt;/a&gt;, the next King, was obliged to suspend intercalation for one or two decades.&lt;/p&gt;

&lt;p&gt;As a tribute to their egos (ahem, I mean contributions), the 7th and 8th months were renamed Julius (for Caesar, obviously) and Augustus (for his successor). &lt;/p&gt;




&lt;h2&gt;
  
  
  A better solar calendar
&lt;/h2&gt;

&lt;p&gt;Unfortunately, the Julian calendar wasn't flawless. It assumed the average solar year was exactly 365.25 days long, overestimating by about 14 minutes. By the year 1582, the excess leap days introduced by the Julian algorithm had caused the calendar to drift such that the &lt;a href="https://en.wikipedia.org/wiki/March_equinox" rel="noopener noreferrer"&gt;March equinox&lt;/a&gt; was occurring well before its nominal 21 March date. This date was important to the Christian churches because it is fundamental to the calculation of the date of Easter.&lt;/p&gt;

&lt;p&gt;To reinstate the association, the then Pope, &lt;a href="https://en.wikipedia.org/wiki/Pope_Gregory_XIII" rel="noopener noreferrer"&gt;Pope Gregory XIII&lt;/a&gt;, did something crazy to the year 1582. He skipped 10 whole days from the calendar! Thursday, October 4th was followed immediately by Friday, October 15th! Good luck negotiating the rent, I guess?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6joag2wbb5yk0gnzyrsv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6joag2wbb5yk0gnzyrsv.png" alt="Calendar of the year 1582 at Italy" width="800" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To ensure that the drift doesn't happen again, Gregory introduced a new calendar, aptly named the Gregorian calendar.&lt;br&gt;
By this time, it was known that a solar year was close to 365.24 days (That's 365 days, 5 hours, 45 minutes, and 36 seconds; for those still keeping track), while the Julian year was 365.25 days. This meant every &lt;code&gt;1 / (365.25 - 365.24) = 100&lt;/code&gt; years an extra day has been accumulated. So, the Gregorian calendar chose to skip adding a leap day every centennial year (those divisible by 100)&lt;/p&gt;

&lt;p&gt;But, the solar year was a smidge longer, around 365.2425 days long. (365 days, 5 hours, 49 minutes, and 12 seconds) Which meant every &lt;code&gt;1/ (365.2425 - 365.24) = 400&lt;/code&gt; years a day has been lost. So, the Gregorian calendar chose to add back a leap day every centennial year divisible by 400.&lt;/p&gt;

&lt;p&gt;This is the calendar we all know (and love?) today. Every year that is exactly divisible by 4, you add a leap day; except for years that are exactly divisible by 100, then you remove the leap day that you would have otherwise added; except if it is divisible by 400, you add back the leap day!&lt;/p&gt;

&lt;p&gt;It took 170 more years, for Britain and its colonies, including India, to follow suit. They skipped 11 days, wherein, Wednesday, 1752, September 2nd was followed by Thursday, September 14.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoxo4c9nt7d97ndzo1um.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoxo4c9nt7d97ndzo1um.png" alt="Calendar of the year 1752 at India" width="800" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In fact, the world is still adopting the Gregorian. Saudi Arabia, for instance, jumped on the Gregorian wagon as late as 2016!&lt;/p&gt;




&lt;h2&gt;
  
  
  Future
&lt;/h2&gt;

&lt;p&gt;So, we finally nailed it right? Close, but not quite.&lt;/p&gt;

&lt;p&gt;Turns out, the solar year is even shorter than the Gregorian calendar accounts for. The latest measurements put it at a mind-bogglingly precise 365.2421897 days. (365 days, 5 hours, 48 minutes, 45 seconds, 19.008 mili-seconds). How long does this take to accumulate an extra day?  &lt;code&gt;1 / (365.2425 - 365.2421897) ~= 3223&lt;/code&gt; years!&lt;/p&gt;

&lt;p&gt;Following the pattern, it seems logical to add back a leap day every 4,000 years, averaging out to 365.24225 days. This would make the calendar drift by a day only once every &lt;code&gt;1 / (365.24225 - 365.2421897) ~= 16584&lt;/code&gt; years! So, why aren't we doing it?&lt;/p&gt;

&lt;p&gt;Well, for starters, as we saw with Gregorian, getting the entire world to adopt a new calendar is nowhere close to easy. But there's a more fundamental reason: it wouldn't be worth the effort.&lt;/p&gt;

&lt;p&gt;The solar year—the time it takes Earth to orbit the sun—is gradually increasing, as is the length of a day. Currently, the length of the year is changing in the sixth decimal place over a person's lifetime. Various cosmic forces are at play here, deserving a blog post in their own right. Any correction based on today's solar year length would become obsolete in a few millennia, requiring yet another adjustment anyway.&lt;/p&gt;

&lt;p&gt;So, for now, we're stuck with the Gregorian calendar, a marvel of human ingenuity with its quirks and imperfections. What makes this feat even more remarkable is that telescopes weren't even invented when these calendars were designed! All of this was achieved with the naked eye, by observing the shadows cast by sticks and gazing up at the celestial dance above.&lt;/p&gt;

&lt;p&gt;As we navigate the complexities of our modern world, perhaps we can take a cue from the ever-shifting cosmos and embrace the fluidity of time itself. After all, isn't life a little more adventurous when we're not always running on schedule?&lt;/p&gt;




&lt;h3&gt;
  
  
  Bonus
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://www.timeanddate.com/calendar/?year=2024&amp;amp;country=35" rel="noopener noreferrer"&gt;timeanddate.com&lt;/a&gt; to look at calendars of any year in any given country.&lt;/li&gt;
&lt;li&gt;Try finding the 10-day skip in October of 1582 in Italy!&lt;/li&gt;
&lt;li&gt;Try finding the 11-day skip in September of 1752 in India!&lt;/li&gt;
&lt;li&gt;Look at the &lt;a href="https://en.wikipedia.org/wiki/List_of_adoption_dates_of_the_Gregorian_calendar_by_country" rel="noopener noreferrer"&gt;Adoption dates of Gregorian Calendar by Country&lt;/a&gt; table, to find when a given country adopted the Gregorian and how many days they skipped to synchronize.&lt;/li&gt;
&lt;li&gt;Which country skipped the most days? Check out the same in the timeanddate tool above.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Sources and references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Roman_calendar" rel="noopener noreferrer"&gt;Roman Calendar&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/List_of_adoption_dates_of_the_Gregorian_calendar_by_country" rel="noopener noreferrer"&gt;Adoption dates of the Gregorian Calendar by country&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/IJhgZBn-LHg?si=fR0jHkk3K79RhlPF" rel="noopener noreferrer"&gt;How Earth Moves&lt;/a&gt;, video by VSauce.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.grc.nasa.gov/www/k-12/Numbers/Math/Mathematical_Thinking/calendar_calculations.htm#:~:text=The%20tropical%20year%20is%20the,46%20seconds%2C%20or%20365.2422%20days." rel="noopener noreferrer"&gt;Calendar calculations&lt;/a&gt;,  by NASA.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/AgKaHTh-_Gs?si=eFmQgqjmJP_oEHlO" rel="noopener noreferrer"&gt;Why Does February Only Have 28 Days?&lt;/a&gt;, video by "Be Smart".&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://youtu.be/WkhrL8NMycU?si=BSD1brY2OTGxK_jz" rel="noopener noreferrer"&gt;Neil deGrasse Tyson Explains Why We Have Leap Days&lt;/a&gt;, video by StarTalk.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>calendar</category>
    </item>
    <item>
      <title>Quine: Self replicating computer programs</title>
      <dc:creator>Darshan A S</dc:creator>
      <pubDate>Fri, 12 Jul 2024 04:14:29 +0000</pubDate>
      <link>https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g</link>
      <guid>https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g</guid>
      <description>&lt;p&gt;A &lt;em&gt;&lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quine&lt;/a&gt;&lt;/em&gt;, (/&lt;em&gt;kwi:n&lt;/em&gt;/ pronounced Kwine) is a self-replicating computer program, a digital life if you will. It takes no input and prints a copy of its own source code.&lt;/p&gt;

&lt;p&gt;This may sound impossible, trivial, or completely uninteresting, depending on your temper and your knowledge of computer science. Trust me, it is not only not impossible, by the end of this post you'll have written your first Quine in Python.&lt;/p&gt;

&lt;p&gt;The name "Quine" was coined by &lt;a href="https://en.wikipedia.org/wiki/Douglas_Hofstadter" rel="noopener noreferrer"&gt;Douglas Hofstadter&lt;/a&gt;, in his popular science book &lt;em&gt;&lt;a href="https://en.wikipedia.org/wiki/G%C3%B6del,_Escher,_Bach" rel="noopener noreferrer"&gt;Gödel, Escher, Bach&lt;/a&gt;&lt;/em&gt;, in honour of the philosopher &lt;a href="https://en.wikipedia.org/wiki/Willard_Van_Orman_Quine" rel="noopener noreferrer"&gt;Willard Van Orman Quine&lt;/a&gt; (1908-2000), who made an extensive study of indirect self-reference, and in particular for the following paradox-producing expression, known as Quine's paradox:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The easiest way to write a Quine, of course, is to read the source file on the disk and print its contents. That may be done, but it is considered cheating; besides, the program might not know where the source file is, it may have access to only the compiled data, or the programming language may simply forbid that sort of operation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Your first Quine
&lt;/h2&gt;

&lt;p&gt;Before we start,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"If you have never done this, I urge you to try it on your own. The discovery of how to do it is a revelation that far surpasses any benefit obtained by being told how to do it."&lt;br&gt;
– Ken Thompson&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That said, below is a step-by-step guide to writing your first Quine in Python:&lt;/p&gt;

&lt;p&gt;Let's start with 2 pieces in our program.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A variable to hold the string representation of the source code; call this the &lt;em&gt;Data&lt;/em&gt; part.&lt;/li&gt;
&lt;li&gt;A print statement to output the variable; call this the &lt;em&gt;Code&lt;/em&gt; part.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we are to take an analogy with cellular biology (thanks to Douglas Hofstadter, again), think of a Quine as a cell with its own DNA. What I have called the &lt;em&gt;data&lt;/em&gt; would be the DNA, and the &lt;em&gt;code&lt;/em&gt; would be the rest of the cell. The cell is able to create a new cell using the DNA, and this involves, among other things, replicating the DNA itself. So the DNA (the data) contains all the necessary information for the replication, but without the cell (the code), or at least some other code to make the data live, it is a useless, inert, piece of data.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;Let's have a variable to store the &lt;em&gt;data&lt;/em&gt; part. And since we don't know the final source code yet, let's use &lt;code&gt;???&lt;/code&gt; as a placeholder. Print statements will read the &lt;code&gt;data&lt;/code&gt; to replicate itself, thereby acting as the &lt;em&gt;code&lt;/em&gt; part.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkHJ3t5eiaugKDOvRAMkpPn/PwA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;???&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Output
&lt;/span&gt;&lt;span class="err"&gt;???&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not quite what we're looking for, is it?&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;We can't just print the contents of the &lt;code&gt;data&lt;/code&gt; variable. We need to print the very act of declaring the variable itself. Let's add another &lt;code&gt;print&lt;/code&gt; statement to do just that.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkHJ3t5eiaugKDOvREMdIqauowBiaForQITBnP//AQ" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;???&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;???&lt;/span&gt;
&lt;span class="err"&gt;???&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sweet. It's starting to look structurally similar. But we still have those pesky &lt;code&gt;???&lt;/code&gt; marks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;Notice that the second line of output is &lt;code&gt;???&lt;/code&gt;, which corresponds to the part of the source code we initially didn't know how to fill. This means, we can replace &lt;code&gt;???&lt;/code&gt; to whatever the second line of source code becomes.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkGpoCgzr0RDHcJV11EAMTStFSDCYI4SF2E1//8DAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, data); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Almost there! But we seem to be missing the double quotes in line 1.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4
&lt;/h4&gt;

&lt;p&gt;In Python&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;str('hi')&lt;/code&gt; outputs &lt;code&gt;hi&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;repr('hi')&lt;/code&gt; outputs &lt;code&gt;"hi"&lt;/code&gt;, with quotes!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's exactly what we need. Let's wrap &lt;code&gt;data&lt;/code&gt; in the second line with &lt;code&gt;repr&lt;/code&gt; to get those quotes.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkGpoCgzr0RDHcJV11EAMTStFSDCYI4SF7qaotSCIogcqsr//wE" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, data); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, data); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yay! Line 1 in the source and output are an exact match.&lt;br&gt;
But in doing so, we altered line 2 of the source!&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 5
&lt;/h4&gt;

&lt;p&gt;We can fix this by setting the value of the &lt;code&gt;data&lt;/code&gt; variable to the updated &lt;em&gt;code&lt;/em&gt; part.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/PyWxJFHBVkGpoCgzr0RDHcJV11EoSi0o0gDxNDWtFSCSYJ4SF7Eq//8HAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;, repr(data)); print(data)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;data =&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;repr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Viola! There you have it. A valid Quine!&lt;/p&gt;




&lt;p&gt;Although I've picked Python here, it's purely due to personal familiarity and brevity, there's nothing special about it. Quines are a general consequence of the so-called &lt;a href="https://en.wikipedia.org/wiki/Kleene%27s_recursion_theorem" rel="noopener noreferrer"&gt;Kleene's Fixed-Point theorem&lt;/a&gt;, which essentially means that a Quine (in fact, infinitely many) can be written in any Turing-complete programming language.&lt;/p&gt;

&lt;p&gt;Almost all programming languages you've heard or used so far are Turing complete.&lt;br&gt;
No, not HTML and CSS, they are not programming languages, let alone Turing-complete. Get over it.&lt;/p&gt;

&lt;p&gt;One word of warning: this code/data distinction in Quines is pleasant and often helpful. It is not, however, completely valid in all circumstances&lt;/p&gt;


&lt;h2&gt;
  
  
  Shortest Quine
&lt;/h2&gt;

&lt;p&gt;In 1983, &lt;a href="https://en.wikipedia.org/wiki/Ken_Thompson" rel="noopener noreferrer"&gt;Ken Thompson&lt;/a&gt; in his Turing Award acceptance speech, &lt;a href="https://fermatslibrary.com/s/reflections-on-trusting-trust" rel="noopener noreferrer"&gt;Reflections on Trusting Trust&lt;/a&gt;, presented the persistent compiler backdoor attack now known as the &lt;em&gt;Thompson hack&lt;/em&gt; or &lt;em&gt;Trusting trust attack&lt;/em&gt;.&lt;br&gt;
Although the paper itself is widely considered a seminal computer security work in its own right, he also made a peculiar statement about Quines.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;”In college, before video games, we would amuse ourselves by posing programming exercises. One of the favorites was to write the shortest self-reproducing program. Since this is an exercise divorced from reality, the usual vehicle was FORTRAN. Actually, FORTRAN was the language of choice for the same reason that three-legged races are popular.“&lt;br&gt;
– Ken Thompson&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I claim no knowledge whatsoever of FORTRAN. So, here's the shortest Quine in Python:&lt;/p&gt;

&lt;p&gt;Python:  &lt;a href="https://tio.run/##K6gsycjPM/7/P95WPd5Wtci6oCgzr0QjXlU1XlMdzonX/P8fAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_=%r;print(_%%_)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks esoteric, doesn't it? But don't let the compactness fool you. Let's decipher how we could have arrived at the shortest one ourselves.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1
&lt;/h4&gt;

&lt;p&gt;Let's start with&lt;/p&gt;

&lt;p&gt;Python Input:  &lt;a href="https://tio.run/##K6gsycjPM/7/P0XBVkHd3t5enaugKDOvRCNF8/9/AA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;???&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="err"&gt;???&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2
&lt;/h4&gt;

&lt;p&gt;Let's add the entire source code from previous step into &lt;code&gt;d&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/P0XBVkEdRNjb28fkFRRl5pVopGiqc8FY//8DAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = ???&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;print(d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;???&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you noticed the output. We just want to replace &lt;code&gt;???&lt;/code&gt; with the exact value of variable &lt;code&gt;d&lt;/code&gt; and we are done!&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3
&lt;/h4&gt;

&lt;p&gt;There's a nifty trick in Python to do this. The &lt;code&gt;str(d)&lt;/code&gt; and &lt;code&gt;repr(d)&lt;/code&gt; have a shortcut symbol of &lt;code&gt;%s&lt;/code&gt; and &lt;code&gt;%r&lt;/code&gt; respectively, and can be used like below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bruce Wayne is %s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Batman&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# outputs: Bruce Wayne is Batman
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bruce Wayne is %r&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Batman&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# outputs: Bruce Wayne is 'Batman'
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using that, replace &lt;code&gt;???&lt;/code&gt; with &lt;code&gt;%r&lt;/code&gt; and substitute &lt;code&gt;d&lt;/code&gt; onto itself in line 2.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/P0XBVkEdRKgWxeQVFGXmlWikaKpzQVkKqgopmv//AwA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = %r&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;print(d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = %r&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;print(d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So close! We are just missing the &lt;code&gt;% d&lt;/code&gt; in the second line.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 4
&lt;/h4&gt;

&lt;p&gt;Let's add that &lt;code&gt;% d&lt;/code&gt; in line 1 of the source.&lt;br&gt;
But hold on &lt;code&gt;% d&lt;/code&gt; would make Python look for a second value to be replaced.&lt;br&gt;
To tell Python not to, we have to escape the &lt;code&gt;%&lt;/code&gt; symbol. This can be done by adding another &lt;code&gt;%&lt;/code&gt; in front.&lt;/p&gt;

&lt;p&gt;Python Input: &lt;a href="https://tio.run/##K6gsycjPM/7/P0XBVkEdRKgWxeQVFGXmlWikKKiqKqRoqnPBuUDe//8A" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = %r&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;print(d %% d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = %r&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;print(d %% d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a valid Quine!&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 5
&lt;/h4&gt;

&lt;p&gt;Now, to make it short. Let's get rid of the newline character and combine both lines using &lt;code&gt;;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;d = %r;print(d %% d)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables can start with underscores. A single underscore is in and of itself a valid variable. Let's replace &lt;code&gt;d&lt;/code&gt; with &lt;code&gt;_&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_ = %r;print(_ %% _)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Get rid of all the spaces. &lt;/p&gt;

&lt;p&gt;Python: &lt;a href="https://tio.run/##K6gsycjPM/7/P95WPd5Wtci6oCgzr0QjXlU1XlMdzonX/P8fAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_=%r;print(_%%_)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There you have it. The shortest Quine.&lt;/p&gt;




&lt;p&gt;Here's an interesting one: An Error-Quine in Python. The source code is an error-like text that throws the exact error when executed.&lt;br&gt;
The only difference being the output now goes to &lt;em&gt;stderr&lt;/em&gt; instead of &lt;em&gt;stdout&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Python:  &lt;a href="https://tio.run/##K6gsycjPM/7/X0HBLTMnVUEpOT8lVa8kM19JRyEnMy9VwZBLQQG/XByXZ15Kal5JIlAmz7WoKL/ISqE0L7WiIDW5JDVFIRMs@f8/AA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;  &lt;span class="n"&gt;File&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;quine.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;File&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;quine.py&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="o"&gt;^&lt;/span&gt;
&lt;span class="nb"&gt;IndentationError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unexpected&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Some more Quines
&lt;/h2&gt;

&lt;p&gt;Ruby: &lt;a href="https://tio.run/##KypNqvz/v9hWqdhWtcC6oLSkWKFYVbVYCcYs5vr/HwA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"s=%p;puts s%%s"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lua: &lt;a href="https://tio.run/##yylN/P@/2Fap2Fa1sKAoM69Eo9gqLb8oNxHI0NRUwhTi@v8fAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"s=%qprint(s:format(s))"&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perl 5: &lt;a href="https://tio.run/##K0gtyjH9/1@l2LZQA0yoFmtaFxRl5pWkAfk6KkAeOp/r/38A" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight perl"&gt;&lt;code&gt;&lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sx"&gt;q($s=q(%s);printf($s,$s);)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$s&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript: &lt;a href="https://tio.run/##y0osSyxOLsosKNHNy09J/f@/2Fap2FY1yzo5P684PydVLyc/XaNYp1hTCUOE6/9/AA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;s=%j;console.log(s,s)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C: &lt;a href="https://tio.run/##S9ZNT07@/z83MTNPo1izuqAoM68kTaPYVglDRDVZtVjVUCVZx9hEp1jTulYJxvj/HwA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight c"&gt;&lt;code&gt;&lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main(s){printf(s=%c%s%1$c,34,s);}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;);}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Java: &lt;a href="https://tio.run/##y0osS9TNSsn@/z85J7G4WCGwuqA0KSczWaG4JLEESJXlZ6Yo5CZm5mkElxRl5qVHxyZqVkOYCsW2SuRoUk1WLVY1VEm2Dq4sLknN1csvLdErAMqVpGkU6xib6BRrWtfWKuGV5fr/HwA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Q&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"class Q{public static void main(String[]a){String s=%c%s%1$c;System.out.printf(s,34,s);}}"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;printf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;);}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rust: &lt;a href="https://tio.run/##KyotLvn/Py1PITcxM09Ds7qgKDOvRFFDCSECE6o2sLKv1QGTmrW1SjqElWjW/v8PAA" rel="noopener noreferrer"&gt;Try it online!&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="nd"&gt;print!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"fn main(){{print!({0:?},{0:?})}}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"fn main(){{print!({0:?},{0:?})}}"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HQ9+: &lt;a href="https://hci.mkps.app/" rel="noopener noreferrer"&gt;Try pasting it Online&lt;/a&gt;&lt;br&gt;
&lt;a href="https://esolangs.org/wiki/HQ9%2B" rel="noopener noreferrer"&gt;Wiki page of HQ9+ language&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Quines are a fascinating topic and an art in their own right.&lt;br&gt;
We'll go more in-depth and explore topics like &lt;strong&gt;&lt;a href="https://dev.to/darshan-as/intron-junk-or-not-junk-that-is-the-quine-tion-44nl"&gt;Intron&lt;/a&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;a href="https://dev.to/darshan-as/quinerelay-birth-of-the-quine-serpent-48be"&gt;QuineRelay&lt;/a&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;a href="https://dev.to/darshan-as/multiquine-weaving-the-web-of-quines-23me"&gt;MultiQuine&lt;/a&gt;&lt;/strong&gt;, and much more in the follow-up posts.&lt;/p&gt;

&lt;p&gt;Stay tuned!&lt;/p&gt;




&lt;p&gt;Sources and references:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://en.wikipedia.org/wiki/Quine_(computing)" rel="noopener noreferrer"&gt;Quine (computing)&lt;/a&gt;, wiki page.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/darshan-as/quine-self-replicating-computer-programs-1c5g"&gt;Quine: Self replicating computer programs&lt;/a&gt;, self-referencing blog.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=a-zEbokJAgY" rel="noopener noreferrer"&gt;Self-replicating Python code | Quine&lt;/a&gt;, Youtube video by Lex Fridman.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.cs.cmu.edu/~rdriley/487/papers/Thompson_1984_ReflectionsonTrustingTrust.pdf" rel="noopener noreferrer"&gt;Reflections on Trusting Trust&lt;/a&gt;, paper by Ken Thompson.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.goodreads.com/book/show/24113.G_del_Escher_Bach" rel="noopener noreferrer"&gt;Gödel, Escher, Bach: An Eternal Golden Braid&lt;/a&gt;, book by Douglas R. Hofstadter.&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.madore.org/~david/computers/quine.html" rel="noopener noreferrer"&gt;Quines (self-replicating programs)&lt;/a&gt;, blog by David Madore.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.nyx.net/~gthompso/quine.htm" rel="noopener noreferrer"&gt;The Quine Page&lt;/a&gt;, blog by Gary P. Thompson II.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://cs.lmu.edu/~ray/notes/quineprograms/" rel="noopener noreferrer"&gt;Quine Programs&lt;/a&gt;, blog by Ray Toal.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>quine</category>
      <category>dna</category>
      <category>selfrep</category>
      <category>python</category>
    </item>
  </channel>
</rss>
