<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>drcabana.org</title>
    <subtitle>Computational divertissements</subtitle>
    <link rel="self" type="application/atom+xml" href="https://drcabana.org/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://drcabana.org/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-10-31T00:00:00+00:00</updated>
    <id>https://drcabana.org/atom.xml</id>
    <entry xml:lang="en">
        <title>Week 4</title>
        <published>2026-10-31T00:00:00+00:00</published>
        <updated>2026-10-31T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/janko/10-31-2026/"/>
        <id>https://drcabana.org/janko/10-31-2026/</id>
        
        <content type="html" xml:base="https://drcabana.org/janko/10-31-2026/">&lt;p&gt;The real world is currently intruding on my time. Tia is in the hospital post heart surgery, her recovery is not going well. I&#x27;ll be in Tampa for a week starting next Saturday.&lt;&#x2F;p&gt;
&lt;p&gt;One month in and I am still not a pianist, who could have expected it.  My scales are slowly improving, but I find it takes a good bit of warmup to achieve what passes for my best play. I cannot walk up to the piano and start playing, I first have to &#x27;get there&#x27;. I expect month after month of practice will reduce the warmup time, with a decent cold start indicating the requisite skills are baked in to my nervous system.&lt;&#x2F;p&gt;
&lt;p&gt;Have started working on major&#x2F;minor&#x2F;dim triads, but I have to think deliberately about the shapes, they are nowhere near automatic.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Week 3</title>
        <published>2026-10-24T00:00:00+00:00</published>
        <updated>2026-10-24T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/janko/10-24-2026/"/>
        <id>https://drcabana.org/janko/10-24-2026/</id>
        
        <content type="html" xml:base="https://drcabana.org/janko/10-24-2026/">&lt;p&gt;I focused on trying to speed up my major scales, fully knowing that this was suboptimal. I just wanted to get it out of my system.  I got up to playing C and F major at 180 bpm quarter notes, fast enough to satisfy my beginner&#x27;s curiosity.  Towards the end of the week I switched to playing all the major scales in order of fifths at 60-80 bpm.  I will speed up asspeed become natural and does not come at the expense of consistent volume or legato.&lt;&#x2F;p&gt;
&lt;p&gt;Something that struck me while practicing the major scale was a multi octave scale run contains each of the modes for that key. I made a note of which finger plays the 6th degree of the major scale on each hand and compared it to Rico Raven&#x27;s &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;playlist?list=PLU-gla-Ho6-qXJtvLSm4QgwN0pA3s5dvl&quot;&gt;suggested fingering&lt;&#x2F;a&gt; of the minor scale, boom. Money for nothing, and modes for free.&lt;&#x2F;p&gt;
&lt;p&gt;Re coming up with a better learning plan, I remembered that &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.zombieguitar.com&#x2F;&quot;&gt;Zombie Guitar&lt;&#x2F;a&gt; recommends for guitarists interested in learning &#x27;keys&#x27; an inexpensive program called &#x27;Piano for All&#x27;. I further recalled that my wife had purchased a copy of the same a couple of years ago.  I found it on her computer and haved decided to give it a try. More on that next week.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Week 2</title>
        <published>2026-10-17T00:00:00+00:00</published>
        <updated>2026-10-17T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/janko/10-17-2026/"/>
        <id>https://drcabana.org/janko/10-17-2026/</id>
        
        <content type="html" xml:base="https://drcabana.org/janko/10-17-2026/">&lt;p&gt;I spent far too much time this trying to compensate for the fact that the workdesk I tried to use as a keyboard stand was just too tall. I finally ordered a height-adjustable keyboard stand which arrived today.&lt;&#x2F;p&gt;
&lt;p&gt;The standard keyboard is essentially linear, the hands move left and right. The Janko keyboard adds a north\south motion as each key has two levels, which adds a second degree of freedom to hand motion. This makes it easier for the thumb to pass under the fingers when needed. This bit was a pleasant surprise.&lt;&#x2F;p&gt;
&lt;p&gt;Two weeks in and I am still getting my hands familiar with the keyboard. Nothing feels entirely natural. I fight my impatience to do more than practice scales by remembering the countless times I have practiced the clawhammer banjo &#x27;bum diddy&#x27; stroke. It is a much simpler motion than a piano scale and yet I have much benefited from endless practice. Gotta stay humble and enjoy the process.&lt;&#x2F;p&gt;
&lt;p&gt;I will eventually need to find an organized approach to learning piano. I am not inclined to look for a local teacher because I assume all will teach the standard keyboard.  Going to their studio I would have no instrument, and I don&#x27;t relish looking for (or paying for) someone to come to my house only to discover they can&#x27;t play my instrument. Fortunately there seems to be no end of online lessons. I will have to try one or more methods to find one that works for me.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Week 1</title>
        <published>2026-10-10T00:00:00+00:00</published>
        <updated>2026-10-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/janko/10-10-2026/"/>
        <id>https://drcabana.org/janko/10-10-2026/</id>
        
        <content type="html" xml:base="https://drcabana.org/janko/10-10-2026/">&lt;p&gt;I am taking up the piano at age 69. Why? Several reasons.&lt;&#x2F;p&gt;
&lt;p&gt;I believe that one must &#x27;use it or lose it&#x27;, whatever &#x27;it&#x27; may be. For me it is neuroplasticity. I think the best way to preserve my nervous system&#x27;s ability to adapt is to keep learning and doing difficult new things. Piano fits the bill perfectly, presenting simultaneous physical and intellectual challenges.&lt;&#x2F;p&gt;
&lt;p&gt;I want to better understand music theory. Western music theory, which co-evolved with the keyboard. I play guitar and banjo, but alas not piano. I need to fix that because the keyboard is the ideal place to contemplate music theory. The design of the conventional piano keyboard means that scales&#x2F;chords&#x2F;intervals can have different fingerings when played in different keys. The isomorphic Janko keyboard removes those asymmetries and so simplifies the practical application of theory by the player.&lt;&#x2F;p&gt;
&lt;p&gt;I am drawn by the fantastic harmonic possibilities the piano presents. A guitar has six strings and so a maximum of six notes in a chord. On piano one has both hands fully available, twelve fingers on 88 strings. Endless possibility.&lt;&#x2F;p&gt;
&lt;p&gt;How do I start? First I want to acclimate my hands to the keyboard. My plan is to play the major scale frequently and regularly until it becomes so engrained in my nervous system that it is automatic. I&#x27;ve been playing C and F major scales, both hands in unison across two octaves, up and down. Once I can do those to my satisfaction at a reasonable speed (160 bpm?) I&#x27;ll add the rest of the major scales,  and practice them all in order of fifths. Then I&#x27;ll add major and minor triads, and the natural minor and pentatonic scales.  No need to overthink the plan in advance, I&#x27;ll have plenty of time to refine it since I have many weeks of major scales still to play.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Misc links</title>
        <published>2024-02-18T00:00:00+00:00</published>
        <updated>2024-02-18T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/links3141/links/"/>
        <id>https://drcabana.org/links3141/links/</id>
        
        <content type="html" xml:base="https://drcabana.org/links3141/links/">&lt;h5 id=&quot;login-pages&quot;&gt;Login pages&lt;&#x2F;h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;learnpracticeplay.com&#x2F;login&#x2F;&quot;&gt;login&lt;&#x2F;a&gt; to Paul Davids Guitar site (david@drcabana.org)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.zombieguitar.com&#x2F;login&#x2F;&quot;&gt;login&lt;&#x2F;a&gt; to Zombie Guitar (verdadquesi@drcabana.org)&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.murphymethod.com&#x2F;library&quot;&gt;login to Murphy Method&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;banjobenclark.com&#x2F;lessons&quot;&gt;login to Banjo Ben Clark&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h5 id=&quot;misc&quot;&gt;Misc&lt;&#x2F;h5&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=xKEG7_OXdZA&amp;amp;t=27s&quot;&gt;Fly Away tutorial&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>A quine in Flix</title>
        <published>2023-06-22T00:00:00+00:00</published>
        <updated>2023-06-22T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/flixquine/"/>
        <id>https://drcabana.org/flixquine/</id>
        
        <content type="html" xml:base="https://drcabana.org/flixquine/">&lt;p&gt;One of my standard exercises when learning a new programming language is to write a quine.
Here is a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;flix.dev&quot;&gt;Flix&lt;&#x2F;a&gt; language quine.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;def quine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; Unit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;\&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;    IO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;    let xs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;List&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; List&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 4&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;def quine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; Unit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;    IO&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 6&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;    let xs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;List&lt;&#x2F;span&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; List&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span&gt;{&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 7&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;    };&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 8&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; join &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;String.&lt;&#x2F;span&gt;&lt;span&gt;flatten;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt; 9&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; get &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;List.&lt;&#x2F;span&gt;&lt;span&gt;slice;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;10&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; len &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;List.&lt;&#x2F;span&gt;&lt;span&gt;length;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;11&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; cp2v &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; c &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        match &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;CodePoint.&lt;&#x2F;span&gt;&lt;span&gt;toChars(c) {&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;13&lt;&#x2F;span&gt;&lt;span&gt;        &amp;quot;            case&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; Some&lt;&#x2F;span&gt;&lt;span&gt;(v)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; v&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;14&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;            case&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; None&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; Vector&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span&gt;{}};&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;15&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; st &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;16&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        cp2v(x)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; |&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;Vector.&lt;&#x2F;span&gt;&lt;span&gt;get(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; |&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;Char.&lt;&#x2F;span&gt;&lt;span&gt;toString;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;17&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; (qte, comma, bslash, space)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;18&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        (st(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0x0022&lt;&#x2F;span&gt;&lt;span&gt;), st(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0x002C&lt;&#x2F;span&gt;&lt;span&gt;), st(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0x005C&lt;&#x2F;span&gt;&lt;span&gt;), st(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0x0020&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;19&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; pad &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; join(space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;20&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; quote &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;21&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        join(pad&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;pad&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;qte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;qte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;22&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; quoteComma &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;23&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        x &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; join(pad&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;pad&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;qte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;qte&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span&gt;comma&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;24&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    let&lt;&#x2F;span&gt;&lt;span&gt; firstLine &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;25&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        join(get({start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;}, {end&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;}, xs)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; :::&lt;&#x2F;span&gt;&lt;span&gt; bslash&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;::&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;Nil&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;26&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    firstLine &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;|&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; println;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;27&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    foreach(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;28&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;-&lt;&#x2F;span&gt;&lt;span&gt; get({start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;}, {end&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;}, xs))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;29&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;|&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; println;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;30&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    foreach(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;31&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;-&lt;&#x2F;span&gt;&lt;span&gt; get({start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;},{end&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;len(xs)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;}, xs))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        quoteComma(line)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; |&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; println;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;33&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    foreach(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;-&lt;&#x2F;span&gt;&lt;span&gt; get({start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;len(xs)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;},{end&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;len(xs)}, xs))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;35&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        quote(line)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; |&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; println;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;36&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    foreach(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;37&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;-&lt;&#x2F;span&gt;&lt;span&gt; get({start&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;}, {end&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;len(xs)}, xs))&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;38&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;        line &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;|&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; println&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;39&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        &amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;40&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;41&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let join = String.flatten;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;42&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let get = List.slice;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;43&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let len = List.length;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;44&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let cp2v = c -&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;45&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        match CodePoint.toChars(c) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;46&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;            case Some(v) =&amp;gt; v&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;47&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;            case None =&amp;gt; Vector#{}};&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;48&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let st = x -&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;49&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        cp2v(x) |&amp;gt; Vector.get(0) |&amp;gt; Char.toString;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;50&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let (qte, comma, bslash, space) =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;51&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        (st(0x0022), st(0x002C), st(0x005C), st(0x0020));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;52&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let pad = join(space::space::space::space::Nil);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;53&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let quote = x -&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;54&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        join(pad::pad::qte::x::qte::Nil);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;55&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let quoteComma =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;56&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        x -&amp;gt; join(pad::pad::qte::x::qte::comma::Nil);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;57&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    let firstLine =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;58&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        join(get({start=0}, {end=1}, xs) ::: bslash::Nil);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    firstLine |&amp;gt; println;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;60&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    foreach(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;61&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line &amp;lt;- get({start=1}, {end=3}, xs))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;62&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line |&amp;gt; println;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;63&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    foreach(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line &amp;lt;- get({start=0},{end=len(xs)-1}, xs))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;65&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        quoteComma(line) |&amp;gt; println;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;66&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    foreach(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;67&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line &amp;lt;- get({start=len(xs)-1},{end=len(xs)}, xs))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;68&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        quote(line) |&amp;gt; println;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;69&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    foreach(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;70&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line &amp;lt;- get({start=3}, {end=len(xs)}, xs))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;71&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;        line |&amp;gt; println&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot; style=&quot;color: #90908A;&quot;&gt;72&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you want to run this code you likely want to grab it as a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&#x2F;gists&#x2F;raw&#x2F;branch&#x2F;main&#x2F;quine.flix&quot;&gt;gist&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The code follows the quine generation approach I describe &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine&#x2F;&quot;&gt;here&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine2&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;, adapted to the syntax of the Flix language.&lt;&#x2F;p&gt;
&lt;p&gt;I did not put any comments in the code itself, but some remarks are in order:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;I use short names to help keep the individual lines short. This is the reason for the definitions in lines 41-43.&lt;&#x2F;li&gt;
&lt;li&gt;Notice that no double quote characters appear anywhere except to denote string literals in the &lt;strong&gt;xs&lt;&#x2F;strong&gt; data structure.  This is purpose of lines 44-51.&lt;&#x2F;li&gt;
&lt;li&gt;Flix does not currently allow trailing commas in lists; lines 66-68 are needed to handle that special case.&lt;&#x2F;li&gt;
&lt;li&gt;Flix strings do not allow the use of the unescaped backslash character.  That character is used in the first line of the program as part of the syntax for declaring the IO effect. Lines 57-59 handle printing that first line.&lt;&#x2F;li&gt;
&lt;li&gt;I suspect a much cleverer and shorter Flix quine is possible. But brevity was not my goal, for reasons explained &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine5&#x2F;&quot;&gt;here&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;If the syntax highlighting above looks wonky, that&#x27;s because it is. The highlight software I&#x27;m using does not (yet) support Flix, so I told it to highlight the code as Haskell.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>ssh with multiple github accounts</title>
        <published>2023-06-21T00:00:00+00:00</published>
        <updated>2023-06-21T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/git-ssh/"/>
        <id>https://drcabana.org/git-ssh/</id>
        
        <content type="html" xml:base="https://drcabana.org/git-ssh/">&lt;p&gt;Suppose you maintain several github accounts (say personal and work accounts) and have
separate ssh keys for the accounts.  You can use host aliases in your ssh config file to simplify your ssh&#x2F;github interactions. Include entries in along these lines in ~&#x2F;.ssh&#x2F;config:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #88846F;&quot;&gt;# Personal account&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Host&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; personal.github.com&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; git&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  IdentityFile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; ~&#x2F;.ssh&#x2F;personal_key&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  HostName&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; github.com&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #88846F;&quot;&gt;# Work account&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Host&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; work.github.com&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  User&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; git&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  IdentityFile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; ~&#x2F;.ssh&#x2F;work_key&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  HostName&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; github.com&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A work project using the above might have something like this in its .git&#x2F;config file.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;url&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = ssh:&#x2F;&#x2F;work.github.com&#x2F;user_name&#x2F;work_project.git&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;A personal project would instead use something like&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;url&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = ssh:&#x2F;&#x2F;personal.github.com&#x2F;user_name&#x2F;personal_project.git&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The host alias in the url implicitly selects the the appropriate ssh key to use.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>The case of the unexpected job interview</title>
        <published>2022-01-29T00:00:00+00:00</published>
        <updated>2022-01-29T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/interview/"/>
        <id>https://drcabana.org/interview/</id>
        
        <content type="html" xml:base="https://drcabana.org/interview/">&lt;p&gt;I like to check out the news and gossip on &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;lobste.rs&#x2F;&quot;&gt;lobste.rs&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;news.ycombinator.com&#x2F;newest&quot;&gt;ycombinator&lt;&#x2F;a&gt;. One recurring theme is the sad state of practices around the interview and hiring of programmers. I was reading such a thread back around the time when &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;blog.codinghorror.com&#x2F;why-cant-programmers-program&#x2F;&quot;&gt;FizzBuzz&lt;&#x2F;a&gt; was all the rage.&lt;&#x2F;p&gt;
&lt;p&gt;One gentleman mentioned that he liked to ask candidates to implement long addition. No tricks mind you, it was not about parsing dubious strings into integers and handling the error cases. Just take valid string representations of two integers and add them. He talked a bit about the sort of errors candidates would make, and some of the hints he would offer.  His code examples were in C. The code seemed more complex than I would have expected, but I&#x27;m the sort who takes every opportunity to avoid programming C.&lt;&#x2F;p&gt;
&lt;p&gt;I got to wondering how hard this could be, and decided to give it a shot in python.  I&#x27;m going from memory, but below is pretty much what I came up with. The way long addition works has a more or less natural representation.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Long addition of non-negative base 10 ints represented by strings of digits.&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;from&lt;&#x2F;span&gt;&lt;span&gt; random&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; import&lt;&#x2F;span&gt;&lt;span&gt; randint&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; left_pad&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;string&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; required_len&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;Pad on the left with 0 to meet required length.&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    padding_len&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; required_len&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; -&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(string)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; padding_len&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;0&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; *&lt;&#x2F;span&gt;&lt;span&gt; padding_len&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; columns&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; b&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    Set up numeric strings a and b for addition by left padding the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    shorter with zeros to match length of longer. Return list of&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    columns, ie list of pairs of corresponding digits.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    maxlen&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; max&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;(a),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(b))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits_a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; left_pad(a, maxlen)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits_b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; left_pad(b, maxlen)]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; list&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;zip&lt;&#x2F;span&gt;&lt;span&gt;(digits_a, digits_b))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; add&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; b&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    Add two numeric strings via standard base 10 long addition,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    return the sum as a string.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    carry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; x, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; reversed&lt;&#x2F;span&gt;&lt;span&gt;(columns(a, b)):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        carry, digit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; divmod&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; carry,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        digits.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;(digit))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; carry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        digits.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;(carry))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;.join(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;reversed&lt;&#x2F;span&gt;&lt;span&gt;(digits))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; test&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;Returns True when all randomized tests pass.&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;100000&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; randint(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 999999999&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; randint(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 999999999&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; and&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; str&lt;&#x2F;span&gt;&lt;span&gt;(a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; b)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span&gt; add(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;(a),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; str&lt;&#x2F;span&gt;&lt;span&gt;(b))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; result&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;print&lt;&#x2F;span&gt;&lt;span&gt;(test())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For grins I sent that to the gentleman who had proposed the problem. In my head I was lightly yanking his chain by sending him short clear (imo) python code rather than long obscure (imo) C. To my surprise he replied. He was vaguely complimentary, and mentioned that he had not known about the divmod function. He went on to say that while my approach did indeed implement long addition, I was creating lists willy-nilly, and so burning through memory.&lt;&#x2F;p&gt;
&lt;p&gt;Space efficiency had not explicitly been part of the problem, but post hoc spec changes are par for the course.  I was in geek mode and consequenty took the bait. I modified the code to use generators instead of lists. I sent the revised version on over, feeling pretty pleased with myself.  I was enjoying the game.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; right_pad&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;numeric_string&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;Pad digits on the right with 0, forever!&amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; digit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; numeric_string:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        yield&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt;(digit)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        yield&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; columns&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; b&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    Set up numeric strings a and b for addition by padding the&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    shorter with zeros to match length of longer. Return generator&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    of columns (corresponding digit pairs) in reverse order.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits_a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; right_pad(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;reversed&lt;&#x2F;span&gt;&lt;span&gt;(a))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits_b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; right_pad(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;reversed&lt;&#x2F;span&gt;&lt;span&gt;(b))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    while&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; True&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        yield&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; next&lt;&#x2F;span&gt;&lt;span&gt;(digits_a),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; next&lt;&#x2F;span&gt;&lt;span&gt;(digits_b)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; add&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; b&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    Add two numeric strings via standard base 10 long addition,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    return the sum as a string.&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    carry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    digits&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    cols&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; columns(a, b)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; _&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;max&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;len&lt;&#x2F;span&gt;&lt;span&gt;(a),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(b))):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        x, y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; next&lt;&#x2F;span&gt;&lt;span&gt;(cols)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        carry, digit&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; divmod&lt;&#x2F;span&gt;&lt;span&gt;(x&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; y&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; carry,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 10&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        digits.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;(digit))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span&gt; carry&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        digits.append(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;str&lt;&#x2F;span&gt;&lt;span&gt;(carry))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;.join(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;reversed&lt;&#x2F;span&gt;&lt;span&gt;(digits))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Later that afternoon I got a reply asking whether I would be interested in a job. That was a surprise, I had not realized we were playing that particular game. I was flattered, but I was happy with my job and did not want to relocate.&lt;&#x2F;p&gt;
&lt;p&gt;Years later I look back and think that was the best job interview I ever took part in, on either side, for various reasons.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The problem posed was not so trivial as FizzBuzz, but neither did it require many hours of research and&#x2F;or coding.&lt;&#x2F;li&gt;
&lt;li&gt;The problem was familiar and easy to understand, and consequently well specified.&lt;&#x2F;li&gt;
&lt;li&gt;The problem had an easily testable solution.&lt;&#x2F;li&gt;
&lt;li&gt;The interviewer was flexible. He was fine with python instead of C.&lt;&#x2F;li&gt;
&lt;li&gt;The interviewer was decisive. He made up his mind within a couple of hours, and did not subject the candidate to multiple rounds of interviews.&lt;&#x2F;li&gt;
&lt;li&gt;The candidate was allowed to use his preferred tools, without limitation, and no special setup was required.&lt;&#x2F;li&gt;
&lt;li&gt;The candidate was not spied on.&lt;&#x2F;li&gt;
&lt;li&gt;The problem requirements changed after the initial solution, as happens in life. The change did not seem contrived.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;I no longer recall anything about the job in question, and I lost touch with the person who proposed the problem.  But I think might have liked working with him.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>The two envelopes paradox</title>
        <published>2022-01-26T00:00:00+00:00</published>
        <updated>2022-01-26T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/twoenvelopes/"/>
        <id>https://drcabana.org/twoenvelopes/</id>
        
        <content type="html" xml:base="https://drcabana.org/twoenvelopes/">&lt;p&gt;Here is how Wikipedia describes the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Two_envelopes_problem&quot;&gt;two envelopes paradox&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;You are given two indistinguishable envelopes, each of which contains a positive sum of money. One envelope contains twice as much as the other. You may pick one envelope and keep whatever amount it contains. You pick one envelope at random but before you open it you are given the chance to take the other envelope instead.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Should you switch?  You don&#x27;t know how much is in either envelope, so symmetry suggests there is no point to switching. But there would not be much of a paradox absent some reason to think that you should switch. The argument for switching is as follows.&lt;&#x2F;p&gt;
&lt;p&gt;Assume the envelope you are holding is the worth X &amp;gt; 0.  Then the other is worth either 2X or X&#x2F;2, with equal likelihood. So the expected value of the other envelope is (1&#x2F;2 * 2X) + (1&#x2F;2 * X&#x2F;2) = X + X&#x2F;4.  This exceeds X, so you should switch. The paradox is that if you do switch, the same expected value argument still holds. So you should switch again, ad infinitum.&lt;&#x2F;p&gt;
&lt;p&gt;A little online searching will find all manner of complicated responses to this paradox. I think the matter is easily resolved. The first step is to realize the expected value computation above is nonsense.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Expected_value&quot;&gt;Expected value&lt;&#x2F;a&gt; is defined as the sum of p * probability(p) over all points p in the sample space. In the computation above we are invited to accept 2X and X&#x2F;2 as the points in the space, each having probability 1&#x2F;2. But there is a problem with that. There are exactly two points in our sample space, the unknown values in the envelopes. We can call those values X and 2X. We can call them X and X&#x2F;2 if you prefer. Either choice means the same thing, that one value is twice the other. But the two points cannot be 2X and X&#x2F;2 because 2X and X&#x2F;2 differ by a factor of 4. The premise of the paradox is that one envelope contains twice as much as the other. The proposed expected value computation is performed over an inadmissable sample space.&lt;&#x2F;p&gt;
&lt;p&gt;There is another problem with the proposed EV calculation. Not only are we invited to consider 2X and X&#x2F;2 as points in the sample space, we are asked to do so while holding an envelope containing X. So there are three distinct points in the sample space.  2X and X&#x2F;2 occur each occur with probability 1&#x2F;2 per the proposed EV calculation. The sum of probabilities is bounded above by 1, so the X that we are assumed to be holding must have probability zero.  Even though we are holding it.&lt;&#x2F;p&gt;
&lt;p&gt;There are a couple of legitimate ways to analyze the &#x27;paradox&#x27; via expected values. One is to compare the expected value of one envelope to the expected value of the other. Let&#x27;s say the envelopes contain X and 2X. We don&#x27;t know which envelope contains which amount, nor does it matter. Both envelopes have the same expected value, (X + 2X)&#x2F;2 = 3X&#x2F;2.  Since both envelopes have the same expected value, the EV computation offers no reason to switch.&lt;&#x2F;p&gt;
&lt;p&gt;The above does not depend on the choice of notation that the envelopes contain X and 2X. We could write the unknown values as Y and Y&#x2F;2. The expected values of both envelopes are still equal, now both are (Y + Y&#x2F;2)&#x2F;2 = 3Y&#x2F;4.  The outcome looks a bit different, but the change of variables makes no difference. What matters is that both envelopes have the same EV.&lt;&#x2F;p&gt;
&lt;p&gt;Here is another way to think about it. One envelope contains X, the other contains 2X. You don&#x27;t know which you are holding, either is equally likely.
If you are holding X and then switch you gain X. If you are holding 2X and then switch you lose X. You are as likely to lose X as to gain X by switching, so the expected gain is zero. There is no reason to switch, just as there is no reason not to switch.  But there is nothing left of the alleged paradox.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Simulating the Monty Hall Problem</title>
        <published>2022-01-25T00:00:00+00:00</published>
        <updated>2022-01-25T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/montyhall2/"/>
        <id>https://drcabana.org/montyhall2/</id>
        
        <content type="html" xml:base="https://drcabana.org/montyhall2/">&lt;p&gt;The &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;montyhall&#x2F;&quot;&gt;previous post&lt;&#x2F;a&gt; considered a generalized version of the Monty Hall problem. Here I want to consider a slightly different version. It goes like this.&lt;&#x2F;p&gt;
&lt;p&gt;Monty shows you N doors; N is at least 3 or the game doesn&#x27;t work. Behind one of the doors is a prize, behind the remaining doors there is nothing. You win if you can guess which door conceals the prize.  After you announce your guess Monty opens one door, not the one you chose and not the one concealing the prize. After this reveal Monty offers you the opportunity to switch doors. Should you switch?&lt;&#x2F;p&gt;
&lt;p&gt;In the game as described in the previous post Monty opened all the doors but two, your guess and one other.  In this game Monty shows you less: he opens only one door.  But you should still switch. Fundamentally not much has changed. There are N doors, so the probability that your initial guess is correct is 1&#x2F;N. Monty&#x27;s big reveal again happens with probability 1, so the chance that your initial guess is correct given the reveal remains at 1&#x2F;N.&lt;&#x2F;p&gt;
&lt;p&gt;The previous post used a slightly abstract argument to reach its conclusion.  Here I want to go in the opposite direction.  Probabilistic arguments are easy to get wrong.  It can be worthwhile to run a simulation to see whether its results agree with the theoretical predictions.&lt;&#x2F;p&gt;
&lt;p&gt;Lets get specific about the game and then simulate it. Let N=5. There are 5 doors, you make your choice. Monty responds by opening one door and showing you that the prize was not behind it. You are allowed to switch from your initial guess to another door if you like. Should you? Yes, you should.&lt;&#x2F;p&gt;
&lt;p&gt;There are four doors still in play, your guess and three more.  I claim that the probability that your original guess is correct is 1&#x2F;5, and consequently the probability that the prize is behind one of the three other doors is 4&#x2F;5.  If you switch, your probability of winning will be 1&#x2F;3 of 4&#x2F;5, so 4&#x2F;15.  The odds ratio of switching to staying put is 4&#x2F;15 to 1&#x2F;5, which is 4&#x2F;15 to 3&#x2F;15, which is 4 to 3.  If you switch you should win about 4&#x2F;3 times more frequently than if you don&#x27;t. This claim is easily tested.&lt;&#x2F;p&gt;
&lt;p&gt;Below is a short program that simulates the game. The program is written the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.wolfram.com&#x2F;language&#x2F;&quot;&gt;Wolfram language&lt;&#x2F;a&gt; (&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.wolfram.com&#x2F;mathematica&#x2F;&quot;&gt;Mathematica&lt;&#x2F;a&gt;).  I think it should be intelligible to most programmers, even those who not familiar with Mathematica.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trial[numDoors_]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; :=&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;  Module[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;{doors, firstGuess, prize, revealed, secondGuess},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;    doors&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = Range[1, numDoors]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;    prize&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = RandomChoice[doors]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;    firstGuess&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = RandomChoice[doors]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;    revealed&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; = RandomChoice[Complement[doors, {firstGuess, prize}]]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;    secondGuess&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; =&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;      RandomChoice[Complement[doors,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; {firstGuess, revealed}]]&lt;&#x2F;span&gt;&lt;span&gt; ;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;If[firstGuess&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; == prize, 1, 0], If[secondGuess == prize, 1, 0]}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s read it.  The number of doors in our case is 5, so &lt;strong&gt;doors&lt;&#x2F;strong&gt; is the list {1,2,3,4,5}.
Monty sets up the game by randomly picking one of the doors, &lt;strong&gt;prize&lt;&#x2F;strong&gt;, and hiding the prize behind it.
Then you take your &lt;strong&gt;firstGuess&lt;&#x2F;strong&gt;.  Then Monty randomly reveals one of the doors, making sure that it is not your first guess or the prize.  Then you switch by taking a &lt;strong&gt;secondGuess&lt;&#x2F;strong&gt;, different from your first guess and the revealed door.  The trial returns a pair of numbers:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;{1,0} if the first guess was correct.&lt;&#x2F;li&gt;
&lt;li&gt;{0,1} if the second guess was correct.&lt;&#x2F;li&gt;
&lt;li&gt;{0,0} if neither was correct.
By construction the first and second guess are not equal, so both cannot be correct.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;One trial is not enough.  We need to run many trials to make decent simulation.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;simulation[numDoors_,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; numTrials_] :=&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; Module[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;fg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, sg},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;fg&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, sg} = Fold[Plus, {0,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;}, Table[trial[numDoors], numTrials]]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;   Print[&amp;quot;correct 1st guesses: &amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; fg]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;   Print[&amp;quot;correct 2nd guesses: &amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; sg]&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;   Print[&amp;quot;ratio 2ndGuess&#x2F;1stGuess: &amp;quot;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; N[sg&#x2F;fg]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The simulation runs a bunch of trials and adds up (pointwise) the pairs returned by each trial. That addition is done by Folding the Plus operator over a list of trial results and an initial value of {0,0}. Functional programming for the win.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s run the simulation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;With[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;{numTrials = 500000, numDoors =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; simulation[numDoors,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; numTrials]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 1st guesses:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 99853&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 2nd guesses:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 132958&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;ratio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 2ndGuess&#x2F;1stGuess:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1.33154&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That ratio agrees nicely with the predicted 4&#x2F;3.&lt;&#x2F;p&gt;
&lt;p&gt;The version of the game played on the original &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Let%27s_Make_a_Deal&quot;&gt;Let&#x27;s Make A Deal&lt;&#x2F;a&gt; television program used three doors. In that case the probability of the first guess winning is 1&#x2F;3.  The probability of winning by switching is 2&#x2F;3, so you should win twice as often if you switch than if you don&#x27;t.  What does the simulation show?&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;With[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;{numTrials = 500000, numDoors =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; simulation[numDoors,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; numTrials]]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 1st guesses:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 167043&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;correct&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 2nd guesses:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 332957&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;ratio&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; 2ndGuess&#x2F;1stGuess:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1.99324&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Again we have excellent agreement with the theoretical odds ratio of 2.  The moral is that sometimes it is both simple and easy to test calculations via simulation.  I am a sucker for probability puzzles, so for me simulations are gold.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Please don&#x27;t troll the Haskell beginners</title>
        <published>2022-01-25T00:00:00+00:00</published>
        <updated>2022-01-25T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/rants/trolling/"/>
        <id>https://drcabana.org/rants/trolling/</id>
        
        <content type="html" xml:base="https://drcabana.org/rants/trolling/">&lt;p&gt;More than once I have seen &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;Categories-Working-Mathematician-Graduate-Mathematics&#x2F;dp&#x2F;0387984038&quot;&gt;Categories for the Working Mathematician&lt;&#x2F;a&gt; recommended to beginners trying to learn Haskell. The rationale for this recommendation seems to be, if I may paraphrase, that&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;It is a truth universally acknowledged, a newb in possession of the Glasgow Haskell Compiler must be in want of category theory.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;And that newb may as well go straight to the source and get the good stuff, amirite?&lt;&#x2F;p&gt;
&lt;p&gt;No, no, and no. That is horrible advice, tantamount to straight-up trolling.&lt;&#x2F;p&gt;
&lt;p&gt;Even if one were to stipulate that category theory is indeed a path to Haskell enlightenment (highly questionable), for most people the CFTWM book is very much not the place to start.  The book&#x27;s title says &#x27;for the working mathematician&#x27;.  The reader is assumed to be familiar with topology, abstract algebra, logic, functional analysis, etc.  All sorts of mathematician stuff. Caveat lector.&lt;&#x2F;p&gt;
&lt;p&gt;Recommending CFTWM to the Haskell or FP beginner is like telling a kid who wants to learn to put up a web page to pick up a copy of Knuth&#x27;s &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.amazon.com&#x2F;Computer-Programming-Volumes-1-4A-Boxed&#x2F;dp&#x2F;0321751043&quot;&gt;Art of Programming&lt;&#x2F;a&gt;. Good luck with that.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Statistical independence and the Monty Hall Problem</title>
        <published>2022-01-23T00:00:00+00:00</published>
        <updated>2022-01-23T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/montyhall/"/>
        <id>https://drcabana.org/montyhall/</id>
        
        <content type="html" xml:base="https://drcabana.org/montyhall/">&lt;p&gt;I want to use the notions of &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Independence_(probability_theory)&quot;&gt;statistical independence&lt;&#x2F;a&gt; and &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Conditional_probability&quot;&gt;conditional probabilty&lt;&#x2F;a&gt; to present a straightforward solution to the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Monty_Hall_problem&quot;&gt;Monty Hall problem&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Notation: probablists often write AB or even A,B for the intersection of sets A and B. Both are shorthand for $A \cap B$. The comma version looks better when the events have names longer than single letters.&lt;&#x2F;p&gt;
&lt;p&gt;Definition: Events A and B are said to be independent if P(AB) = P(A) P(B). In words, the probability that both A and B occur is the product of their respective probabilities.&lt;&#x2F;p&gt;
&lt;p&gt;The solution to the MH problem that I will propose hinges on the fact that if an event C has probability 1 then C is independent of any other event E.&lt;&#x2F;p&gt;
&lt;p&gt;&amp;amp;&amp;amp;Claim: P(C) = 1 \Rightarrow P(EC) = P(E)P(C) = P(E)&amp;amp;&amp;amp;&lt;&#x2F;p&gt;
&lt;p&gt;This follows from facts that usually are demonstrated or assumed as &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Probability_axioms&quot;&gt;axioms&lt;&#x2F;a&gt; in an intro to probability:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;If $A \subseteq B$ then $P(A) \le P(B)$&lt;&#x2F;li&gt;
&lt;li&gt;If A and B are disjoint, then $P(A \cup B) = P(A) + P(B)$&lt;&#x2F;li&gt;
&lt;li&gt;Let $\bar A$ denote the complement of A; then $P(\bar A) + P(A) = 1$&lt;&#x2F;li&gt;
&lt;li&gt;$A = A \cap (B \cup \bar B) = AB \cup A\bar B$&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Let&#x27;s establish the claim. Let $P(C)=1$ and hence $P(\bar C)=0$. For any event E,
&amp;amp;&amp;amp;E = E \cap (C \cup \bar C) = EC \cup E\bar C&amp;amp;&amp;amp;&lt;&#x2F;p&gt;
&lt;p&gt;The rightmost union is a disjoint union, so
&amp;amp;&amp;amp;P(E) = P(EC) + P(E\bar C) &amp;amp;&amp;amp;&lt;&#x2F;p&gt;
&lt;p&gt;But $P(E\bar C) = 0$ because $E\bar C \subseteq \bar C$ so $P(E\bar C) \le P(\bar C) = 0$.
It follows that $P(EC) = P(E),$ as claimed. If an event C is certain, i.e. P(C) = 1 then C is independent of any other event E.&lt;&#x2F;p&gt;
&lt;p&gt;Now let&#x27;s talk about the Monty Hall problem.&lt;&#x2F;p&gt;
&lt;p&gt;Monty shows you N &amp;gt; 2 doors. Behind one of the doors is a prize, behind the rest there is nothing. You win if you guess which door conceals the prize.  The probability that your initial guess is correct is 1&#x2F;N.&lt;&#x2F;p&gt;
&lt;p&gt;But there is a twist to the game. After you make your guess Monty opens all the doors but two, the one you chose and another of his choice. After this big reveal Monty offers you the opportunity to switch doors. This is the problem, should you switch?&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s think about the game. From the outset Monty knows where the prize is. He can always choose doors so that the prize is not behind any of the N-2 doors opened during the reveal.  In fact, he always does this. That is how the game is played.&lt;&#x2F;p&gt;
&lt;p&gt;One of two things happens during the reveal. If you picked the door concealing the prize then Monty opens all but one of the remaining doors, it does not matter which. If you did not guess correctly then Monty&#x27;s hand is forced. He cannot open either your door or the prize door. In that (more likely) case the unopened door other than yours hides the prize.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s do the numbers. Before the reveal we had P(Win)=1&#x2F;N, where Win is the event that your initial guess was correct. Does the reveal change that? We need to compute the winning probability conditional on the reveal, P(Win|Reveal).&lt;&#x2F;p&gt;
&lt;p&gt;The general formula for conditional probabilities is P(A|B) = P(A,B)&#x2F;P(B). So P(Win|Reveal) = P(Win,Reveal)&#x2F;P(Reveal). Recall that Monty always does the reveal, that is how the game is played. So P(Reveal)=1.  Consequently P(Win,Reveal) = P(Win) P(Reveal)&#x2F;P(Reveal) = P(Win). This means that P(Win|Reveal) = P(Win) = 1&#x2F;N.  The probability that the original guess was correct is still 1&#x2F;N.&lt;&#x2F;p&gt;
&lt;p&gt;Some see two doors after the reveal, and reason that the odds must be 50-50. They believe (at least implicitly) that the reveal changed the win probability of the original guess from 1&#x2F;N to 1&#x2F;2. Not so; that probability is not changed by the reveal. But the reveal does change the number of doors remaining in the game, from N to 2. The original choice of door continues to win with probability 1&#x2F;N, and the set of doors other than the original continues to win with probability 1-1&#x2F;N. But now there is only one other door in that set. That remaining door wins with probability 1-1&#x2F;N.  It is better to switch.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Counting uniques</title>
        <published>2022-01-21T00:00:00+00:00</published>
        <updated>2022-01-21T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/rants/distinct/"/>
        <id>https://drcabana.org/rants/distinct/</id>
        
        <content type="html" xml:base="https://drcabana.org/rants/distinct/">&lt;p&gt;Much of my disreputable youth was spent in company of mathematicians. Not surprisingly, I acquired some of their habits of speech. Later I worked adjacent to the web publishing industry and there had to endure abominable abuses of language. People would speak of &#x27;counting unique visitors&#x27;, or worse still, &#x27;counting uniques&#x27;.&lt;&#x2F;p&gt;
&lt;p&gt;Such talk arose when discussing the measurement of website traffic. During a given time interval a site might serve many visitors, with the same person sometimes visiting the site more than once. Those charged with measuring site traffic did not want to count the same visitor more than once. They wanted to know how many different visitors the site had during the interval in question.  This was the problem of &#x27;counting uniques&#x27;.  Hold that thought.&lt;&#x2F;p&gt;
&lt;p&gt;The equation x+1=3 has exactly one solution: x=2. When an equation has one and only one solution, that solution is said to be &lt;strong&gt;unique&lt;&#x2F;strong&gt;. By way of contrast, consider the equation x*x=1.  It has two solutions: x=1 is one, x=-1 is another. The equation is said to have two &lt;strong&gt;distinct&lt;&#x2F;strong&gt; solutions. The second equation does not have a &lt;strong&gt;unique&lt;&#x2F;strong&gt; solution precisely because it has two &lt;strong&gt;distinct&lt;&#x2F;strong&gt; solutions. The terms &lt;strong&gt;unique&lt;&#x2F;strong&gt; and &lt;strong&gt;distinct&lt;&#x2F;strong&gt; stand in contrast to one another. One does not ask about the number of unique solutions, because there can be only one. But one might well inquire about the number of distinct solutions to an equation.&lt;&#x2F;p&gt;
&lt;p&gt;My associates in the web publishing industry wanted to know the number of &lt;del&gt;unique&lt;&#x2F;del&gt; distinct visitors to a site. Counting the number of unique anything is pointless. If something is unique, then there is only one such thing. That is what unique means.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Pure functions and three sided triangles</title>
        <published>2022-01-21T00:00:00+00:00</published>
        <updated>2022-01-21T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/rants/purefunctions/"/>
        <id>https://drcabana.org/rants/purefunctions/</id>
        
        <content type="html" xml:base="https://drcabana.org/rants/purefunctions/">&lt;p&gt;In recent years functional programming has become if not trendy then at least less niche. Well-meaning introductory articles often bring up the idea of &#x27;pure functions&#x27;. The qualifier &#x27;pure&#x27; suggests that pure functions are to be singled out in contrast to some other sort of function. What is it that sets pure functions apart?  The answer varies across authors, but it tends to be something along these lines:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Pure functions are deterministic in the sense that f(x)=y and f(x)=z implies that y=z.&lt;&#x2F;li&gt;
&lt;li&gt;Pure function do not mutate their arguments.&lt;&#x2F;li&gt;
&lt;li&gt;Pure functions have no side effects, say incrementing a global variable, writing to a log, or launching nuclear missiles.&lt;&#x2F;li&gt;
&lt;li&gt;Pure functions are referentially transparent in the sense that if f(x)=y then we can substitute y for any occurrence of f(x) without change of meaning.&lt;&#x2F;li&gt;
&lt;li&gt;Pure functions depend only on their arguments and immutable constants such as numbers.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;These are all very nice, but there is no need for the &#x27;pure&#x27; qualifier. Anything purporting to be a function but lacking these properties is just not a function. One could call such a thing a subroutine, a procedure, a method, a code blob, whatever. The word &lt;strong&gt;function&lt;&#x2F;strong&gt; already has a well established mathematical meaning that covers these purity concerns. It has been in use since &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;History_of_the_function_concept&quot;&gt;Liebniz introduced it in 1673&lt;&#x2F;a&gt;. The idea of a function has been around even longer.&lt;&#x2F;p&gt;
&lt;p&gt;To speak of &#x27;pure&#x27; functions makes as much sense as speaking of &#x27;three-sided&#x27; triangles or &#x27;aqueous&#x27; water.  There is no other kind.  The fact that various programming languages misappropriate the word is unfortunate. I prefer the established mathematical usage.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Quines and the halting problem</title>
        <published>2022-01-20T00:00:00+00:00</published>
        <updated>2022-01-20T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/quine5/"/>
        <id>https://drcabana.org/quine5/</id>
        
        <content type="html" xml:base="https://drcabana.org/quine5/">&lt;p&gt;Quines are generally portrayed as curiosities, often with the focus on writing the shortest possible quine. This leads to pretty little things like this &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;scm.iis.sinica.edu.tw&#x2F;home&#x2F;2007&#x2F;a-haskell-quine&#x2F;&quot;&gt;Haskell one-liner&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;main&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt;putStr&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;.&lt;&#x2F;span&gt;&lt;span&gt;ap(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)show&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;main=putStr.ap(++)show$&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That is really slick. By comparison, the quine I demonstrated &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine&#x2F;&quot;&gt;earlier&lt;&#x2F;a&gt; has the elegant lines of a UPS van. But cargo vans do have their charms, not the least of which is the ability to haul cargo. With some refactoring we can make a quine haul computational cargo. Here&#x27;s how.&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;ll start with the by now familiar quine below, and do a bit of refactoring. The attentive reader will notice that relative to the earlier version, I have dropped the PEP 8 four space indentation of data. It is annoying and I am over it.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;for d in data[:boundary]:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;for d in data:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    print(q + d + q + &amp;#39;,&amp;#39;)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;for d in data[boundary:]:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data[:boundary]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data[boundary:]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The first step is to repackage the print loops as a function.  Instead of printing, the function &lt;strong&gt;quine&lt;&#x2F;strong&gt; returns a string. We leave the printing to the top level of the program. Here&#x27;s the idea:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;def quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    return data[:boundary] + [q + d + q + &amp;#39;,&amp;#39; for d in data] + data[boundary:]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;for line in quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    print(line)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quine&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; data[:boundary]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; [q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data[boundary:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; quine():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(line)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Notice that we can pack in arbitrary code and still preserve the quine property, so long as we add the new code as both data and code.  For example, let&#x27;s insert a &lt;strong&gt;hello&lt;&#x2F;strong&gt; function.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;def hello():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    return &amp;#39;Hello&amp;#39;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;def quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    return data[:boundary] + [q + d + q + &amp;#39;,&amp;#39; for d in data] + data[boundary:]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;for line in quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    print(line)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; hello&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;Hello&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quine&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; data[:boundary]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; [q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data[boundary:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; quine():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(line)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now lets modify the top level so the program can express its dual nature. The new version will behave differently depending on whether it is invoked with a command line argument. Notice that because we stuck an import statement before declaring &lt;strong&gt;data&lt;&#x2F;strong&gt; we had to increment &lt;strong&gt;boundary&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;import&lt;&#x2F;span&gt;&lt;span&gt; sys&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;import sys&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;def hello():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    return &amp;#39;Hello&amp;#39;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;def quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    boundary = 2&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    return data[:boundary] + [q + d + q + &amp;#39;,&amp;#39; for d in data] + data[boundary:]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;if __name__ == &amp;#39;__main__&amp;#39; :&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    if len(sys.argv) &amp;gt; 1:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;        for line in quine():&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;            print(line)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;    else:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;        print(hello())&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; hello&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;Hello&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quine&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 2&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; data[:boundary]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; [q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data[boundary:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; __name__&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;__main__&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt; :&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    if&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(sys.argv)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; quine():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;            print&lt;&#x2F;span&gt;&lt;span&gt;(line)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;        print&lt;&#x2F;span&gt;&lt;span&gt;(hello())&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The new program is a chameleon.  It is a hello world program that can act as a quine on demand, as seen below.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;❯&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; python chameleon.py&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Hello&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;❯&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; diff&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; chameleon.py =&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;python&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; chameleon.py&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -q&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; chameleon.py and &#x2F;tmp&#x2F;zshd1nU9h are identical&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;With a bit of work, arbitrary programs can be given the ability to act as quines when desired. So it turns out quines are not particularly rare. But are programs with quine powers even useful?   Two possibilities jump to mind.&lt;&#x2F;p&gt;
&lt;p&gt;An obvious idea is to write &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Computer_worm&quot;&gt;worms&lt;&#x2F;a&gt;.  That strikes me as a knucklehead thing to do, but there it is. Writing worms is pretty well understood by now, so it&#x27;s not like I&#x27;m letting the cat out of the bag.&lt;&#x2F;p&gt;
&lt;p&gt;The other idea (my motive for writing this post) is to give a simple explanation of why the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Halting_problem&quot;&gt;halting problem&lt;&#x2F;a&gt; is insoluble. An explanation that makes intuitive sense.  Turing&#x27;s original explanation was basically a &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cantor%27s_diagonal_argument&quot;&gt;diagonalization argument&lt;&#x2F;a&gt;.  That type of argument can be challenging for people who are not comfortable with mathematics.  I think quines can shed light here.&lt;&#x2F;p&gt;
&lt;p&gt;Suppose for the sake of argument that there were a program capable of solving the halting problem.  I&#x27;m going to call such a program a &#x27;halting oracle&#x27;.
What exactly does a halting oracle claim to be able to do?&lt;&#x2F;p&gt;
&lt;p&gt;Basically, it is a program that accepts other programs as input.  It returns True if the input program eventually halts, and it returns False if it does not.  The oracle must decide correctly, every time. Unlike many programs, the oracle never fails to halt. It always returns an answer.  Given any program, it correctly decides whether that program eventually halts.&lt;&#x2F;p&gt;
&lt;p&gt;It turns out there are no halting oracles. They do not exist because they cannot exist. Here is why. Suppose some program &lt;strong&gt;Halts&lt;&#x2F;strong&gt; claims to be a halting oracle. We can write a program &lt;strong&gt;Q&lt;&#x2F;strong&gt; designed to stump any purported halting oracle.  We build &lt;strong&gt;Q&lt;&#x2F;strong&gt; so that it has its own source code available via a &lt;strong&gt;quine&lt;&#x2F;strong&gt; function, as seen above.  &lt;strong&gt;Q&lt;&#x2F;strong&gt; calls the oracle, and does something along these lines:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;if&lt;&#x2F;span&gt;&lt;span&gt; Halts(quine()):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  while&lt;&#x2F;span&gt;&lt;span&gt; true:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; print&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;#39;I win&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;else&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;You lose&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;Q&lt;&#x2F;strong&gt; in effect asks the oracle &#x27;Do I halt?&#x27;.  If the oracle replies True (yes), then &lt;strong&gt;Q&lt;&#x2F;strong&gt; branches to an infinite loop. If the oracle replies False (no) then &lt;strong&gt;Q&lt;&#x2F;strong&gt; immediately halts. Heads I win, tails you lose.  The point is that a halting oracle must correctly decide every time. &lt;strong&gt;Halts&lt;&#x2F;strong&gt; cannot do so for &lt;strong&gt;Q&lt;&#x2F;strong&gt;, and so fails to meet the requirements.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;concluding-remarks&quot;&gt;Concluding remarks&lt;&#x2F;h4&gt;
&lt;p&gt;It&#x27;s too bad about the non-existence of halting oracles, such a program would be very handy. So much so as to be magical.  It could make short work of tough mathematical questions. For instance, consider what was long known as the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Fermat%27s_Last_Theorem&quot;&gt;Fermat conjecture&lt;&#x2F;a&gt;. Fermat claimed that he had a proof that there are no positive integer solutions to the equation a^n + b^n = c^n where n is greater than 2. That claim was discovered after Fermat&#x27;s death. If Fermat had a proof no one ever found it. Generations of mathematicians got &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;xkcd.com&#x2F;356&#x2F;&quot;&gt;nerd sniped&lt;&#x2F;a&gt; into looking for a proof (or a refutation) of Fermat&#x27;s claim. It took over three and a half centuries of effort to find a proof.  A halting oracle would have made short work of the matter.  The conjecture is parameterized by four positive integers.  Write a program to enumerate all such 4-tuples, and sequentially test each one to see whether it satisfies a^n + b^n = c^n. If the program finds one that does, halt. Otherwise just keep looking. Here&#x27;s the good part: don&#x27;t try run the program, it might never stop. Instead give it to the halting oracle, which presumably would say the program does not halt, hence Fermat&#x27;s claim is correct.&lt;&#x2F;p&gt;
&lt;p&gt;Too ivory tower for you? How about using a halting oracle to snag some of that sweet bitcoin that you missed out on when it sold for pennies?  Breaking encryption is easy if you have a really really fast way to exhaustively search huge keyspaces, say at least 2^2048 distinct keys. It is not even remotely feasible to exhaustively search spaces that size with current tech. But a halting oracle is magic.  Write a program that can enumerate the entire keyspace, but have it walk just the first half, testing each potential key to see whether it is the one sought. If the key is found, return it.  If the key is not found in that first half of the keyspace, then loop forever. The cool part is you don&#x27;t run the program, instead you ask the oracle whether it halts.  If it does, the key is in the first half of the keyspace. If not, it is in the second half.  Rinse, lather, repeat. You now have binary search on a vast scale, without needing the order properties that conventional binary search requires, or even actually running any search at all. Magic!&lt;&#x2F;p&gt;
&lt;p&gt;It turns out that halting oracles are just too good to be true.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to build a quine relay generator</title>
        <published>2022-01-15T00:00:00+00:00</published>
        <updated>2022-01-15T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/quine4/"/>
        <id>https://drcabana.org/quine4/</id>
        
        <content type="html" xml:base="https://drcabana.org/quine4/">&lt;p&gt;This is the fourth post in a series. The goal here is to extend the quine generator built in the &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine3&#x2F;&quot;&gt;previous post&lt;&#x2F;a&gt; so that it can generate quine relays. Let&#x27;s get started.&lt;&#x2F;p&gt;
&lt;p&gt;The quine relay generator is a python program called &lt;strong&gt;polyquine&lt;&#x2F;strong&gt;.  It expects one or more string arguments, selected from &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.oracle.com&#x2F;java&#x2F;&quot;&gt;java&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.python.org&#x2F;&quot;&gt;python&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.ruby-lang.org&#x2F;en&#x2F;&quot;&gt;ruby&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.lua.org&#x2F;about.html&quot;&gt;lua&lt;&#x2F;a&gt;, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;fsharp.org&#x2F;&quot;&gt;fsharp&lt;&#x2F;a&gt;, or &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;babashka.org&#x2F;&quot;&gt;babashka&lt;&#x2F;a&gt;. A single argument results in a standard quine.  It is OK to repeat arguments.&lt;&#x2F;p&gt;
&lt;p&gt;Below is terminal output from a sample run. We ask for a quine relay using java, babaskha, and F#. The output is a java program, call it &lt;strong&gt;J&lt;&#x2F;strong&gt;. Running &lt;strong&gt;J&lt;&#x2F;strong&gt; would result in a babashka program, &lt;strong&gt;B&lt;&#x2F;strong&gt;. Running &lt;strong&gt;B&lt;&#x2F;strong&gt; would result in an F# program, &lt;strong&gt;F&lt;&#x2F;strong&gt;.  Running &lt;strong&gt;F&lt;&#x2F;strong&gt; would result in the original program, &lt;strong&gt;J&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;❯ .&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&#x2F;&lt;&#x2F;span&gt;&lt;span&gt;polyquine.py java babashka fsharp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;public class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;quine&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; public static&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; main&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span&gt;[]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; args&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;  String&lt;&#x2F;span&gt;&lt;span&gt;[] data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;public class quine {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; public static void main(String[] args) {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  String[] data = {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  };&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  int a=14; int b=15; int c=21; int sep=32;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  char q = (char) 34; char space = (char) 32; char separator = (char) sep;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  for (int i = a; i &amp;lt; b; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;    System.out.println(data[i]);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  for (int i = 0; i &amp;lt; data.length; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;    System.out.println(String.valueOf(space) + q + data[i] + q + separator);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  for (int i = b; i &amp;lt; c; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;    System.out.println(data[i]);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; }&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;(let [data [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; ]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; [a b c sep] [21 22 31 59]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; q (char 34), space (char 32), separator (char sep)]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; (doseq [k (range a b)]           (println (nth data k)))&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; (doseq [k (range (count data))] (println (str space q (nth data k) q separator)))&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; (doseq [k (range b c)]           (println (nth data k))))&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let a, b, c, sep = 0, 3, 14, 44&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let q, space, separator = string(char 34), string(char 32), string(char sep)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for i in a..b-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(data.[i])&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for i in 0..data.Length-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(space + q + data.[i] + q + separator)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for i in b..c-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(data.[i])&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  };&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;  int&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;14&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;15&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;21&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span&gt; sep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;  char&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 34&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; char&lt;&#x2F;span&gt;&lt;span&gt; space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 32&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; char&lt;&#x2F;span&gt;&lt;span&gt; separator&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;char&lt;&#x2F;span&gt;&lt;span&gt;) sep;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a; i &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; b; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    System.out.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(data[i]);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; i &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; data.length; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    System.out.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(String.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;valueOf&lt;&#x2F;span&gt;&lt;span&gt;(space)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; data[i]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; separator);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  for&lt;&#x2F;span&gt;&lt;span&gt; (&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;int&lt;&#x2F;span&gt;&lt;span&gt; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; b; i &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span&gt; c; i&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    System.out.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;println&lt;&#x2F;span&gt;&lt;span&gt;(data[i]);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The output should seem familiar if you read the preceding posts.  We see a list of strings followed by three print loops. The print loops are controlled by the indices &lt;strong&gt;a&lt;&#x2F;strong&gt;,&lt;strong&gt;b&lt;&#x2F;strong&gt;, and &lt;strong&gt;c&lt;&#x2F;strong&gt;.  The trick is to compute appropriate values for those indices.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s look at some of the data used to generate quine relays. It is almost the same as the data used by the quine generator from the previous post. Here is the template used to generate java code:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;java&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;   &amp;quot;public class quine {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot; public static void main(String[] args) {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;  String[] data = {&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;  };&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, ],&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;   &amp;quot;  char q = (char) 34; char space = (char) 32; char separator = (char) sep;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;  for (int i = a; i &amp;lt; b; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    System.out.println(data[i]);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;  for (int i = 0; i &amp;lt; data.length; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    System.out.println(String.valueOf(space) + q + data[i] + q + separator);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;  for (int i = b; i &amp;lt; c; i++)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    System.out.println(data[i]);&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot; }&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;}&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The analogous data in the quine generator was a list of strings. This is a list containing two lists of strings. What is the reason for the change? Compare the template to the java strings in the output from the polyquine run. There is a line in the output unaccounted for in the template. The template contains no string declaring the variables &lt;strong&gt;a,b,c&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;That line will be constructed at runtime, and inserted into the template. Where? Exactly between the two lists that initially make up the template. The syntax for the line to be constructed comes from the &lt;strong&gt;parms&lt;&#x2F;strong&gt;  found in data representing facts about the various languages:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;facts&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;babashka&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:babashka ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                       &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(babashka[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(babashka[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                       &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; [a b c sep] [&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{} {} {} {}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;         &amp;quot;fsharp&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;  :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:fsharp ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;  &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;59&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(fsharp[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(fsharp[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let a, b, c, sep = &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;         &amp;quot;java&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;3&lt;&#x2F;span&gt;&lt;span&gt;  ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:java ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;  &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;44&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(java[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(java[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;  int a=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;; int b=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;; int c=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;; int sep=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;         &amp;quot;lua&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;     :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:lua ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;  &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;44&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(lua[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(lua[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;a, b, c, sep= &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;         &amp;quot;python&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;  :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:python,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;  &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;44&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(python[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(python[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;a, b, c, sep = &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;},&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;         &amp;quot;ruby&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;    :{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;boundary&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;template&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:ruby,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;  &amp;quot;separator&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;44&lt;&#x2F;span&gt;&lt;span&gt; ,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;size&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(ruby[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(ruby[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;]),&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;                     &amp;quot;parms&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;a, b, c, sep = &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;{}&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Let&#x27;s take a look at the mechanics of computing &lt;strong&gt;a,b,c&lt;&#x2F;strong&gt; for langs = [&#x27;java&#x27;, &#x27;babashka&#x27;, &#x27;fsharp&#x27;], as in the sample run. Here is the code.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; populate_templates&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;langs&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;#39;&amp;#39;&amp;#39; Compute required offsets per language choices, inject them into raw templates. &amp;#39;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    offsets&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; partial_sums([ size(l)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; l&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; langs[:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;] ])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    templates&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; []&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    num_langs&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; len&lt;&#x2F;span&gt;&lt;span&gt;(langs)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    for&lt;&#x2F;span&gt;&lt;span&gt; k&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; range&lt;&#x2F;span&gt;&lt;span&gt;(num_langs):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        langX&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; langs[k]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        langY&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; langs[(k&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; %&lt;&#x2F;span&gt;&lt;span&gt; num_langs]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; offsets[(k&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; %&lt;&#x2F;span&gt;&lt;span&gt; num_langs]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        b&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; boundary(langY)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        c&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; a&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; size(langY)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        parms&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; parameters(langX).format(a, b, c, separator(langY))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        top,bottom&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; template(langX)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        templates.append(top&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; [parms]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; bottom)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; templates[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;],concat(templates)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;strong&gt;for&lt;&#x2F;strong&gt; loop will run three times, because we use three  languages. Each pass handles two of the languages, langX and langY.  In the first pass these are java and babashaka. In the second pass they are babashka and F#, and in the final pass F# and java. This reflects the goal of building a java program that emits a babashka program that emits an F# program that emits the original java program.&lt;&#x2F;p&gt;
&lt;p&gt;Consider the first pass. There langX is java, langY is bashska. Imagine that we have concatenated the templates for our three languages into a single list. The variable &lt;strong&gt;a&lt;&#x2F;strong&gt; is the offset of langY in that list. By construction, all three indices &lt;strong&gt;a,b,c&lt;&#x2F;strong&gt; will point into the langY strings. Those indices will be used as values in the langX template. Why? Because we are generating a langX program that emits a langY program.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;strong&gt;populate_templates&lt;&#x2F;strong&gt; function returns a pair of values.  The first value is the completed langX template. The &lt;strong&gt;polyquine&lt;&#x2F;strong&gt; function will need that because it will construct a program in langX.  The second value is the concatenation of all the completed language templates. That list is exactly the &lt;strong&gt;data&lt;&#x2F;strong&gt; seen in the sample quine relay.&lt;&#x2F;p&gt;
&lt;p&gt;With those two values in hand, constructing the quine relay is almost identical to the way the earlier quine generator constructed quines. Here it is:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; polyquine&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;langs&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;#39;&amp;#39;&amp;#39; Generate a polyquine in the specified languages. &amp;#39;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    code,payload&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; populate_templates(langs)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bnd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; boundary(langs[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(separator(langs[&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;0&lt;&#x2F;span&gt;&lt;span&gt;]))&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [quote(line, sep)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; payload]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; code[:bnd]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; code[bnd:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;testing&quot;&gt;Testing&lt;&#x2F;h4&gt;
&lt;p&gt;The repo for the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&#x2F;polyquine.git&quot;&gt;polyquine project&lt;&#x2F;a&gt; includes a test harness.  It uses python to generate bash scripts that invoke the various language runtimes and the diff utility. I was on a code generation roll, and decided to run with it.&lt;&#x2F;p&gt;
&lt;p&gt;Running the tests will likely require customization of the both the host system and the test script generator. The host needs to have the various languages installed.  The test script generator needs to know the paths on the host to the language runtime executables. I decided it was out of scope to explain how to install the various languages, instead leaving it as an exercise for the motivated reader.&lt;&#x2F;p&gt;
&lt;p&gt;I built and tested this code on macOS Catalina. I suspect it could easily be made to run on linux, but have not attempted it. On Windows, who knows? There I&#x27;d try to use the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;wsl&#x2F;&quot;&gt;WSL&lt;&#x2F;a&gt;. I toyed with the idea of setting up a container or a VM with the various language runtimes installed, but decided that was one yak too many to shave.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;concluding-remarks&quot;&gt;Concluding remarks&lt;&#x2F;h4&gt;
&lt;p&gt;If you read all four posts in this series, thank you. I applaud your patience and hope you enjoyed them. I tried to make a tricky bit of programming as clear and intelligible as I could. I wanted to explain how the quine relay trick is done, and so demonstrate that it is simpler than would first appear. Whether I succeeded is for &lt;a href=&quot;&#x2F;images&#x2F;absgoose432.png&quot;&gt;others to decide&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to build a quine generator</title>
        <published>2021-12-30T00:00:00+00:00</published>
        <updated>2021-12-30T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/quine3/"/>
        <id>https://drcabana.org/quine3/</id>
        
        <content type="html" xml:base="https://drcabana.org/quine3/">&lt;p&gt;The plan per the previous posts has been to:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Develop a way to write quines by hand, described in the &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine&#x2F;&quot;&gt;first post&lt;&#x2F;a&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Use the lessons learned to write a quine generator.&lt;&#x2F;li&gt;
&lt;li&gt;Use the further lessons learned to write a quine relay generator.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Step 2 is the subject of this post. So far we have seen a pair of quines, one in python and one in F#. Each consists of data and logic used to control the printing of said data. The plan here is to repackage the data and the logic. A single python program will handle the printing logic across all languages. The data representing the various quines will live in in python lists, one per language.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s start by looking at (part of) the data for one language:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fsharp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;let data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;let boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;let a, b, c = 0, boundary, data.Length&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;let quote, space, separator = string(char 34), string(char 32), string(char 59)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for k in a..b-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(data.[k])&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(space + quote + d + quote + separator)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for k in b..c-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(data.[k])&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Starting with that data, here is the basic idea for the printing logic.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quote&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;line&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; separator&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;&amp;quot;&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39; &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; separator&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quine&lt;&#x2F;span&gt;&lt;span&gt;():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    code&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; fsharp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [quote(line,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; code]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt;  code[:boundary]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; code[boundary:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; quine():&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(line)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;strong&gt;quine()&lt;&#x2F;strong&gt; function returns a string representing a quine. As seen in the return statement, that string is built by concatenating three pieces. Those three pieces correspond exactly to the three print loops in our earlier hand-written quines.&lt;&#x2F;p&gt;
&lt;p&gt;The sketch above needs to be generalized so that it can generate quines in multiple languages.  We&#x27;ll modify &lt;strong&gt;quine()&lt;&#x2F;strong&gt; to take an argument specifying which language to use. We&#x27;ll have to look up language specific details, such as the character used to separate elements of a list.  Here&#x27;s the revised idea:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;def&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; quine&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt;lang&lt;&#x2F;span&gt;&lt;span&gt;):&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    code&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; template(lang)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    bnd&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; boundary(lang)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    sep&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; separator(lang)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [quote(line, sep)&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; for&lt;&#x2F;span&gt;&lt;span&gt; line&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; code]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    return&lt;&#x2F;span&gt;&lt;span&gt; code[:bnd]&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; code[bnd:]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;That&#x27;s pretty much the final version, except for the glue code used to implement the various lookups.  The complete code is available &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&#x2F;quines.git&quot;&gt;here&lt;&#x2F;a&gt;.  It includes language templates for python, F#, lua, ruby, java, and babashka.  Also included is a slightly whimsical test harness that uses python to generate bash scripts that test whether a purported quine is actually a quine. It just felt right to use generated test code to test generated code.&lt;&#x2F;p&gt;
&lt;p&gt;One last thing. Consider these lines from the F# template above:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;let a, b, c = 0, boundary, data.Length&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for k in a..b-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(data.[k])&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(space + quote + d + quote + separator)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for k in b..c-1 do&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;   System.Console.WriteLine(data.[k])&amp;quot;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Why take the trouble to declare variables a,b,c and then write the print loops in terms of those variables? Why not instead use the known values of the variables in the loop indices?  Those values are known at design time when generating quines, but they will have to be computed at runtime when generating quine relays. In that scenario it will be convenient to have parameterized loop indices. More on that in the &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine4&#x2F;&quot;&gt;next post&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;The supporting code repo is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&quot;&gt;drcabana&#x2F;quines&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to build a quine, reprise</title>
        <published>2021-12-29T00:00:00+00:00</published>
        <updated>2021-12-29T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/quine2/"/>
        <id>https://drcabana.org/quine2/</id>
        
        <content type="html" xml:base="https://drcabana.org/quine2/">&lt;p&gt;Let&#x27;s revisit the quine building exercise described in the &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine&#x2F;&quot;&gt;first post&lt;&#x2F;a&gt; in this series, this time in F#. Small issues will arise, and we&#x27;ll see how to handle them.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;step-one&quot;&gt;Step One&lt;&#x2F;h4&gt;
&lt;p&gt;As before, we start with an empty list, and three print loops.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;fsharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Notice that the closing bracket is indented one space.  The indentation is required in F#.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;step-two&quot;&gt;Step Two&lt;&#x2F;h4&gt;
&lt;p&gt;As before, the middle print loop is special. Let&#x27;s set it up. The variable &lt;strong&gt;space&lt;&#x2F;strong&gt; is used for indentation, and &lt;strong&gt;semicolon&lt;&#x2F;strong&gt; is the element separator. Recall that python used a comma for that.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;fsharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;])&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;space &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;step-three&quot;&gt;Step Three&lt;&#x2F;h4&gt;
&lt;p&gt;We need to put some content into &lt;strong&gt;data&lt;&#x2F;strong&gt;, via copy-paste:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Copy the program so far.&lt;&#x2F;li&gt;
&lt;li&gt;Paste it on a new line following the first bracket delimiting &lt;strong&gt;data&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Wrap each line in quotes, and append a semicolon to each pasted line. A semicolon, not a comma.&lt;&#x2F;li&gt;
&lt;li&gt;Indent each line by one space.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Here&#x27;s the result&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;fsharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; ]&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let q = string(char 34)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let semicolon = string(char 59)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let space = string(char 32)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(space + q + d + q + semicolon)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;space &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;step-four&quot;&gt;Step Four&lt;&#x2F;h4&gt;
&lt;p&gt;Next we adjust the print loops and their string representations inside &lt;strong&gt;data&lt;&#x2F;strong&gt;. We have to be careful. Blindly copying the approach used in the earlier post will not suffice. Different programming languages use different conventions that may become relevant. For instance:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;What is the element separator character in a list&#x2F;array&#x2F;vector?&lt;&#x2F;li&gt;
&lt;li&gt;Do lists&#x2F;arrays&#x2F;vectors allow the use of trailing separators?&lt;&#x2F;li&gt;
&lt;li&gt;Does the language count from 0 (e.g. python) or from 1 (e.g. lua)?&lt;&#x2F;li&gt;
&lt;li&gt;Do numerical ranges include or exclude the upper limit?&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;In python &lt;strong&gt;data[:b]&lt;&#x2F;strong&gt; does not include the bth element, but in F# &lt;strong&gt;data[..b]&lt;&#x2F;strong&gt; does include it, so we have to adjust for that. In python the 1st and 3rd print loops ranged over &lt;strong&gt;data[:boundary]&lt;&#x2F;strong&gt; and &lt;strong&gt;data[boundary:]&lt;&#x2F;strong&gt;, a pleasant symmetry. F# requires &lt;strong&gt;data[..boundary-1]&lt;&#x2F;strong&gt; and &lt;strong&gt;data[boundary..]&lt;&#x2F;strong&gt; to achieve the same outcome.  We&#x27;ll see more minor linguistic differences in the next post, when the ruby, lua, and babashka languages join the party.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s the final result.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;fsharp&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot; ]&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let q = string(char 34)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let semicolon = string(char 59)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let space = string(char 32)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;let boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data[..boundary-1] do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(space + q + d + q + semicolon)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;for d in data[boundary..] do&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;   System.Console.WriteLine(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; ]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;59&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; space&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; string&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;char &lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;32&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;let&lt;&#x2F;span&gt;&lt;span&gt; boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;[..&lt;&#x2F;span&gt;&lt;span&gt;boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;-1&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;] do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;space &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; q &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span&gt; semicolon&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;in&lt;&#x2F;span&gt;&lt;span&gt; data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;[&lt;&#x2F;span&gt;&lt;span&gt;boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;..] do&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   System.Console.WriteLine&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h4 id=&quot;testing&quot;&gt;Testing&lt;&#x2F;h4&gt;
&lt;p&gt;Save the program as quine.fsx and run a diff via zsh &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;superuser.com&#x2F;questions&#x2F;1059781&#x2F;what-exactly-is-in-bash-and-in-zsh&quot;&gt;process substitution&lt;&#x2F;a&gt;:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;❯&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; dotnet fsi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Microsoft&lt;&#x2F;span&gt;&lt;span&gt; (R) F# Interactive version 12.0.0.0 &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; F# 6.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;❯&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; diff&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -s&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.fsx =&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;dotnet&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; fsi quine.fsx&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.fsx and &#x2F;tmp&#x2F;zshsHJ5T3 are identical&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;If you want to try this at home, make sure to call your program &lt;strong&gt;quine.fsx&lt;&#x2F;strong&gt; rather than &lt;strong&gt;quine.fs&lt;&#x2F;strong&gt;. The F# compiler considers an &lt;strong&gt;fs&lt;&#x2F;strong&gt; file to be program and an &lt;strong&gt;fsx&lt;&#x2F;strong&gt; file to be a script; it treats them differently. For our purpose the script is easier to work with.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;but-wait-there-s-more&quot;&gt;But wait, there&#x27;s more.&lt;&#x2F;h4&gt;
&lt;p&gt;In the &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine3&#x2F;&quot;&gt;next post&lt;&#x2F;a&gt; we introduce more languages and automate the building of the quines. This will set the stage for building quine relays in the subsequent post.&lt;&#x2F;p&gt;
&lt;p&gt;The supporting code repo is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&quot;&gt;drcabana&#x2F;quines&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>How to build a quine</title>
        <published>2021-12-28T00:00:00+00:00</published>
        <updated>2021-12-28T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              Unknown
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://drcabana.org/quine/"/>
        <id>https://drcabana.org/quine/</id>
        
        <content type="html" xml:base="https://drcabana.org/quine/">&lt;p&gt;I want to show you how to do a magic trick. I first saw the trick on Dan Piponi&#x27;s blog, &lt;a rel=&quot;external&quot; href=&quot;http:&#x2F;&#x2F;blog.sigfpe.com&#x2F;2011&#x2F;01&#x2F;quine-central.html&quot;&gt;A Neighborhood of Infinity&lt;&#x2F;a&gt;.  Here&#x27;s how Dan described it:&lt;&#x2F;p&gt;
&lt;blockquote&gt;The code below spits out a Haskell program that prints out a Perl program that prints out a Python program that prints out a Ruby program that prints out a C program that prints out a Java program that prints out the original program.
&lt;&#x2F;blockquote&gt;
&lt;p&gt;I really wanted to understand how Dan did that, but I could not wrap my head around his &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;dpiponi&#x2F;quine-central&#x2F;blob&#x2F;master&#x2F;quineCentral.hs&quot;&gt;Haskell code&lt;&#x2F;a&gt;. I decided to to start from scratch, and eventually figured out how to do the trick.  This is the first of four posts that explain how in detail.&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;ll need some terminology.  A &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Quine_(computing)&quot;&gt;quine&lt;&#x2F;a&gt; is a program P such that Eval P = P.  That is, evaluating the program produces the original program, or at least a textual representation thereof.  A quine relay is a sequence of programs, say [P, Q, R] such that&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Eval P = Q&lt;&#x2F;li&gt;
&lt;li&gt;Eval Q = R&lt;&#x2F;li&gt;
&lt;li&gt;Eval R = P.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The exact number of programs does not matter.  What matters is that the programs cyclically produce one another. The programs are not required to be written in the same language; it is more interesting when they are not. The Eval functions are taken to be appropriate for the languages at hand.  If P, Q, and R are written in different languages, we would require distinct Eval functions, say python, ruby, and lua interpreters.&lt;&#x2F;p&gt;
&lt;p&gt;My initial goal was to figure out how generate quine relays. The trouble was that I had only a vague idea, one I could not even begin to implement. I decided that solving a simpler version of the problem might provide insight. Since I didn&#x27;t know how to generate quine relays, how about a writing a program to generate ordinary quines? It turned out I didn&#x27;t know how to do that either. OK, I had to solve an even simpler version of the problem.  How about writing a single quine by hand?  I started there.&lt;&#x2F;p&gt;
&lt;p&gt;I came up with a four step recipe, illustrated below in python. The approach is easily adapted to various languages, as will be seen in the next post in this series.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;step-one&quot;&gt;Step One&lt;&#x2F;h4&gt;
&lt;p&gt;Start with an empty list and three print loops.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The loops don&#x27;t print anything because &lt;strong&gt;data&lt;&#x2F;strong&gt; is empty.  The plan is to fill &lt;strong&gt;data&lt;&#x2F;strong&gt; with carefully chosen strings, and to adjust the print loops to print what we need.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;step-two&quot;&gt;Step Two&lt;&#x2F;h4&gt;
&lt;p&gt;The middle loop will be special, let&#x27;s set that up. We want it to wrap each line of data in double quotes, and then append a comma. The variable &lt;strong&gt;q&lt;&#x2F;strong&gt; is used to denote the double quote character. Notice that the value of &lt;strong&gt;q&lt;&#x2F;strong&gt; is given as chr(34). The reason for using the character encoding will be explained in the next step.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Now we have a slightly longer Python program that doesn&#x27;t print anything.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;step-three&quot;&gt;Step Three&lt;&#x2F;h4&gt;
&lt;p&gt;To get output we need to put some content into &lt;strong&gt;data&lt;&#x2F;strong&gt;. Let&#x27;s do so via a bit of copy-paste.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Copy the entire text of the program so far.&lt;&#x2F;li&gt;
&lt;li&gt;Paste it between the brackets that delimit &lt;strong&gt;data&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;Wrap each pasted line in double quotes, so that we have valid strings. Take care to preserve indentation.&lt;&#x2F;li&gt;
&lt;li&gt;Separate the strings by appending commas, so that &lt;strong&gt;data&lt;&#x2F;strong&gt; is a valid list of strings.&lt;&#x2F;li&gt;
&lt;li&gt;Indent each line 4 spaces, for PEP 8 compliance, and adjust the middle print loop accordingly. This step is technically optional, but this whole effort is an exercise in obsessive detail. In for a dime, in for a dollar. Notice that the adjustment to the middle print loop is made to both the code and its representation in the &lt;strong&gt;data&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The result looks like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(&amp;#39;    &amp;#39; + q + d + q + &amp;#39;,&amp;#39;)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;#39;    &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The reason for defining &lt;strong&gt;q&lt;&#x2F;strong&gt; via character encoding is that above we wrapped each line of pasted text in double quotes. Had the double quote literal been present inside the pasted text, it would have led to woe and confusion. The quotes used to delimit python strings would have collided with quotes used as characters inside the strings. Better to avoid that via the character encoding trick.&lt;&#x2F;p&gt;
&lt;p&gt;At this point the program does print something, but not what we want. Let&#x27;s fix it.&lt;&#x2F;p&gt;
&lt;h5 id=&quot;step-four&quot;&gt;Step Four&lt;&#x2F;h5&gt;
&lt;p&gt;We will adjust the print loops so that&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The first loop emits the text of the first line of the program, by printing its
representation, the first element of &lt;strong&gt;data&lt;&#x2F;strong&gt;.&lt;&#x2F;li&gt;
&lt;li&gt;The second loop emits the entire contents of &lt;strong&gt;data&lt;&#x2F;strong&gt;, including the double quotes. No change is required.&lt;&#x2F;li&gt;
&lt;li&gt;The third loop emits the text of the rest of program.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Python&#x27;s &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.python.org&#x2F;3&#x2F;library&#x2F;stdtypes.html#typesseq&quot;&gt;slice notation&lt;&#x2F;a&gt; is handy here. We need to make any adjustments twice: once in the working print loops, and again in their quoted analogs. These have to agree.&lt;&#x2F;p&gt;
&lt;p&gt;We also introduce a variable, &lt;strong&gt;boundary&lt;&#x2F;strong&gt;, used to coordinate the action of the first and third print loops.  A variable may seem like overkill, but it will be useful to have this number parameterized when we start constructing quine relays in a subsequent post.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s the final version:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;data&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; [&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;data = [&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;]&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;q = chr(34)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;boundary = 1&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data[:boundary]:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(&amp;#39;    &amp;#39; + q + d + q + &amp;#39;,&amp;#39;)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;for d in data[boundary:]:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;    &amp;quot;    print(d)&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt; chr&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;34&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;boundary&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data[:boundary]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;#39;    &amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span&gt; q&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; +&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;,&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;for&lt;&#x2F;span&gt;&lt;span&gt; d&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; in&lt;&#x2F;span&gt;&lt;span&gt; data[boundary:]:&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;&quot;&gt;    print&lt;&#x2F;span&gt;&lt;span&gt;(d)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The claim is that this version is a quine.  How does it work? Think back to the copy-paste step. We copied every line in the program, and pasted those lines into &lt;strong&gt;data&lt;&#x2F;strong&gt;.  So each line in the text of the resulting program occurs twice: once as data, once as code.&lt;&#x2F;p&gt;
&lt;p&gt;When executed, the program prints each line twice.  The middle loop prints all the the data, in quotes. The first and third loops coordinate to print each line of the surrounding code. The two loops coordinate via the value of &lt;strong&gt;boundary&lt;&#x2F;strong&gt;, which contains the number of lines before the first quoted string.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;testing&quot;&gt;Testing&lt;&#x2F;h4&gt;
&lt;p&gt;To check whether the program (saved as &lt;strong&gt;quine.py&lt;&#x2F;strong&gt;) is indeed a quine, use the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Diff&quot;&gt;diff utility&lt;&#x2F;a&gt; to compare the file &lt;strong&gt;quine.py&lt;&#x2F;strong&gt; to the output from running the file.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; python --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Python&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 2.7.16&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; python3 --version&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Python&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 3.9.5&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; diff -s quine.py =(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;python&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.py&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.py and &#x2F;dev&#x2F;fd&#x2F;63 are identical&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; diff -s quine.py =(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;python3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.py&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;Files&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; quine.py and &#x2F;dev&#x2F;fd&#x2F;63 are identical&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;diff&lt;&#x2F;strong&gt; is shown running in a zsh shell above. If you prefer bash, try using different &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;tldp.org&#x2F;LDP&#x2F;abs&#x2F;html&#x2F;process-sub.html&quot;&gt;process substitution&lt;&#x2F;a&gt; syntax: &lt;strong&gt;&amp;lt;()&lt;&#x2F;strong&gt; instead of &lt;strong&gt;=()&lt;&#x2F;strong&gt;. Or skip process substitution altogether. Simply save the output to a file and diff it against &lt;strong&gt;quine.py&lt;&#x2F;strong&gt;. The latter approach would make more sense from a pure testing point of view, because it is more likely to succeed on a wider variety of platforms. But it does not display as well in a blog post, and process substitution on the CLI  was my actual workflow.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;but-wait-there-s-more&quot;&gt;But wait, there&#x27;s more&lt;&#x2F;h4&gt;
&lt;p&gt;The &lt;a href=&quot;https:&#x2F;&#x2F;drcabana.org&#x2F;quine2&#x2F;&quot;&gt;next post&lt;&#x2F;a&gt; in this series uses the same approach to build a quine in F#. The goal will be to illustrate some issues that arise when the programming language changes, and to set the stage for automating quine generation in the subsequent post.&lt;&#x2F;p&gt;
&lt;p&gt;The supporting code repo is &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;codeberg.org&#x2F;drcabana&quot;&gt;drcabana&#x2F;quines&lt;&#x2F;a&gt;.&lt;&#x2F;p&gt;
</content>
        
    </entry>
</feed>
