<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>connorhanan</title>
<link>https://connorhanan.com/posts/</link>
<atom:link href="https://connorhanan.com/posts/index.xml" rel="self" type="application/rss+xml"/>
<description></description>
<generator>quarto-1.9.36</generator>
<lastBuildDate>Sun, 29 Mar 2026 04:00:00 GMT</lastBuildDate>
<item>
  <title>Recently Read, Automated</title>
  <link>https://connorhanan.com/posts/20260329-goodreads-plugin/</link>
  <description><![CDATA[ 




<p>In the <a href="../../posts/20260328-discogs-plugin/index.html">last post</a>, I showed off my Discogs plugin that auto-generates my <em>New Records</em> posts. The Goodreads equivalent follows the same general pattern: fetch data, diff against a local hacky NDJSON-based DB, write a Quarto post; however, the data fetching is a bit more creative, since Goodreads doesn’t have a public API (anymore!).</p>
<section id="widgets-and-scraping" class="level2">
<h2 class="anchored" data-anchor-id="widgets-and-scraping">Widgets and Scraping</h2>
<p>Goodreads does still offer embeddable shelf widgets, which are served as a JavaScript file containing an HTML string assigned to a variable.</p>
<p>It’s not the prettiest thing in the world, but it’s something to fetch and work with:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">curl</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-sS</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$GOODREADS_WIDGET</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-o</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/widget.js"</span></span></code></pre></div></div>
<p>The widget URL encodes your shelf preferences as query parameters (number of books, sort order, which fields to show, &amp;c).</p>
<p>This script uses a default URL pointed at my <code>read</code> shelf, but it can be overridden via the first argument or a <code>GOODREADS_WIDGET</code> environment variable, which means you could generate posts for other shelves like <code>to-be-read</code>, or the like.</p>
</section>
<section id="extracting-the-html" class="level2">
<h2 class="anchored" data-anchor-id="extracting-the-html">Extracting the HTML</h2>
<p>The JS file looks roughly like:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript"><span id="cb2-1"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">var</span> widget_code <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&lt;div&gt;...escaped HTML...&lt;/div&gt;'</span></span></code></pre></div></div>
<p>First, we need to strip the JS wrapper and “unescape” the four escape patterns Goodreads uses (<code>\n</code>, <code>\/</code>, <code>\"</code>, <code>\'</code>). I had never used <code>sed</code> all that much, but it’s pretty powerful with a touch of regex:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-1</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/widget.js"</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-2">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s/^[[:space:]]*var widget_code = '//; s/'[[:space:]]*$//"</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-3">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s/\\n/\n/g'</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-4">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s/</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\\\\\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\"</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/g"</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-5">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"s/</span><span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\\\\</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'/'/g"</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-6">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s|\\\/|/|g'</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">\</span></span>
<span id="cb3-7">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/widget.html"</span></span></code></pre></div></div>
<p>The whole widget is on one line, so the shorthand <code>head -1</code> pulls the entire thing. Once that line is in stdout, it’s fairly straightforward to pipe <code>sed</code> substitutions until we have readable HTML.</p>
</section>
<section id="parsing-the-books" class="level2">
<h2 class="anchored" data-anchor-id="parsing-the-books">Parsing the Books</h2>
<p>Each book in the widget HTML is wrapped in a <code>gr_custom_each_container</code> div. <code>csplit</code> splits the HTML into individual files on that pattern:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">csplit</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-sz</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-f</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/book_"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/widget.html"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'/gr_custom_each_container/'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'{*}'</span></span></code></pre></div></div>
<p>Then we loop over those files and extract the pieces we need with <code>grep</code> and fancy regex:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">full_title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-oP</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&lt;a title="\K[^"]+'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$block</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-1</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-2"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-A2</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'gr_custom_title'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$block</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-oP</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;\K[^&lt;]+(?=&lt;/a&gt;)'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-1</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-3"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">author</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-A2</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'gr_custom_author'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$block</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-oP</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'&gt;\K[^&lt;]+(?=&lt;/a&gt;)'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-1</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-4"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">img</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'gr_custom_book_container'</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-A5</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$block</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-oP</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'src="\K[^"]+'</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">head</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-1</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb5-5"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">rating</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-o</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'gr_red_star_active'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$block</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">wc</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-l</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span></code></pre></div></div>
<p>The rating is derived by counting active star images rather than reading a numeric value; granted, it’s a little roundabout and brittle, but it works.</p>
<p>Each book gets written out as a line of NDJSON with <code>jq -nc</code>.</p>
</section>
<section id="finding-whats-new" class="level2">
<h2 class="anchored" data-anchor-id="finding-whats-new">Finding What’s New</h2>
<p>The comparison logic here is slightly different from the Discogs plugin. There is no date field explicitly, but the data is returned by date descending, so we can rely on the order of the keys to determine what’s new. We first build a composite key for each book in both the fetched collection and the local DB, which is just the author and title joined with <code>||</code>.</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">in</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$l_keys</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f_keys</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">do</span></span>
<span id="cb6-2">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sed</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'s/\r$//; s/[[:space:]]\+$//'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.tmp"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mv</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">.tmp"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb6-3"><span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">done</span></span>
<span id="cb6-4"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">grep</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-Fvxf</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$l_keys</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f_keys</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/new.keys"</span></span></code></pre></div></div>
<p>Then we trim any trailing whitespace and standardize line endings to avoid false mismatches, which allows us to do a simple <code>grep</code> to find the new keys based on line mismatches:</p>
</section>
<section id="building-the-post" class="level2">
<h2 class="anchored" data-anchor-id="building-the-post">Building the Post</h2>
<p>One piece the Goodreads plugin has that Discogs doesn’t is a small helper to render a numeric rating as a Unicode star string:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb7" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb7-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stars()</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">{</span></span>
<span id="cb7-2">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">local</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$1</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span></span>
<span id="cb7-3">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">((</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">i</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">));</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">do</span></span>
<span id="cb7-4">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">[</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$i</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="ot" style="color: #003B4F;
background-color: null;
font-style: inherit;">-le</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$r</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">]</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">&amp;&amp;</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"★"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">||</span> <span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">s</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"☆"</span></span>
<span id="cb7-5">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">done</span></span>
<span id="cb7-6">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$s</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb7-7"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">}</span></span></code></pre></div></div>
<p>The rest of the post-building follows the same pattern as my Discogs plugin (frontmatter, then a block per book with cover image, title, author, and stars):</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb8" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb8-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"![](</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$img</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">){width=150px}"</span></span>
<span id="cb8-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"## </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$title</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb8-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">${author}</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">**"</span></span>
<span id="cb8-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Rating: </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$star_display</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
<p>New books get prepended to the local NDJSON database, and off we go!</p>
<hr>
<p>Scraping a widget is obviously less reliable than a real API; however, the alternative is a manual solution which isn’t nearly as fun.</p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automation</category>
  <category>Books</category>
  <guid>https://connorhanan.com/posts/20260329-goodreads-plugin/</guid>
  <pubDate>Sun, 29 Mar 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>New Records, Automated</title>
  <link>https://connorhanan.com/posts/20260328-discogs-plugin/</link>
  <description><![CDATA[ 




<p>Lately, there have been quite a few posts titled <em>Automated Updates</em>. I’ve been playing around with some bash, so those are the result of custom scripts that I am calling my blog website “plugins”.</p>
<p>They are generated, entirely automatically, as part of my publishing workflow – of course aside from updating my ever-expanding <a href="https://www.discogs.com/user/syrchanan/collection">Discogs collection</a>.</p>
<p>I thought it would be fun to walk through the process…</p>
<section id="setup" class="level2">
<h2 class="anchored" data-anchor-id="setup">Setup</h2>
<p>The whole process lives in <code>plugins/discogs.sh</code>, a Bash script invoked by my top-level (and very creatively named) plugin manager <code>publish.sh</code>, which loads environment variables and fires each plugin in sequence:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb1" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb1-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">./discogs.sh</span> syrchanan db</span></code></pre></div></div>
<p>The script accepts two positional arguments:</p>
<ol type="1">
<li>A Discogs username (in this case, <code>syrchanan</code>).</li>
<li>An output directory (in this case, <code>db</code>).</li>
</ol>
<p>It also looks for two optional environment variables:</p>
<ul>
<li><code>DISCOGS_API_TOKEN</code>: A personal API token for the Discogs API, which allows for higher rate limits than the free usage allotment.</li>
<li><code>PAGELIM</code>: A limit on how many pages of collection data to fetch (each page contains 100 records, the default of 1 should be plenty for sporadic updates).</li>
</ul>
</section>
<section id="fetching-the-collection" class="level2">
<h2 class="anchored" data-anchor-id="fetching-the-collection">Fetching the Collection</h2>
<p>The <a href="https://www.discogs.com/developers/#">Discogs API</a> exposes a user’s collection at <code>/users/{username}/collection/folders/0/releases</code>, sorted by date added descending.</p>
<p>The script iterates through the pages (up to <code>$PAGELIM</code>), writing each release as a compact JSON object to a temporary NDJSON<sup>1</sup> file:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb2" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb2-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">jq</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-c</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.releases[]? as $r | $r.basic_information as $b | {</span></span>
<span id="cb2-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  added:    $r.date_added,</span></span>
<span id="cb2-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  title:    $b.title,</span></span>
<span id="cb2-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  year:     (try ($b.year|tonumber) catch null),</span></span>
<span id="cb2-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  formats:  $b.formats[0],</span></span>
<span id="cb2-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  labels:   $b.labels[0],</span></span>
<span id="cb2-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  artists:  $b.artists[0],</span></span>
<span id="cb2-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  genres:   $b.genres,</span></span>
<span id="cb2-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  styles:   $b.styles,</span></span>
<span id="cb2-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  img:      $b.cover_image</span></span>
<span id="cb2-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">}'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$resp</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$outfile</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
<p>This results in a file with one line per release, such that each line is a cleaned up JSON object with the fields I care about. Since the API returns your collection sorted by date descending, the newest releases are at the top of the file – a feature that becomes important for the next step.</p>
</section>
<section id="looking-for-new-records" class="level2">
<h2 class="anchored" data-anchor-id="looking-for-new-records">Looking for New Records</h2>
<p>The local “database” is also just an NDJSON file on disk, which contains every release that has already been posted<sup>2</sup>. Also, rather than comparing full objects, I build a composite key for each release, comprised of the date added, artist name, and title — joined with <code>||</code>:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb3" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb3-1"><span class="ex" style="color: null;
background-color: null;
font-style: inherit;">jq</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-r</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'[(.added // ""), ((.artists.name) // ""), (.title // "")]</span></span>
<span id="cb3-2"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  | map(gsub("\\n"; " ") | gsub("\\r"; ""))</span></span>
<span id="cb3-3"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  | join("||")'</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$fetched</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">|</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-ur</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$f_keys</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
<p>Both the fetched collection and the local DB get this same format. Next, the script walks through the fetched keys from newest to oldest, writing any that don’t match the most recent local key into a <code>new.keys</code> file. It stops at the first match, which is a little fragile, but still works because everything is sorted by date descending.</p>
<p>If <code>new.keys</code> is empty, the script exits cleanly with no output.</p>
</section>
<section id="building-the-automated-post" class="level2">
<h2 class="anchored" data-anchor-id="building-the-automated-post">Building the Automated Post</h2>
<p>For each new record in our newly minted <code>new.keys</code> file, we pull the full object back out of the fetched data, extracts the fields, and append a markdown block to a new Quarto document:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb4" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb4-1"><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">filename</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"posts/auto/</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">date</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-I</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">-discogs.qmd"</span></span>
<span id="cb4-2"></span>
<span id="cb4-3"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$filename</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt; QMD_HEAD</span></span>
<span id="cb4-4"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">---</span></span>
<span id="cb4-5"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">title: "New Records"</span></span>
<span id="cb4-6"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">date: </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$(</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">date</span> <span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">-I</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">)</span></span>
<span id="cb4-7"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">categories:</span></span>
<span id="cb4-8"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  - Automated Updates</span></span>
<span id="cb4-9"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  - Music</span></span>
<span id="cb4-10"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">draft: false</span></span>
<span id="cb4-11"><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">---</span></span>
<span id="cb4-12"><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">QMD_HEAD</span></span></code></pre></div></div>
<p>Each record then gets a cover image, an H2 markdown (<code>##</code>) heading, and a markdown table with the label, year, catalog number, format, and genre:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb5" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb5-1"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"![](</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$img</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">){width=300px}"</span></span>
<span id="cb5-2"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"## </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$title</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span>
<span id="cb5-3"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"**</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$artists</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">**"</span></span>
<span id="cb5-4"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"| Label  | </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$label</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;"> |"</span></span>
<span id="cb5-5"><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">echo</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"| Year   | </span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$year</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">  |"</span></span>
<span id="cb5-6"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"># ...&amp;c &amp;c</span></span></code></pre></div></div>
</section>
<section id="updating-the-local-db" class="level2">
<h2 class="anchored" data-anchor-id="updating-the-local-db">Updating the Local DB</h2>
<p>Once the post is written, the new releases get prepended to the local NDJSON database so we don’t double count any records the next time the script runs:</p>
<div class="code-copy-outer-scaffold"><div class="sourceCode" id="cb6" style="background: #f1f3f5;"><pre class="sourceCode numberSource bash number-lines code-with-copy"><code class="sourceCode bash"><span id="cb6-1"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cat</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/updated_db.ndjson"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$local</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/combined.ndjson"</span></span>
<span id="cb6-2"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">mv</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$tmpdir</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">/combined.ndjson"</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="va" style="color: #111111;
background-color: null;
font-style: inherit;">$local</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span></span></code></pre></div></div>
<hr>
<p>The whole thing runs pretty quick, and produces a clean <code>.qmd</code> file; it requires nothing beyond <code>bash</code>, <code>curl</code>, and <code>jq</code>. From there, Quarto renders it into the site like any other post (with a special tag so you all can ignore them if you want).</p>
<p>I have a similar plugin for Goodreads that follows the same pattern — a post for another day.</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>NDJSON (Newline-Delimited JSON) - I chose this format because it makes it far easier to diff my local “database” with <code>jq</code> and <code>sort</code>.↩︎</p></li>
<li id="fn2"><p>One optimization I’ve been considering is to clean up the local DB to remove all but the latest record posted, that way I can do a simpler <code>grep</code> to find where the break point is. Or, you, know, use a real sqlite DB. But I was lazy.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Automation</category>
  <category>Music</category>
  <guid>https://connorhanan.com/posts/20260328-discogs-plugin/</guid>
  <pubDate>Sat, 28 Mar 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Recently Read</title>
  <link>https://connorhanan.com/posts/auto/2026-03-28-goodreads.html</link>
  <description><![CDATA[ 




<p><img src="https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1518344922l/38292111._SX98_.jpg" class="img-fluid" width="150"></p>
<section id="dollars-and-democracy" class="level2">
<h2 class="anchored" data-anchor-id="dollars-and-democracy">Dollars and Democracy</h2>
<p><em>Dollars and Democracy (Classic Reprint)</em></p>
<p><strong>Philip Burne-Jones</strong></p>
<p>Rating: ★★★★★</p>
<p><br></p>
<p><img src="https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1702557732l/203790675._SX98_.jpg" class="img-fluid" width="150"></p>
</section>
<section id="the-war-in-the-united-states-report-to-the-swiss-military-department-preceded-by-a-discourse-to-the-federal-military-society-assembled-at-berne-aug.-18-1862" class="level2">
<h2 class="anchored" data-anchor-id="the-war-in-the-united-states-report-to-the-swiss-military-department-preceded-by-a-discourse-to-the-federal-military-society-assembled-at-berne-aug.-18-1862">The war in the United States: Report to the Swiss Military Department : Preceded by a Discourse to the Federal Military Society Assembled at Berne, Aug.&nbsp;18, 1862</h2>
<p><strong>Ferdinand Lecomte</strong></p>
<p>Rating: ★★★★★</p>
<p><br></p>
<hr>
<p><em>This post was automatically generated from <a href="https://www.goodreads.com/review/list/98547221-connor-hanan?shelf=read">my Goodreads shelf</a>.</em></p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automated Updates</category>
  <category>Books</category>
  <guid>https://connorhanan.com/posts/auto/2026-03-28-goodreads.html</guid>
  <pubDate>Sat, 28 Mar 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Recently Read</title>
  <link>https://connorhanan.com/posts/auto/2026-03-21-goodreads.html</link>
  <description><![CDATA[ 




<p><img src="https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1624658259l/58425375._SX98_.jpg" class="img-fluid" width="150"></p>
<section id="moral-aspects-of-city-life-a-series-of-lectures" class="level2">
<h2 class="anchored" data-anchor-id="moral-aspects-of-city-life-a-series-of-lectures">Moral Aspects of City Life: A Series of Lectures</h2>
<p><strong>E.H. Chapin</strong></p>
<p>Rating: ★★★★☆</p>
<p><br></p>
<hr>
<p><em>This post was automatically generated from <a href="https://www.goodreads.com/review/list/98547221-connor-hanan?shelf=read">my Goodreads shelf</a>.</em></p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automated Updates</category>
  <category>Books</category>
  <guid>https://connorhanan.com/posts/auto/2026-03-21-goodreads.html</guid>
  <pubDate>Sat, 21 Mar 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>New Records</title>
  <link>https://connorhanan.com/posts/auto/2026-03-17-discogs.html</link>
  <description><![CDATA[ 




<p><img src="https://i.discogs.com/C15Ptj4epV-D3vb3DniBRycPCSL1p5tterxNsdKcohw/rs:fit/g:sm/q:90/h:600/w:590/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQzMTc0/MzMtMTY2NjUzNDMw/MC03NjQ5LmpwZWc.jpeg" class="img-fluid" width="300"></p>
<section id="deck-of-cards-sweet-thing" class="level2">
<h2 class="anchored" data-anchor-id="deck-of-cards-sweet-thing">Deck Of Cards / Sweet Thing</h2>
<p><strong>T. Texas Tyler</strong><br>
<em>“T” Texas Tyler</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>4 Star Records</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1948</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>1228</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/zQW355qrSZHO3K7t2vl1X1QnCI9RgESsLYWaoQul_Jo/rs:fit/g:sm/q:90/h:598/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTk1MjE3/MzUtMTQ4MjAyMTMw/Ny0yMDcwLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="just-before-the-battle-mother-old-folks-at-home" class="level2">
<h2 class="anchored" data-anchor-id="just-before-the-battle-mother-old-folks-at-home">Just Before The Battle Mother / Old Folks At Home</h2>
<p><strong>Monroe Quartette</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Okeh</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1927</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>45133</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/dH1PB1EfTiFszV7-J8B0rR-lP3KGD0Ko85Uzbq1-dcM/rs:fit/g:sm/q:90/h:600/w:587/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQ0NDcx/NjUtMTQ2ODQ2Njk4/NC04NzY2LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="night-train-to-memphis-low-and-lonely" class="level2">
<h2 class="anchored" data-anchor-id="night-train-to-memphis-low-and-lonely">Night Train To Memphis / Low And Lonely</h2>
<p><strong>Roy Acuff And His Smoky Mountain Boys</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>OKeh</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1942</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>6693</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/0cRvg5DKP7eDvHioll5tWvGm3Lwuwln2MQ8YeEDhNaU/rs:fit/g:sm/q:90/h:600/w:596/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTc4MzUx/ODYtMTQ0OTc5NTU2/MS0yNDE5LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="handsome-molly-train-forty-five" class="level2">
<h2 class="anchored" data-anchor-id="handsome-molly-train-forty-five">Handsome Molly / Train Forty-Five</h2>
<p><strong>Grayson &amp; Whitter</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1928</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>21189</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/5St_iAgfvEUiNxoLCc4w0y0N9YUxhMpjMP0PU1xw-NE/rs:fit/g:sm/q:90/h:600/w:596/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTMyNTU2/NTgtMTY2ODYzOTg2/NC0yNzExLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="train-of-love-there-you-go" class="level2">
<h2 class="anchored" data-anchor-id="train-of-love-there-you-go">Train Of Love / There You Go</h2>
<p><strong>Johnny Cash &amp; The Tennessee Two</strong><br>
<em>Johnny Cash And Tennessee Two</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Sun (9)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1956</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>258</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Rock, Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/G4pcj73RRxl_bARhsxePrm3RNrSC817ldWsFbWPOiOc/rs:fit/g:sm/q:90/h:600/w:594/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTc3OTkz/NjMtMTQ1MDA0NjI5/OC0yNjUxLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="guess-things-happen-that-way" class="level2">
<h2 class="anchored" data-anchor-id="guess-things-happen-that-way">Guess Things Happen That Way</h2>
<p><strong>Johnny Cash &amp; The Tennessee Two</strong><br>
<em>Johnny Cash And The Tennessee Two</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Sun (9)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1958</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>295</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single, Mono)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Blues</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/PvV6x3Uo0SVyI16Ky5wSm352BieXbqsIfLOLoPSOMfk/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTcwMzY0/NDQtMTQzMjIxODQw/OC03MDk1LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="i-forgot-to-remember-to-forget" class="level2">
<h2 class="anchored" data-anchor-id="i-forgot-to-remember-to-forget">I Forgot To Remember To Forget</h2>
<p><strong>Johnny Cash &amp; The Tennessee Two</strong><br>
<em>Johnny Cash And The Tennessee Two</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Sun (9)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1959</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>321</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/rmBs3hs9R4-qFI8F5tFg7-nRb28wd6TmpOnx2sqXpG8/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTMyNTU2/NzQtMTQ4NDg1MTMy/MC04MzE2LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="whatd-i-say" class="level2">
<h2 class="anchored" data-anchor-id="whatd-i-say">What’d I Say</h2>
<p><strong>Jerry Lee Lewis</strong><br>
<em>Jerry Lee Lewis And His Pumping Piano</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Sun (9)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1961</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>356</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Rock, Funk / Soul, Blues, Pop</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 17, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<hr>
<p><em>This post was automatically generated from <a href="https://www.discogs.com/user/syrchanan/collection">my Discogs collection</a>.</em></p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automated Updates</category>
  <category>Music</category>
  <guid>https://connorhanan.com/posts/auto/2026-03-17-discogs.html</guid>
  <pubDate>Tue, 17 Mar 2026 04:00:00 GMT</pubDate>
</item>
<item>
  <title>New Records</title>
  <link>https://connorhanan.com/posts/auto/2026-03-08-discogs.html</link>
  <description><![CDATA[ 




<p><img src="https://i.discogs.com/wYlAL0hKPM0gI6X9EAMz7zxNuGnkWxPhrQM0sbWWYQI/rs:fit/g:sm/q:90/h:600/w:555/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTM2NzE1/NTU4LTE3NzI5ODMx/MDEtNDM3My5qcGVn.jpeg" class="img-fluid" width="300"></p>
<section id="el-capote-de-paseo-amor-de-madre" class="level2">
<h2 class="anchored" data-anchor-id="el-capote-de-paseo-amor-de-madre">El Capote De Paseo / Amor De Madre</h2>
<p><strong>Banda Original Columbia</strong><br>
<em>Banda Columbia</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Columbia</td>
</tr>
<tr class="even">
<td>Year</td>
<td>0</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>93491</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/uw66uzKEx9IZ3e2gD70fUS1RgKvbMDl3XGO8i5NJ5t4/rs:fit/g:sm/q:90/h:600/w:595/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTUwNzA4/NzQtMTY0MTc0Nzg5/MC00OTI5LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="tip-top-medley-fox-trot-if-a-wish-could-make-it-so-medley-fox-trot" class="level2">
<h2 class="anchored" data-anchor-id="tip-top-medley-fox-trot-if-a-wish-could-make-it-so-medley-fox-trot">Tip Top-Medley Fox Trot / If A Wish Could Make It So-Medley Fox Trot</h2>
<p><strong>Six Brown Brothers (2)</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1921</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>18714</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (78 RPM, 10”)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Pop, Stage &amp; Screen</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/Zy3PhLJKweJz2muT86KpFqOj6lF5SEGA8RqxSKXBWvo/rs:fit/g:sm/q:90/h:337/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTEwOTU1/OTY0LTE1MDcxNjUx/OTEtNjQ2Ny5qcGVn.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="detour-someone-won-your-heart-little-darlin" class="level2">
<h2 class="anchored" data-anchor-id="detour-someone-won-your-heart-little-darlin">Detour / Someone Won Your Heart Little Darlin’</h2>
<p><strong>Foy Willing &amp; The Riders Of The Purple Sage</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Decca</td>
</tr>
<tr class="even">
<td>Year</td>
<td>0</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>9000</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/5tIxK4Az7LtiulmKRvCdWI4GCVHvEPI6W_Wyd2FFyNQ/rs:fit/g:sm/q:90/h:571/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTEwMDU5/ODE4LTE0OTA5MTE4/NjMtNTUxMy5qcGVn.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="mississippi-flaming-youth" class="level2">
<h2 class="anchored" data-anchor-id="mississippi-flaming-youth">Mississippi / Flaming Youth</h2>
<p><strong>Duke Ellington And His Orchestra</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1932</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>24057</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Jazz</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/vWW_rlxy4eucGCCZOV5YaAHRn1cF-RiznBoZYXRkmlA/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQ1Mzk5/NzAtMTQ4NjM3NTAy/OS05ODQ2LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="open-the-door-richard-lonesome-blues" class="level2">
<h2 class="anchored" data-anchor-id="open-the-door-richard-lonesome-blues">Open The Door Richard! / Lonesome Blues</h2>
<p><strong>Jack McVea’s All Stars</strong><br>
<em>Jack McVea And His All Stars</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Black &amp; White</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1946</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>792</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Jazz, Blues</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/Sn8FbtsEpQ8kCTdEK6oqOqQj1HcuNQeV6Kp9bA21fyk/rs:fit/g:sm/q:90/h:600/w:591/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTM1NjI5/NzItMTUxODQ4OTc5/OS03MjQ1LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="how-bout-that-mess-drum-boogie" class="level2">
<h2 class="anchored" data-anchor-id="how-bout-that-mess-drum-boogie">How ’Bout That Mess / Drum Boogie</h2>
<p><strong>Gene Krupa And His Orchestra</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Okeh</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1941</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>6046</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Jazz</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/_U7WsWuigi8LXXyg0HZlg2adWxulVxQDipmbacA7Pkc/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTU5MjY3/MjctMTQ4OTcwMzA1/OS0zNzY1LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="the-original-fox-trot-that-moaning-saxophone-rag" class="level2">
<h2 class="anchored" data-anchor-id="the-original-fox-trot-that-moaning-saxophone-rag">The Original Fox Trot / That Moaning Saxophone Rag</h2>
<p><strong>Fred Van Eps Trio</strong><br>
<em>Van Eps Trio</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1915</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>17677</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Pop</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/nHgRVDZNPeudLgmnqPglQruYzG4SQmu1HWKji7-xuio/rs:fit/g:sm/q:90/h:584/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTg5NzY5/NTEtMTQ3MjYwOTk4/Ny01ODQ4LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="my-lonely-lola-lo-in-hawaii-my-own-iona-moi-one-ionae" class="level2">
<h2 class="anchored" data-anchor-id="my-lonely-lola-lo-in-hawaii-my-own-iona-moi-one-ionae">My Lonely Lola Lo (In Hawaii) / My Own Iona (Moi One-Ionae)</h2>
<p><strong>Sterling Trio</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1916</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>18171</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Pop, Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/FTT9upKin-I3uwrisLV_M2zrvy0H7jTm60CGLImbqjM/rs:fit/g:sm/q:90/h:593/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTI2MTEz/OTAtMTU4MTczMjA0/NC02Mzc4LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="stars-and-stripes-forever-march-fairest-of-the-fair-march" class="level2">
<h2 class="anchored" data-anchor-id="stars-and-stripes-forever-march-fairest-of-the-fair-march">Stars And Stripes Forever March / Fairest Of The Fair March</h2>
<p><strong>Sousa’s Band</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1920</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>16777</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM, Reissue, Repress)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Brass &amp; Military</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/ycxpMDm7C-TUAuPsotBfLmoYBk8J_kKBS7hdbs2ElYE/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTIyODcw/ODYtMTI3NDU3NTA0/Mi5qcGVn.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="crazy-man-crazy-whatcha-gonna-do" class="level2">
<h2 class="anchored" data-anchor-id="crazy-man-crazy-whatcha-gonna-do">Crazy Man, Crazy / Whatcha Gonna Do</h2>
<p><strong>Bill Haley And His Comets</strong><br>
<em>Bill Haley With Haley’s Comets</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Essex Records (3)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1953</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>321</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Rock</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/0IASumR7peOQDMz_Iq19aaEjJ5Mn3sKU0kx1IofOx1Y/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQ2Mjgy/MjUtMTM3MDM5Mzkw/Mi0zMTgxLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="the-wang-wang-blues-the-way-you-look-tonight" class="level2">
<h2 class="anchored" data-anchor-id="the-wang-wang-blues-the-way-you-look-tonight">The Wang Wang Blues / The Way You Look Tonight</h2>
<p><strong>Benny Goodman Sextet</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Columbia</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1942</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>36594</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Jazz</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Mar 08, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<hr>
<p><em>This post was automatically generated from <a href="https://www.discogs.com/user/syrchanan/collection">my Discogs collection</a>.</em></p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automated Updates</category>
  <category>Music</category>
  <guid>https://connorhanan.com/posts/auto/2026-03-08-discogs.html</guid>
  <pubDate>Sun, 08 Mar 2026 05:00:00 GMT</pubDate>
</item>
<item>
  <title>New Records</title>
  <link>https://connorhanan.com/posts/auto/2026-02-27-discogs.html</link>
  <description><![CDATA[ 




<p><img src="https://i.discogs.com/uBUqAZTIOrA_Oq71p-daED6tKx6dU8KYuCiAnFzVhYo/rs:fit/g:sm/q:90/h:600/w:597/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTc5ODc3/MjMtMTQ1Mjk4NTQ0/MS00MTU2LmpwZWc.jpeg" class="img-fluid" width="300"></p>
<section id="the-hobo-from-the-t-p-line" class="level2">
<h2 class="anchored" data-anchor-id="the-hobo-from-the-t-p-line">The Hobo From The T &amp; P Line</h2>
<p><strong>Almoth Hodges</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Brunswick</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1930</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>399</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 21, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/-9e-bXn8d-TxPJuELSFyoXFa6Rs8e3G6mqT_kAcp13o/rs:fit/g:sm/q:90/h:598/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTk1ODE2/NDQtMTQ4MzExNzI4/OC02NjczLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="cotillion" class="level2">
<h2 class="anchored" data-anchor-id="cotillion">Cotillion</h2>
<p><strong>National Barn Dance Orchestra</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Bluebird (3)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1933</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>B-5214</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 21, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/5zGDNR0IW8P_j3l5OwNBeBt-Y3iRd-Od_6zmyMYRucg/rs:fit/g:sm/q:90/h:599/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTk1OTUw/MDctMTQ4MzM3MTQ5/MC05OTkxLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="mobile-county-blues-just-because" class="level2">
<h2 class="anchored" data-anchor-id="mobile-county-blues-just-because">Mobile County Blues / Just Because</h2>
<p><strong>Nelstone’s Hawaiians</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1930</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>V-40273</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 21, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/4Jp4TehiN1BTuqp3FUphsYJkTVcEOxuQ16ojvMVp3r8/rs:fit/g:sm/q:90/h:425/w:425/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTUwMTUy/ODMtMTM4MjE5MjI2/Ni0yNDcwLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="a-corn-licker-still-in-georgia---part-3-a-corn-licker-still-in-georgia---part-4" class="level2">
<h2 class="anchored" data-anchor-id="a-corn-licker-still-in-georgia---part-3-a-corn-licker-still-in-georgia---part-4">A Corn Licker Still In Georgia - Part 3 / A Corn Licker Still In Georgia - Part 4</h2>
<p><strong>Clayton McMichen</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Columbia</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1928</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>15258-D</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Shellac (10”, 78 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Non-Music, Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 21, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/QmuRKdgNyLsQIE8SIWPesvBay1KipPqg79dOK6QMK-E/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTU5Mzk5/NDAtMTQwNjg3NjQx/Ny0xMDU1LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="leroy-my-true-love" class="level2">
<h2 class="anchored" data-anchor-id="leroy-my-true-love">Leroy / My True Love</h2>
<p><strong>Jack Scott</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Carlton</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1958</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>462</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Rock, Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 16, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/S2VI9zAVTPjpJXh0hhX7007v34Z5blFT7COqJdamSjk/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTc2ODI3/OTgtMTQ0NjY0NzUz/OS03MDM0LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="mansions-for-me-mothers-only-sleeping" class="level2">
<h2 class="anchored" data-anchor-id="mansions-for-me-mothers-only-sleeping">Mansions For Me / Mother’s Only Sleeping</h2>
<p><strong>Bill Monroe &amp; His Blue Grass Boys</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Columbia</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1954</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>4-54013-s</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single, Reissue)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 16, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/vN8mhQt4dGOvSdxIX_TrX4OLsYIitEThixiUUO2dKnc/rs:fit/g:sm/q:90/h:596/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTIxMDcz/MDQtMTMzOTQzODUx/OC0xMDQ0LmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="ubangi-stomp-black-jack-david" class="level2">
<h2 class="anchored" data-anchor-id="ubangi-stomp-black-jack-david">Ubangi Stomp / Black Jack David</h2>
<p><strong>Warren Smith (3)</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Sun (9)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1956</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>250</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Rock</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 16, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<p><img src="https://i.discogs.com/wX4j0qaUi1YF2f_ok9gdoU2rAZhtoKs9I5ZPWc_BM9o/rs:fit/g:sm/q:90/h:597/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTM2MzI3/MzMtMTMzODI2MjY3/MS05ODQwLmpwZWc.jpeg" class="img-fluid" width="300"></p>
</section>
<section id="last-night-night-before" class="level2">
<h2 class="anchored" data-anchor-id="last-night-night-before">Last Night / Night Before</h2>
<p><strong>The Mar-Keys</strong><br>
<em>Mar-Keys</em></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>Satellite (2)</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1961</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>S-107</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, Single, 45 RPM)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Funk / Soul</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 15, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
</section>
<section id="in-sunny-tennessee-columbus-stockade-blues" class="level2">
<h2 class="anchored" data-anchor-id="in-sunny-tennessee-columbus-stockade-blues">In Sunny Tennessee / Columbus Stockade Blues</h2>
<p><strong>Hal Lone Pine And His Mountaineers</strong></p>
<table class="caption-top table">
<tbody>
<tr class="odd">
<td>Label</td>
<td>RCA Victor</td>
</tr>
<tr class="even">
<td>Year</td>
<td>1954</td>
</tr>
<tr class="odd">
<td>Catalog</td>
<td>48-0668-A</td>
</tr>
<tr class="even">
<td>Format</td>
<td>Vinyl (7”, 45 RPM, Single)</td>
</tr>
<tr class="odd">
<td>Genres</td>
<td>Folk, World, &amp; Country</td>
</tr>
<tr class="even">
<td>Added</td>
<td>Feb 15, 2026</td>
</tr>
</tbody>
</table>
<p><br></p>
<hr>
<p><em>This post was automatically generated from <a href="https://www.discogs.com/user/syrchanan/collection">my Discogs collection</a>.</em></p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Automated Updates</category>
  <category>Music</category>
  <guid>https://connorhanan.com/posts/auto/2026-02-27-discogs.html</guid>
  <pubDate>Fri, 27 Feb 2026 05:00:00 GMT</pubDate>
</item>
<item>
  <title>Discogs Randomizer</title>
  <link>https://connorhanan.com/posts/20260220-discogs-ojs-random/</link>
  <description><![CDATA[ 




<p>This tool will import your discogs collection and offer a randomized selection of which record to play, with filters for your convenience.</p>
<p>Enter username below (case-sensitive) to get started.*</p>
<p>*Please note it may take up to a minute to load your collection depending on size.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="28" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 27;"><span id="cb1-28">viewof username <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guard</span>(</span>
<span id="cb1-29">  ({ template }) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">form</span>(</span>
<span id="cb1-30">    {</span>
<span id="cb1-31">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">username</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>({ <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Discogs Username: '</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">required</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">placeholder</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'e.g., syrchanan'</span> })</span>
<span id="cb1-32">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-33">    { template }</span>
<span id="cb1-34">  )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-35">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">resetLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reset to Previous"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">required</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">resubmit</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span> }</span>
<span id="cb1-36">)</span>
<span id="cb1-37"></span>
<span id="cb1-38"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">md</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`## Filters`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="expression">

</div>
</div>
</div>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="40" data-source-offset="-292" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 39;"><span id="cb2-40">viewof filters <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guard</span>(</span>
<span id="cb2-41">  ({ template }) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">form</span>(</span>
<span id="cb2-42">    {</span>
<span id="cb2-43">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interval</span>(</span>
<span id="cb2-44">        d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">extent</span>(cleanCollection<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-45">        {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Year'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">disabled</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>username<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">username</span>}</span>
<span id="cb2-46">      )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-47">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">search</span>(</span>
<span id="cb2-48">        <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(cleanCollection<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-49">        {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">md</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Record Label &lt;br/&gt; (leave empty to include all)`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">disabled</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>username<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">username</span>}</span>
<span id="cb2-50">      )</span>
<span id="cb2-51">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-52">    { template }</span>
<span id="cb2-53">  )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-54">  { </span>
<span id="cb2-55">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">submitLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reroll"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-56">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">resetLabel</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reset to Previous"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-57">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">required</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-58">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">resubmit</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb2-59">  }</span>
<span id="cb2-60">)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="65" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 64;"><span id="cb3-65">{</span>
<span id="cb3-66"></span>
<span id="cb3-67">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// reload on username.submit</span></span>
<span id="cb3-68">  username</span>
<span id="cb3-69">  </span>
<span id="cb3-70">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>username<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">username</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">md</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">``</span></span>
<span id="cb3-71">  </span>
<span id="cb3-72">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// retrigger on button press</span></span>
<span id="cb3-73">  filters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">reroll</span></span>
<span id="cb3-74"></span>
<span id="cb3-75">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// subsetting and </span><span class="al" style="color: #AD0000;
background-color: null;
font-style: inherit;">TODO</span><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;"> markdown output</span></span>
<span id="cb3-76">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> subset <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> cleanCollection<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-77">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> filters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> filters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> </span>
<span id="cb3-78">      (filters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span>))</span>
<span id="cb3-79">  })</span>
<span id="cb3-80"></span>
<span id="cb3-81">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> record <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getRandomItem</span>(subset)</span>
<span id="cb3-82"></span>
<span id="cb3-83">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>record <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">md</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb3-84"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;br/&gt;</span></span>
<span id="cb3-85"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  Invalid filters resulted in an empty search. </span></span>
<span id="cb3-86"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;br/&gt; </span></span>
<span id="cb3-87"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  Please adjust and try again.`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb3-88"></span>
<span id="cb3-89">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">md</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb3-90"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;br/&gt;</span></span>
<span id="cb3-91"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;br/&gt;</span></span>
<span id="cb3-92"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">Your selection is...</span></span>
<span id="cb3-93"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;br/&gt;</span></span>
<span id="cb3-94"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;br/&gt;</span></span>
<span id="cb3-95"></span>
<span id="cb3-96"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">## </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-97"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">**</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">artists</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">**  </span></span>
<span id="cb3-98"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">artists</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">anv</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`*</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">artists</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">anv</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">*`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-99"></span>
<span id="cb3-100"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;div style="</span></span>
<span id="cb3-101"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  display: flex;</span></span>
<span id="cb3-102"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  flex-wrap: wrap;</span></span>
<span id="cb3-103"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  gap: 2rem;</span></span>
<span id="cb3-104"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  align-items: flex-start;</span></span>
<span id="cb3-105"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  flex-direction: row;</span></span>
<span id="cb3-106"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;</span></span>
<span id="cb3-107"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;div style="flex: 0 0 300px; min-width: 150px; text-align: center;"&gt;</span></span>
<span id="cb3-108"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;img src="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">img</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">" alt="</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">" style="height:300px;object-fit:contain;max-width:100%;"&gt;</span></span>
<span id="cb3-109"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/div&gt;</span></span>
<span id="cb3-110"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;div style="flex: 1 1 300px; min-width: 250px; max-width: 400px;"&gt;</span></span>
<span id="cb3-111"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;table&gt;</span></span>
<span id="cb3-112"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      &lt;tr&gt;&lt;th style='text-align:left;'&gt;Year&lt;/th&gt;&lt;td&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;</span></span>
<span id="cb3-113"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      &lt;tr&gt;&lt;th style='text-align:left;'&gt;Label&lt;/th&gt;&lt;td&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> · Cat# </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">catno</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;</span></span>
<span id="cb3-114"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      &lt;tr&gt;&lt;th style='text-align:left;'&gt;Format&lt;/th&gt;&lt;td&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">name</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">descriptions</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">', '</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)&lt;/td&gt;&lt;/tr&gt;</span></span>
<span id="cb3-115"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      &lt;tr&gt;&lt;th style='text-align:left;'&gt;Genre&lt;/th&gt;&lt;td&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">genres</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">', '</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'—'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;</span></span>
<span id="cb3-116"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      &lt;tr&gt;&lt;th style='text-align:left;'&gt;Style&lt;/th&gt;&lt;td&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>record<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">styles</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">', '</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">??</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'—'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/td&gt;&lt;/tr&gt;</span></span>
<span id="cb3-117"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    &lt;/table&gt;</span></span>
<span id="cb3-118"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/div&gt;</span></span>
<span id="cb3-119"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;</span></span>
<span id="cb3-120"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;style&gt;</span></span>
<span id="cb3-121"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">@media (max-width: 700px) {</span></span>
<span id="cb3-122"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  div[style*="display: flex"] {</span></span>
<span id="cb3-123"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    flex-direction: column !important;</span></span>
<span id="cb3-124"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    gap: 1rem !important;</span></span>
<span id="cb3-125"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb3-126"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-127"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">table th, table td {</span></span>
<span id="cb3-128"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: 0.5em 1.5em 0.5em 0.5em;</span></span>
<span id="cb3-129"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb3-130"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/style&gt;</span></span>
<span id="cb3-131"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb3-132">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb4" data-startfrom="139" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 138;"><span id="cb4-139"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">guard</span>(fn<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> options <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}) {</span>
<span id="cb4-140">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> {</span>
<span id="cb4-141">    submitLabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Submit"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-142">    resetLabel <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Reset"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-143">    required <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-144">    resubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-145">    width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fit-content"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-146">    justify <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-147">    valid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> input <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">querySelector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":invalid"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-148">  } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-149"></span>
<span id="cb4-150">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> onSubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-151">    value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-152">    submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>resubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> invalid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-153">    reset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-154">    wrapper<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatchEvent</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Event</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"input"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">bubbles</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span> }))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-155">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-156">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> onReset <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-157">    input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-158">    submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>resubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> invalid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-159">    reset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-160">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-161">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> onInnerInputCapture <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-162">    invalid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-163">    submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-164">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-165">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> onInnerInput <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-166">    e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopPropagation</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-167">    invalid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">valid</span>(input)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-168">    submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> invalid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-169">    reset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-170">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-171">  </span>
<span id="cb4-172">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> submit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;button </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">disabled</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>resubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>required<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">onclick</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> onSubmit}<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>submitLabel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-173">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> reset <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;button </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">disabled</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">onclick</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> onReset}<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>resetLabel<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-174">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> footer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div&gt;&lt;hr style="padding:0;margin:10px 0"&gt;&lt;div style="display:flex;gap:1ch;justify-content:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>justify<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>submit<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>reset<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-175">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> template <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> inputs <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span></span>
<span id="cb4-176">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">isArray</span>(inputs) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> inputs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">values</span>(inputs)</span>
<span id="cb4-177">  <span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}${</span>footer<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-178">  </span>
<span id="cb4-179">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fn</span>({submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> reset<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> footer<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> template<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> onSubmit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> onReset})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-180">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> invalid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!!</span>input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">querySelector</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">":invalid"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-181">  submit<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">disabled</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>resubmit <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> invalid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-182"></span>
<span id="cb4-183">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"input"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> onInnerInputCapture<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">capture</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-184">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"input"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> onInnerInput)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-185">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> required <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">undefined</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-186">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> wrapper <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div style="width:</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>width<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">"&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>input<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-187">  wrapper<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"submit"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> onSubmit)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-188">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defineProperty</span>(wrapper<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"value"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-189">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">get</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-190">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> (v) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> { input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> v }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-191">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-192">}</span>
<span id="cb4-193"></span>
<span id="cb4-194"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">interval</span>(range <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> options <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}) {</span>
<span id="cb4-195">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-196">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> {</span>
<span id="cb4-197">    step <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">001</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-198">    label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-199">    value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-200">    format <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ([start<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> end]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>start<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> … </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>end<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-201">    color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-202">    width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">360</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-203">    theme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-204">    __ns__ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomScope</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-205">  } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-206"></span>
<span id="cb4-207">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> css <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-208"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">#</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> {</span></span>
<span id="cb4-209"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  font: 13px/1.2 var(--sans-serif);</span></span>
<span id="cb4-210"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  display: flex;</span></span>
<span id="cb4-211"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  align-items: baseline;</span></span>
<span id="cb4-212"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  flex-wrap: wrap;</span></span>
<span id="cb4-213"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  max-width: 100%;</span></span>
<span id="cb4-214"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: auto;</span></span>
<span id="cb4-215"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-216"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">@media only screen and (min-width: 30em) {</span></span>
<span id="cb4-217"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  #</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> {</span></span>
<span id="cb4-218"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    flex-wrap: nowrap;</span></span>
<span id="cb4-219"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    width: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cssLength</span>(width)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-220"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  }</span></span>
<span id="cb4-221"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-222"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">#</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> .label {</span></span>
<span id="cb4-223"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 120px;</span></span>
<span id="cb4-224"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: 5px 0 4px 0;</span></span>
<span id="cb4-225"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  margin-right: 6.5px;</span></span>
<span id="cb4-226"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  flex-shrink: 0;</span></span>
<span id="cb4-227"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-228"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">#</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> .form {</span></span>
<span id="cb4-229"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  display: flex;</span></span>
<span id="cb4-230"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 100%;</span></span>
<span id="cb4-231"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-232"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">#</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> .range {</span></span>
<span id="cb4-233"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  flex-shrink: 1;</span></span>
<span id="cb4-234"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 100%;</span></span>
<span id="cb4-235"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-236"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">#</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> .range-slider {</span></span>
<span id="cb4-237"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 100%;</span></span>
<span id="cb4-238"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-239"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  `</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-240">  </span>
<span id="cb4-241">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> $range <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rangeInput</span>({min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> step<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"100%"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> theme})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-242">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> $output <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;output&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-243">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> $view <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div id=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>__ns__<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb4-244"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>label <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">''</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="label"&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>label<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-245"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;div class=form&gt;</span></span>
<span id="cb4-246"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;div class=range&gt;</span></span>
<span id="cb4-247"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>$range<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;div class=range-output&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>$output<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;</span></span>
<span id="cb4-248"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  &lt;/div&gt;</span></span>
<span id="cb4-249"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;</span></span>
<span id="cb4-250"><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;style&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>css<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-251"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  `</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-252"></span>
<span id="cb4-253">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> update <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-254">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">format</span>([$range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> $range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-255">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">typeof</span> content <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'string'</span>) $output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> content<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-256">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb4-257">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span>($output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lastChild</span>) $output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">lastChild</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">remove</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-258">      $output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">appendChild</span>(content)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-259">    }</span>
<span id="cb4-260">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-261">  $range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">oninput</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> update<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-262">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-263">  </span>
<span id="cb4-264">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defineProperty</span>($view<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-265">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">get</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> $range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-266">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ([a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-267">      $range<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-268">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">update</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-269">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-270">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-271">}</span>
<span id="cb4-272"></span>
<span id="cb4-273"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rangeInput</span>(options <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}) {</span>
<span id="cb4-274">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> {</span>
<span id="cb4-275">    min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-276">    max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-277">    step <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'any'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-278">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> defaultValue <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-279">    color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-280">    width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-281">    theme <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> theme_Flat<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-282">  } <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> options<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-283">  </span>
<span id="cb4-284">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> controls <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-285">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> scope <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomScope</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-286">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> clamp <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> v<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-287"></span>
<span id="cb4-288">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Will be used to sanitize values while avoiding floating point issues.</span></span>
<span id="cb4-289">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;input type=range </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>{min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> step}<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-290">  </span>
<span id="cb4-291">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> dom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>scope<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> range-slider`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> style=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>{</span>
<span id="cb4-292">    color<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-293">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">cssLength</span>(width)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-294">  }<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&gt;</span></span>
<span id="cb4-295"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">track</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="range-track"&gt;</span></span>
<span id="cb4-296"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zone</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="range-track-zone"&gt;</span></span>
<span id="cb4-297"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="range-select" tabindex=0&gt;</span></span>
<span id="cb4-298"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="thumb thumb-min" tabindex=0&gt;`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-299"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">        </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;div class="thumb thumb-max" tabindex=0&gt;`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-300"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">      `</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-301"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">    `</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-302"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  `</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-303"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;style&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>theme<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replace</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/:scope</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\b</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/g</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>scope)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-304"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&lt;/div&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-305"></span>
<span id="cb4-306">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> changed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-307">  <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">defineProperty</span>(dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'value'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb4-308">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">get</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>value]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-309">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">set</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ([a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-310">      value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sanitize</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-311">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateRange</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-312">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-313">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-314"></span>
<span id="cb4-315">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sanitize <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-316">    a <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">isNaN</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ((input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">valueAsNumber</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-317">    b <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">isNaN</span>(b) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> ((input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">value</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">valueAsNumber</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-318">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">min</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-319">  }</span>
<span id="cb4-320">  </span>
<span id="cb4-321">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> updateRange <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> () <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-322">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> ratio <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> (max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-323">    dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setProperty</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'--range-min'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ratio</span>(value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-324">    dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">style</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setProperty</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'--range-max'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ratio</span>(value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-325">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-326"></span>
<span id="cb4-327">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> dispatch <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> name <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-328">    dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatchEvent</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Event</span>(name<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">bubbles</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-329">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-330">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> setValue <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> vmax) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-331">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [pmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pmax] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-332">    value <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sanitize</span>(vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> vmax)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-333">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">updateRange</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-334">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Only dispatch if values have changed.</span></span>
<span id="cb4-335">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(pmin <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> pmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> value[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-336">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatch</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'input'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-337">    changed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-338">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-339">  </span>
<span id="cb4-340">  <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>defaultValue)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-341">  </span>
<span id="cb4-342">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Mousemove handlers.</span></span>
<span id="cb4-343">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> handlers <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>([</span>
<span id="cb4-344">    [controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">min</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-345">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clamp</span>(min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-346">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(v<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-347">    }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-348">    [controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">max</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-349">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clamp</span>(ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-350">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-351">    }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-352">    [controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">range</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (dt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-353">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-354">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clamp</span>(min<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ov[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> dt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-355">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(v<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> d)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-356">    }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-357">  ])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-358">  </span>
<span id="cb4-359">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Returns client offset object.</span></span>
<span id="cb4-360">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pointer <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">touches</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">touches</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-361">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Note: Chrome defaults "passive" for touch events to true.</span></span>
<span id="cb4-362">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> on  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> fn) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">addEventListener</span>(e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> fn<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">passive</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-363">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> off <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> fn) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">' '</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">document</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">removeEventListener</span>(e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> fn<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">passive</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-364">  </span>
<span id="cb4-365">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> initialX<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> initialV<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-366">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">handleDrag</span>(e) {</span>
<span id="cb4-367">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Gracefully handle exit and reentry of the viewport.</span></span>
<span id="cb4-368">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">buttons</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">touches</span>) {</span>
<span id="cb4-369">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">handleDragStop</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-370">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-371">    }</span>
<span id="cb4-372">    dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-373">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> w <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zone</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getBoundingClientRect</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-374">    e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">preventDefault</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-375">    handlers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(target)((<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointer</span>(e)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientX</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> initialX) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> w<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> initialV)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-376">  }</span>
<span id="cb4-377">  </span>
<span id="cb4-378">  </span>
<span id="cb4-379">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">handleDragStop</span>(e) {</span>
<span id="cb4-380">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">off</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mousemove touchmove'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> handleDrag)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-381">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">off</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mouseup touchend'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> handleDragStop)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-382">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(changed) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatch</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'change'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-383">  }</span>
<span id="cb4-384">  </span>
<span id="cb4-385">  invalidation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">then</span>(handleDragStop)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-386">  </span>
<span id="cb4-387">  dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ontouchstart</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onmousedown</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-388">    dragging <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-389">    changed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-390">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>handlers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span>)) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-391">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mousemove touchmove'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> handleDrag)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-392">    <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'mouseup touchend'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> handleDragStop)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-393">    e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">preventDefault</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-394">    e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stopPropagation</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-395">    </span>
<span id="cb4-396">    target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> e<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-397">    initialX <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointer</span>(e)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientX</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-398">    initialV <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-399">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-400">  </span>
<span id="cb4-401">  controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">track</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">onclick</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-402">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(dragging) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-403">    changed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-404">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> controls<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">zone</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getBoundingClientRect</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-405">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">clamp</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pointer</span>(e)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">clientX</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">left</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">width</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-406">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> min <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> t <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> (max <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> min)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-407">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> vmax] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> value<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> vmax <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> vmin<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-408">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> vmin) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(v<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> d)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-409">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> vmax) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">setValue</span>(v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> v)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-410">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span>(changed) <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dispatch</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'change'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-411">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-412">  </span>
<span id="cb4-413">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> dom<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-414">}</span>
<span id="cb4-415"></span>
<span id="cb4-416">cssLength <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> v <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">typeof</span> v <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'number'</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>v<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">px`</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>v<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-417"></span>
<span id="cb4-418">html <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> htl<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">html</span></span>
<span id="cb4-419"></span>
<span id="cb4-420"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">randomScope</span>(prefix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'scope-'</span>) {</span>
<span id="cb4-421">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> prefix <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> (<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">performance</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">now</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">random</span>())<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toString</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">32</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">replace</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'-'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb4-422">}</span>
<span id="cb4-423"></span>
<span id="cb4-424">theme_Flat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb4-425"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">/* Options */</span></span>
<span id="cb4-426"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope {</span></span>
<span id="cb4-427"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  color: #3b99fc;</span></span>
<span id="cb4-428"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 240px;</span></span>
<span id="cb4-429"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-430"></span>
<span id="cb4-431"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope {</span></span>
<span id="cb4-432"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: relative;</span></span>
<span id="cb4-433"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  display: inline-block;</span></span>
<span id="cb4-434"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  --thumb-size: 15px;</span></span>
<span id="cb4-435"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  --thumb-radius: calc(var(--thumb-size) / 2);</span></span>
<span id="cb4-436"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: var(--thumb-radius) 0;</span></span>
<span id="cb4-437"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  margin: 2px;</span></span>
<span id="cb4-438"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  vertical-align: middle;</span></span>
<span id="cb4-439"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-440"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .range-track {</span></span>
<span id="cb4-441"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  box-sizing: border-box;</span></span>
<span id="cb4-442"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: relative;</span></span>
<span id="cb4-443"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  height: 7px;</span></span>
<span id="cb4-444"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  background-color: hsl(0, 0%, 80%);</span></span>
<span id="cb4-445"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  overflow: visible;</span></span>
<span id="cb4-446"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border-radius: 4px;</span></span>
<span id="cb4-447"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  padding: 0 var(--thumb-radius);</span></span>
<span id="cb4-448"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-449"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .range-track-zone {</span></span>
<span id="cb4-450"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  box-sizing: border-box;</span></span>
<span id="cb4-451"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: relative;</span></span>
<span id="cb4-452"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-453"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .range-select {</span></span>
<span id="cb4-454"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  box-sizing: border-box;</span></span>
<span id="cb4-455"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: relative;</span></span>
<span id="cb4-456"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  left: var(--range-min);</span></span>
<span id="cb4-457"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: calc(var(--range-max) - var(--range-min));</span></span>
<span id="cb4-458"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  cursor: ew-resize;</span></span>
<span id="cb4-459"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  background: currentColor;</span></span>
<span id="cb4-460"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  height: 7px;</span></span>
<span id="cb4-461"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border: inherit;</span></span>
<span id="cb4-462"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-463"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">/* Expands the hotspot area. */</span></span>
<span id="cb4-464"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .range-select:before {</span></span>
<span id="cb4-465"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  content: "";</span></span>
<span id="cb4-466"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: absolute;</span></span>
<span id="cb4-467"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: 100%;</span></span>
<span id="cb4-468"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  height: var(--thumb-size);</span></span>
<span id="cb4-469"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  left: 0;</span></span>
<span id="cb4-470"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  top: calc(2px - var(--thumb-radius));</span></span>
<span id="cb4-471"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-472"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .range-select:focus,</span></span>
<span id="cb4-473"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .thumb:focus {</span></span>
<span id="cb4-474"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  outline: none;</span></span>
<span id="cb4-475"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-476"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .thumb {</span></span>
<span id="cb4-477"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  box-sizing: border-box;</span></span>
<span id="cb4-478"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  position: absolute;</span></span>
<span id="cb4-479"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  width: var(--thumb-size);</span></span>
<span id="cb4-480"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  height: var(--thumb-size);</span></span>
<span id="cb4-481"></span>
<span id="cb4-482"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  background: #fcfcfc;</span></span>
<span id="cb4-483"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  top: -4px;</span></span>
<span id="cb4-484"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border-radius: 100%;</span></span>
<span id="cb4-485"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  border: 1px solid hsl(0,0%,55%);</span></span>
<span id="cb4-486"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  cursor: default;</span></span>
<span id="cb4-487"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  margin: 0;</span></span>
<span id="cb4-488"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-489"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .thumb:active {</span></span>
<span id="cb4-490"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  box-shadow: inset 0 var(--thumb-size) #0002;</span></span>
<span id="cb4-491"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-492"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .thumb-min {</span></span>
<span id="cb4-493"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  left: calc(-1px - var(--thumb-radius));</span></span>
<span id="cb4-494"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-495"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">:scope .thumb-max {</span></span>
<span id="cb4-496"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">  right: calc(-1px - var(--thumb-radius));</span></span>
<span id="cb4-497"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">}</span></span>
<span id="cb4-498"><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display hidden">
<div>
<div id="ojs-cell-3-7" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="503" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 502;"><span id="cb5-503">sleep <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (ms) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Promise</span>(resolve <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">setTimeout</span>(resolve<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ms))</span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb6" data-startfrom="509" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 508;"><span id="cb6-509">getRandomItem <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (arr) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> arr[<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">random</span>() <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> arr<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>)]</span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="515" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 514;"><span id="cb7-515">pageLim <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span></span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell hidden">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb8" data-startfrom="521" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 520;"><span id="cb8-521">cleanCollection <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb8-522">  </span>
<span id="cb8-523">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-524">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> releases <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-525">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> totalPages <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb8-526"></span>
<span id="cb8-527">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// reload on username</span></span>
<span id="cb8-528">  username</span>
<span id="cb8-529">  </span>
<span id="cb8-530">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>username<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">username</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> []</span>
<span id="cb8-531"></span>
<span id="cb8-532">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">do</span> {</span>
<span id="cb8-533">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> response <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fetch</span>(</span>
<span id="cb8-534">      <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`https://api.discogs.com/users/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>username<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">username</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">/collection/folders/0/releases?per_page=100&amp;page=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>page<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">&amp;sort=added&amp;sort_order=desc`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-535">      { </span>
<span id="cb8-536">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">headers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { </span>
<span id="cb8-537">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"User-Agent"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"DiscogsSuggestedPlay/0.1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb8-538">        <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Authorization"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Discogs token=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>DISCOGS_API_TOKEN<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> } </span>
<span id="cb8-539">      }</span>
<span id="cb8-540">    )</span>
<span id="cb8-541">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> response<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">json</span>()</span>
<span id="cb8-542">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">console</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Parsing Collection Page: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>page<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>totalPages<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb8-543">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message</span>) {</span>
<span id="cb8-544">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">throw</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Error</span>(<span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">message</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>)</span>
<span id="cb8-545">    }</span>
<span id="cb8-546">    totalPages <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pagination</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">pages</span></span>
<span id="cb8-547">    releases <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> releases<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">releases</span>)</span>
<span id="cb8-548">    page<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span></span>
<span id="cb8-549">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> pageLim) {</span>
<span id="cb8-550">      <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">console</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">log</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'pageLim reached, stopping early'</span>)</span>
<span id="cb8-551">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb8-552">    }</span>
<span id="cb8-553">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sleep</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1000</span>)</span>
<span id="cb8-554">  } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (page <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> totalPages)</span>
<span id="cb8-555">  </span>
<span id="cb8-556">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> releases<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb8-557">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb8-558">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-559">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">year</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-560">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">formats</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">formats</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-561">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">labels</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">labels</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-562">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">artists</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">artists</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-563">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">genres</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">genres</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-564">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">styles</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">styles</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb8-565">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">img</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">basic_information</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cover_image</span></span>
<span id="cb8-566">    }</span>
<span id="cb8-567">  })</span>
<span id="cb8-568">}</span></code></pre></div></div>
<div class="cell-output cell-output-display hidden">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<hr>
<p>Inspired by Real_gone_daddy45’s trove - hopefully this should solve any music indecision!</p>
<p>-CH</p>



 ]]></description>
  <category>OJS</category>
  <category>Music</category>
  <guid>https://connorhanan.com/posts/20260220-discogs-ojs-random/</guid>
  <pubDate>Fri, 20 Feb 2026 05:00:00 GMT</pubDate>
</item>
<item>
  <title>The Quintessential American</title>
  <link>https://connorhanan.com/posts/20250817-quintessential-american/</link>
  <description><![CDATA[ 




<p>While I’ve been working on some new posts, I decided to take a break and clean out one of my hard drives. Lo and behold, I stumbled across some of my old college papers!</p>
<p>Mostly as a way to ensure I don’t lose them, I thought I might share a select few here, beginning with one I wrote in a <em>James Bond</em> class. Just as the eponymous character has become known as the quintessential British figure, we were tasked with determining who is the American equivalent.</p>
<section id="the-quintessential-american" class="level2">
<h2 class="anchored" data-anchor-id="the-quintessential-american">The Quintessential American</h2>
<p>Characters in the media often adhere to certain predefined roles, allowing audiences to understand the character much quicker. These “stock” characteristics do not have to only be limited to the character’s actions; rather, they can also speak to matters of identity. The perfect example of this is James Bond, who is quintessentially British<sup>1</sup>. He is suave, upper-class, has command of every situation – essentially, he is everything that the stereotypical Briton has come to represent.</p>
<p>However, this phenomenon extends beyond the overly British Bond – there are counterparts for many other cultures all over the world. “The Man With No Name”, from the Dollars Trilogy, can be considered stereotypically American as a character, specifically in The Good, The Bad, and The Ugly.</p>
<p>The Man With No Name, or “Blondie” (as Tuco, the Ugly, calls him), is defined almost entirely by core tenets of the American stereotype<sup>2</sup>. Popularly, among the world’s various forms of media, Americans have commonly been depicted as arrogant and over-zealous.</p>
<p>These stereotypes are activated by a few different aspects of Blondie’s environment and character<sup>3</sup>. First and foremost, the film is set in New Mexico around the middle of the American Civil War, a time at which this area was still very much a frontier.</p>
<p>The harsh lands and unforgiving climates set the stage perfectly for Blondie to eventually triumph over them, giving the impression that he will triumph over anything that comes his way. This goes hand in hand with Blondie’s quiet, self-assured nature – they both perpetuate an arrogance that goes unmatched amongst the other characters of the film. These traits of Blondie’s act as primers, triggering the audience to recall the well-established schema<sup>4</sup> of the “arrogant American” identity.</p>
<p>Another quintessentially American trait is to believe in one’s own goodness, no matter the methods employed. Historically, the United States has employed, well, less than honest methods to gain and keep power on the world stage.</p>
<p>As such, it has become a part of the national identity – so long as America comes out on top, most of the steps in between can be overlooked. Accordingly, Blondie’s actions adhere to this mantra of doing good with less than scrupulous means.</p>
<p>Throughout the film, he is an anti-hero, willing to lie, cheat, gamble, kill and whatever else is necessary to get ahead. However, in the enigma code<sup>5</sup> that is the film’s title, he is the titular “Good” character, which implies that he has morals to some extent, and at the very least, is the best of the rest of the characters. The audience, watching The Man With No Name act contrary to his given descriptor, is exposed to example after example of the ends justifying the means in stereotypical American fashion.</p>
<p>Though the previously mentioned schema tends to support the interpretation of negative traits in Blondie, there are some good ones as well. Pax Americana is the idea that as soon as the United States gained hemispheric economic and militaristic dominance after World War II, an era of peace followed in its trail.</p>
<p>In the early parts of the film, Blondie struggles to gain the upper hand against Tuco, right up until he learns where the gold is. This knowledge, combined with Blondie being constantly armed after this inflection point, is very reminiscent of Pax Americana. Whether the audience can define it or not, they have been primed through repeated exposure to these ideas<sup>6</sup>, so even the subtlest surfacing of them will bring to mind American identity.</p>
<p>Perhaps, this is indeed the most critical part of implicit association: the viewer does not have to explicitly recall precise definitions and try to apply them to the situation. All that is needed is enough of a pattern for the brain to recognize it, and the rest falls in to place<sup>7</sup>.</p>
<p>The Man With No Name’s arrogance, antithetical nature and similarities to Pax Americana all bring forth views of American identity in the minds of the audience. As media consumers, we have developed a common schema of what the American identity consists of; however, realizing the connection from a character on screen to implicit associations is another story.</p>
<hr>
<p>I had a rather fun time writing this one, as it meant I got to rewatch a classic!</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Baron C. (2009). Doctor No: bonding Britishness to racial sovereignty. In C. Lindler (ed.). The James Bond Phenomenon, A Critical Reader. Manchester: Manchester University Press.↩︎</p></li>
<li id="fn2"><p>Gorham, B. (2019). “The Social Psychology of Stereotypes and Bias: Implications for Media Audiences” In Lind, R.A. (Ed.) Race/Gender/Media. Considering Diversity Across Audiences, Content and Producers. Boston: Allyn &amp; Bacon.↩︎</p></li>
<li id="fn3"><p>Gorham, B. (2019). “The Social Psychology of Stereotypes and Bias: Implications for Media Audiences” In Lind, R.A. (Ed.) Race/Gender/Media. Considering Diversity Across Audiences, Content and Producers. Boston: Allyn &amp; Bacon.↩︎</p></li>
<li id="fn4"><p>Gorham, B. (2019). “The Social Psychology of Stereotypes and Bias: Implications for Media Audiences” In Lind, R.A. (Ed.) Race/Gender/Media. Considering Diversity Across Audiences, Content and Producers. Boston: Allyn &amp; Bacon.↩︎</p></li>
<li id="fn5"><p>De Reeper, M. (2013). How to analyze movies #2: Signs, codes and conventions. From Film Inquiry (website). Available at https://www.filminquiry.com/analyse-movies-signs/↩︎</p></li>
<li id="fn6"><p>Gorham, B. (2019). “The Social Psychology of Stereotypes and Bias: Implications for Media Audiences” In Lind, R.A. (Ed.) Race/Gender/Media. Considering Diversity Across Audiences, Content and Producers. Boston: Allyn &amp; Bacon.↩︎</p></li>
<li id="fn7"><p>Gorham, B. (2019). “The Social Psychology of Stereotypes and Bias: Implications for Media Audiences” In Lind, R.A. (Ed.) Race/Gender/Media. Considering Diversity Across Audiences, Content and Producers. Boston: Allyn &amp; Bacon.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Analysis</category>
  <category>College</category>
  <guid>https://connorhanan.com/posts/20250817-quintessential-american/</guid>
  <pubDate>Sun, 17 Aug 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Bury Me Not</title>
  <link>https://connorhanan.com/posts/20250802-bury-me-not/</link>
  <description><![CDATA[ 




<p>This my second musical deep dive; if you missed the first, <a href="../../posts/20221024-john-hardy-vs-henry/index.html">you can catch it here</a>.</p>
<p>Additionally, I have again created an accompanying playlist to this post: click <a href="https://open.spotify.com/playlist/5pnmTf5gbT0LHMLi8Mt3C0?si=f4158e9ed6884c40" style="color: #1DB954;">here</a> to listen to different versions as you read!</p>
<hr>
<section id="foreword" class="level1">
<h1>Foreword</h1>
<p>As you can probably tell by now, folk music is my favorite genre of music because every part of it is a historical artifact. The recorders, the lyrics, the performers – each have their own rich background which makes the combination of them even more special. However, American folk specifically holds a special place in my heart, since it’s a unique blend of worldly traditions with specifically American experiences.</p>
<p>“John Henry” and “John Hardy” from the last post in this series are perfect examples: both men<sup>1</sup> exemplify the common man being a hero (as opposed to kings, knights, etc. from other Western traditions), the frontier experience of lawlessness and overcoming the odds, as well as the historical context of Post-Reconstruction meets the Industrial Revolution.</p>
<p>So without any further ado, let’s look at “Bury Me Not on the Lone Prarie”, a popular cowboy folk song, as another unique example of American folk music.</p>
</section>
<section id="th-century" class="level1">
<h1>19th Century</h1>
<section id="original-poem" class="level2">
<h2 class="anchored" data-anchor-id="original-poem">Original Poem</h2>
<p>“Bury Me Not on the Lone Prarie”, also “The Cowboy’s Lament”/“The Dying Cowboy”, was, just as much other American folk, passed down via oral transmission before being ever recorded. However, we need to back up even farther to get to the original basis for the song.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/uu.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="454"></p>
</figure>
</div>
<p>The earliest version of the song I could find was not actually a song – instead, it was originally published as a poem called “The Ocean Burial” in the <em>Universalist Union</em>, a religious journal published in Antebellum New York. Written by the Rev.&nbsp;E. H. Chapin in the 6/22/1839 issue<sup>2</sup>, which was a lament from the perspectives of sailors wishing to not be buried at sea, with the first stanza reading:</p>
<blockquote class="blockquote">
<p>“Bury me not in the deep, deep sea?”<br>
The words came faint and mournfully,<br>
From the pallid lips of a youth, who lay<br>
On the cabin couch, where day by day,<br>
He had wasted and pined till o’er his brow,<br>
The death-shade had slowly passed, and now,<br>
When the land and his fond-loved home were nigh,<br>
They had gathered around him to see him die.</p>
</blockquote>
<p>As you can see, there’s no mention of the frontier, or cowboys, yet the main structure of the song is still present (“deep deep sea” vs “lone prairie”, etc.). It will still be decades before we start to see the version we know develop; however, this poem was later picked up as-is for publication elsewhere.</p>
</section>
<section id="the-southern-literary-messenger" class="level2">
<h2 class="anchored" data-anchor-id="the-southern-literary-messenger">The Southern Literary Messenger</h2>
<p>Later, in September of the same year (1839), the same poem by Rev.&nbsp;E. H. Chapin was published in the <em>Southern Literary Messenger</em>, a paper “devoted to every department of literature and fine arts”<sup>3</sup> in Richmond, VA. Nestled between various other poems and a treatises<sup>4</sup>, it seems to be a pretty straight reprint of the original poem. As is custom, here is the first stanza:</p>
<blockquote class="blockquote">
<p>“Bury me not in the deep, deep sea!”<br>
The words came faint and mournfully,<br>
From the pallid lips of a youth, who lay<br>
On the cabin couch, where, day by day,<br>
He had wasted and pined, till o’er his brow<br>
The death shade had slowly passed—and now,<br>
When the land and his fond-loved home were nigh,<br>
They had gathered around him to see him die.</p>
</blockquote>
<p>Of course, it was only a few months after the <em>Univeralist Union</em>, but the distance between the publications in such a short span already bodes well for the rate of spread of this poem. Granted, traveling the eastern seaboard of the United States in 1839 was far easier than going cross-country, but it’s still no small feat that the same poem was being taken up in different intellectual circles around the same time.</p>
</section>
<section id="setting-to-music" class="level2">
<h2 class="anchored" data-anchor-id="setting-to-music">Setting to Music</h2>
<p>To this point, each of the previous publications have been purely poems – enter George N. Allen, who published the first (that I can find) sheet music to the song, entitled “The Ocean Burial”<sup>5</sup>. Published in Boston in 1850 (and affectionately dedicated to his sister), Allen’s version of the song still has largely left the text the same – though his musical composition is not the one we are familiar with today.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/allen.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="467"></p>
</figure>
</div>
<p>If you are interested, you can listen to that version here:</p>
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/R5Kx22t3Ejc" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>
<p>And per usual, here is the opening verse:</p>
<blockquote class="blockquote">
<p>“O! bury me not in the deep, deep sea”<br>
The words came low and mournfully<br>
From the pallid lips of youth, who lay<br>
On his cabin couch at close of day<br>
He had wasted and pined ’till o´er his brow<br>
The death-shade had slowly passed, and now<br>
Where the land and his fond loved home were nigh<br>
They had gathered around him to see him to die</p>
</blockquote>
<p>Now properly set to music, it’s truly become a lament in my eyes, as the music offers much more emotion to the work than before.</p>
</section>
<section id="first-cowboy-influences" class="level2">
<h2 class="anchored" data-anchor-id="first-cowboy-influences">First Cowboy Influences</h2>
<p>The next time we see the song is back in the paper, though this time it has very much adopted its cowboy influence. Jumping forward to 6/1/1887, under a miscellaneous section of the <em>Vermont Watchman</em>, we see it published under a new name: “the Song of the Dy-ing Cowboy”<sup>6</sup>. Before we go any farther, let’s take a look at the beginning:</p>
<blockquote class="blockquote">
<p>“Oh! bury me not on the lone prairie!”<br>
These words came slow and mournfully<br>
From the pallid lips of a youth who lay<br>
On his dying couch at the close of day.</p>
</blockquote>
<p>Still, there is not much difference between this version and those that preceded it; however, it is clearly beginning to morph into the folk tune we know today. This transition becomes even clearer when you proceed to the third verse:</p>
<blockquote class="blockquote">
<p>“Oh! bury me not on the lone prairie,<br>
Where the wild coyotes will howl over me,<br>
For I always wished to be buried, when I died,<br>
In the little church-yard on the green hillside.</p>
</blockquote>
<p>This time, the song also was not published alone – in fact, in the miscellaneous section, it’s part of a larger work called “Life Among the Cowboys”<sup>7</sup>. It was supposedly written in to the paper by a cowboy who relates a story that, well, you simply have to read for yourself (edited for clarity):</p>
<blockquote class="blockquote">
<p>I will try and state a chapter of cow-boy life which even now brings tears to my eyes. In the spring [of 1879] a young man left his pleasant home in North Carolina and came out here to be a cow-boy. He got a job with our outfit, C. X. brand. The boys all called him “the kid from the States” and made fun of his attempt to lasso, but in a short time he got on all the rackets, and no one could throw a rope better or ride more recklessly than Tom, and he could shoot to perfection.<br>
<br>
In the spring [of 1880] we were camped on the North Canadian, taking a drove of cattle to Kansas. Tom was taken sick one night and died the next evening. How well I remember that evening!<br>
<br>
The sun was setting behind the white capped clouds, and a gentle wind fanned his pale cheeks. Not even a coyote broke the stillness with its dis-mal howl. The boys had gathered around to see their “pardner” die. Some of them might be called bad men, but none waited on him more tenderly.<br>
<br>
“Raise me up, Dave,” [Tom] said, “and let me look out once more, for when to-morrow’s sun rises”—and he burst into tears. “Boys, when I die you all must not forget me.”<br>
<br>
“Hush up, Tom,” said Tom Purdy; “you are not going to die.”<br>
<br>
“Boys,” he went on, “I hoped when I should die I might be laid in the little church-yard at home, where my sister could plant flowers over my grave; but now I must lie by the Canadian, and the wolves will howl over me. I never shall be with you again at your round-ups and camp-fires. Boys, I want you to sing the song of the Dying Cow-boy.”<br>
<br>
We gathered round him and sang it. How sad it sounded as the mournful tune rose and fell on the evening air. Just as we finished Tom sank back, dead. When the moon rose that night it looked down upon a sad group of men around a prairie grave. One wrote this on a rough board:<br>
<br>
<em>Tom Martin. Resting. May 1st, 1880.</em><br>
<br>
Men say cow-boys are rough and have no hearts, but that night showed that they had hearts. Weep, O mother, for your boy sleeps beneath the sands of the North Canadian!</p>
</blockquote>
<p>What else is there to say? The story above, though filled with too many coincidences to be true (granted, parts of it may be), is a perfect example of what American folk music is all about. An elegy, focused on the common man, who breaks out of the normalcy of American life and adopts the frontier spirit, who forges a brotherhood with the other cowboys and who dies in the harsh realities of the untamed West yearning for those at home.</p>
</section>
</section>
<section id="th-century-1" class="level1">
<h1>20th Century</h1>
<section id="title-change" class="level2">
<h2 class="anchored" data-anchor-id="title-change">Title Change</h2>
<p>Now we make our first foray into the 20th century, where we find our song published for the first time as “Bury Me Not on the Lone Prarie” in November of 1907 by William Jossey<sup>8</sup>. I can’t find much more detail on this one, but the art on the songster is quite neat.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/jossey.jpg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="315"></p>
</figure>
</div>
</section>
<section id="out-west-a-magazine-of-the-old-pacific-and-new" class="level2">
<h2 class="anchored" data-anchor-id="out-west-a-magazine-of-the-old-pacific-and-new">Out West: A Magazine of The Old Pacific and New</h2>
<p>Just after Jossey’s publication, we next find our ballad in <em>Out West</em>’s early 1908 volume, published in Los Angeles, California. The song in questions is actually part of a larger piece entitled “Songs of the Old Cattle Trails”, by Sharlot M. Hall<sup>9</sup>.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/out west.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="372"></p>
</figure>
</div>
<p>Told as a narrative, Hall blends story and song together, regaling the reader with a scene of various men (Tex, Kid, Sailor Man, and others) gathered ’round the campfire, singing songs and talking with one another. I will share where our song comes in:</p>
<blockquote class="blockquote">
<p>…The Sailor-man had been lying stretched out beyond the fire, his head on a saddle, looking up at the sky while the others sang. No one knew where the Sailor-man hailed from, but he could do things with a rope that left the rest of the outfit wondering. … The Sailor-man sat up and reached into his blanket-roll for a little old guitar, odd wreckage from some hidden past; under his fingers it began to hum the old sea song, “The Sailor’s Grave,” but the words were a rough adaptation to the life of the range. The Sailor-man had drifted up the Long Trail from Texas and down again into Arizona, and left the song in a hundred camps to mark his way. His voice had a quality of pathos, like the desert wind at night, or the faint call of the sea across the darkness.</p>
<p>“Oh! bury me not on the lone prairie!”<br>
These words came low and mournfully<br>
From the pallid lips of a youth who lay<br>
On his dying bed at the close of day. …</p>
</blockquote>
<p>Just as the last story-version that we read, this is quintessential Americana folk. Not only is the ballad telling its own story, but “storifying” the singing of the tune is just about as good as it gets.</p>
</section>
<section id="cowboy-songs-and-other-frontier-ballads" class="level2">
<h2 class="anchored" data-anchor-id="cowboy-songs-and-other-frontier-ballads">Cowboy Songs and Other Frontier Ballads</h2>
<p>Our next stop is in 1910, where for the first time, the popular tune that has come to be associated with the song is added for the first time. Published in John Lomax’s <em>Cowboy Songs and Other Frontier Ballads</em>, the folk song changed from strictly a lament to a little bit of an ode to the cowboy, romanticizing the trade as something that is representative of the American spirit.</p>
<p>Lomax, in his preface, wrote as much<sup>10</sup>:</p>
<blockquote class="blockquote">
<p>[The cowboy] has always been on the skirmish line of civilization. Restless, fearless, chivalric, elemental, he lived hard, shot quick and true, and died with his face to his foe. Still much misunderstood, he is often slandered, nearly always caricatured, both by the press and by the stage.</p>
<p>Perhaps these songs, coming direct from the cowboy’s experience, giving vent to his careless and his tender emotions, will afford future generations a truer conception of what he really was than is now possessed by those who know him only through highly colored romances. … [Though] the old-time round-up is no more, … the last figure to vanish is the cowboy, the animating spirit of the vanishing era.</p>
<p>He sits his horse easily as he rides through a wide valley, enclosed by mountains, clad in the hazy purple of coming night, with his face turned steadily down the long, long road. … Dauntless, reckless, without the unearthly purity of Sir Galahad though as gentle to a pure woman as King Arthur, he is truly a knight of the twentieth century.</p>
</blockquote>
<p>With that in mind to set the stage, let’s turn to the song itself, and mark here too the first verse:</p>
<blockquote class="blockquote">
<p>“O BURY me not on the lone prairie,”<br>
These words came low and mournfully<br>
From the pallid lips of a youth who lay<br>
On his dying bed at the close of day</p>
</blockquote>
<p>It’s almost remarkable how little the verse has changed over nigh on 100 years since the original poem. Of course, this can probably be attributed to the fact that it is the first verse, as most people (I would assume) recall the first better than the rest. However, this didn’t have to be the case, as Lomax admitted to collecting various verses and putting them together in a way that seemed fitting<sup>11</sup>.</p>
<p>That this became the default version of the song is not purely chance – the Lomaxs (John and Alan) are widely credited with being some of the first to write down many floating verses and songs which had till that point only been passed on through oral transmission.</p>
<p>After Lomax’s book, the ballad very much took off and began to be published in more outlets, as well as be recorded on the relatively new technology that was vinyl – but let’s start with the other publications.</p>
</section>
<section id="journal-of-american-folklore" class="level2">
<h2 class="anchored" data-anchor-id="journal-of-american-folklore">Journal of American Folklore</h2>
<p>In early 1912, Phillips Barry, A.M. published a piece in the journal entitled “Some Aspects of Folk-Song”, in which he defines two categories of folk ballads: those of <em>situation</em> and those of <em>introspection</em><sup>12</sup>. The former is concerned with realism of action, whereas the latter’sinterest lies with the chief actor as a personality.</p>
<p>What’s interesting here is that Barry classifies our ballad of interest as being in both camps – the current version being a ballad of situation, whereas it’s origin (“The Ocean Burial”), is more of a ballad on introspection. He also notes that the origin is more popular in the Eastern States, whereas the “modern” cowboy version is more popular elsewhere, ostensibly the West.</p>
<p>Perhaps this also can explain the difference of situation vs introspection: where the ballad is more literally applicable, it takes on a situational aspect, describing events as they happen (or purport to; see the story above from the Vermont Watchman). However, where the listeners have no frame of reference for the frontier, the ballad sounds more introspective, closer to a universal feeling rather than a specific application.</p>
</section>
<section id="sunset-the-pacific-monthly" class="level2">
<h2 class="anchored" data-anchor-id="sunset-the-pacific-monthly">Sunset (The Pacific Monthly)</h2>
<p>Later in 1912, Sunset (formerly the Pacific Monthly; Sunset magazine still exists today) issued a magazine in Portland, Oregon with our ballad inside, entitled “The Lone Prarie”<sup>13</sup>, as part of a collection of “Cow Boy Songs” by Dane Coolidge.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/sunset cover.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="406"></p>
</figure>
</div>
<p>Here as usual, is the first verse:</p>
<blockquote class="blockquote">
<p>(From the version of W. E. Hawks)</p>
<p>“Oh bury me not on the lone prairie,”<br>
These words came low and mournfully<br>
From the pallid lips of a youth who lay<br>
On his dying bed at the break of day.</p>
</blockquote>
<p>Again, we see no major deviations in the first verse, though there are some slight changes later in the ballad as written. Later in his piece, Coolidge goes on to describe the song as:</p>
<blockquote class="blockquote">
<p>[This] is another song with a history, a song which shows in its many verses the native poetry of the cow-boy and yet carries in its music the memories of other days. Many a puncher has sung it beneath the stars and added a prayer for himself, only to be buried at last on the lone prairie. … [It is] one of the best-known and best-loved of cow-boy songs, having many other verses and variants, but the music is from an old English sea-song which begins: “Oh bury me not in the deep, deep sea,” hence the reason for prairie being pronounced “prai-ree.”</p>
</blockquote>
<p>All of the writers have stressed the romanticism of cowboys, the greater West, and Americana as a whole in the ballad, and Coolidge is no exception to that rule.</p>
</section>
<section id="song-a-logue-of-america" class="level2">
<h2 class="anchored" data-anchor-id="song-a-logue-of-america">Song-a-Logue of America</h2>
<p>In 1922, Bentley Ball published his “Song-a-Logue of America”, a collection of folk and art songs, writing of folk songs and ballads<sup>14</sup>:</p>
<blockquote class="blockquote">
<p>Many of these songs are simple and artless in form, but they are true to human nature, and strike deep in the soul of man a responsive chord. Therefore it is they live and seem destined to live.</p>
</blockquote>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/songalogue.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="296"></p>
</figure>
</div>
<p>As part of this collection, Ball included various cowboy songs, of which one was “The Dying Cowboy”, an alternate title to our song of interest (recall it was also this in the Vermont Watchman). As is now our tradition, I present the first verse:</p>
<blockquote class="blockquote">
<p>“O bury me not on the lone prairie”<br>
These words came low and mournfully<br>
From the pale lips of a youth who lay<br>
On his dying bed at the close of day.</p>
</blockquote>
<p>Again, not much daylight between versions, which is remarkable. The rest of the song, however, does carry some very slight lyrical and melodic variations, though none quite so drastic as the jump from “The Ocean Buried” to now.</p>
</section>
<section id="the-american-songbag" class="level2">
<h2 class="anchored" data-anchor-id="the-american-songbag">The American Songbag</h2>
<p>Our last publication of note comes in 1927, courtesy of Carl Sandburg<sup>15</sup>. Nothing too crazy to note here, as it is a reprinting of other versions, with not much else added.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/songbag.png" class="img-fluid quarto-figure quarto-figure-center figure-img" width="469"></p>
</figure>
</div>
<p>However, I will note that this, and the previous publication, are collections of popular songs (songsters) that people could buy. This way, as recordings started taking off, they can play the music themselves, or know the lyrics, etc.</p>
</section>
</section>
<section id="thoughts" class="level1">
<h1>Thoughts</h1>
<p>As of 1927, our ballad, which we have so carefully traced over 100+ years, has certainly entered the public sphere, and is enjoyed by many from coast to coast. At this time, the ballad is available for purchase in both print and vinyl, and as such, our journey with the song’s evolution will end here.</p>
<p>Evolving from a sailor’s plea not to be lost at sea, all the way to a cowboy’s dying wish on the frontier, “Bury Me Not on the Lone Prairie” grew alongside the spirit of the American West. Each modification, re-telling, floating verse, or publication only adds to the storied past of this iconically American ballad. It’s no longer just a song, as its story of creation is just another piece of what makes it so special. Stories of the common man, of overcoming the odds, of the rough-and-tumble - all pieces which come together in this ballad to form a unique blend of American experiences.</p>
<hr>
<p>I hope you’ve enjoyed the accompanying playlist; I wanted to include a few notes on the performances and recordings of the ballad as a whole:</p>
<p>The first recording I can find is Bentley Ball (on the Columbia Label) in 1919/1920ish, which is actually our writer of the Song-a-Logue of America.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/Dying Cowboy - Bentley Ball 1920.jpg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="294"></p>
</figure>
</div>
<p>Below, find a list of some of the other recordings I found mention of<sup>16</sup>:</p>
<p>Carl T. Sprague (1926); Vernon Dalhart (1927); Pickard Family (1927); Bill Childers (1928); Jules Verne Allen (1928); Asa Martin (1932); Carter Family (1939); Cisco Houston (1952); Tex Ritter (1959); Burl Ives (1961); Johnny Cash (1966).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://connorhanan.com/posts/20250802-bury-me-not/Carl T. Sprague 1926.jpg" class="img-fluid quarto-figure quarto-figure-center figure-img" width="294"></p>
</figure>
</div>
<p>I really love the Carter Family, but I would say Sprague’s version is the best of them all – he truly sings it as a lament. The emotion comes through, and you can really imagine the hardship faced by the character of the song. The rest of the recordings are also great, but are played a little faster, so to me at least, they don’t convey the same feeling.</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Though I suggest they are the same man, per the last post↩︎</p></li>
<li id="fn2"><p><a href="https://babel.hathitrust.org/cgi/pt?id=nyp.33433002940694&amp;seq=537">Universalist Union Paper</a>↩︎</p></li>
<li id="fn3"><p><a href="https://babel.hathitrust.org/cgi/pt?id=mdp.39076000323654&amp;view=1up&amp;seq=669">The Southern Literary Messenger</a>↩︎</p></li>
<li id="fn4"><p>Including one written by a purported doctor, entitled “Differences in the Intellectual Character of the Several Varieties of the Human Race” (Harvey Lindsly, M.D.)↩︎</p></li>
<li id="fn5"><p><a href="https://levysheetmusic.mse.jhu.edu/collection/182/107">The Ocean Burial Sheet Music</a>↩︎</p></li>
<li id="fn6"><p><a href="https://chroniclingamerica.loc.gov/lccn/sn86071719/1887-06-01/ed-1/seq-7/">Vermont Watchman</a>↩︎</p></li>
<li id="fn7"><p><a href="https://chroniclingamerica.loc.gov/lccn/sn86071719/1887-06-01/ed-1/seq-7/">Vermont Watchman</a>↩︎</p></li>
<li id="fn8"><p><a href="https://www.loc.gov/pictures/item/2004682066/">Library of Congress</a>↩︎</p></li>
<li id="fn9"><p><a href="https://books.google.com/books?id=MkQLAAAAYAAJ&amp;pg=PA216#v=onepage&amp;q&amp;f=false">Out West Magazine</a>↩︎</p></li>
<li id="fn10"><p><a href="https://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1011&amp;context=englishunsllc">Cowboy Songs and Other Frontier Ballads</a>↩︎</p></li>
<li id="fn11"><p><a href="https://digitalcommons.unl.edu/cgi/viewcontent.cgi?article=1011&amp;context=englishunsllc">Cowboy Songs and Other Frontier Ballads</a>↩︎</p></li>
<li id="fn12"><p><a href="https://books.google.com/books?id=3RkpAAAAYAAJ&amp;vq=%22Bury%20Me%20Not%20on%20the%20Lone%20Prairie%22&amp;pg=PA274#v=onepage&amp;q&amp;f=false">Some Aspects of Folk Song</a>↩︎</p></li>
<li id="fn13"><p><a href="https://books.google.com/books?id=aCYLAAAAIAAJ&amp;q=%22Bury+Me+Not+on+the+Lone+Prairie%22&amp;pg=PA506#v=onepage&amp;q&amp;f=false">Sunset Magazine</a>↩︎</p></li>
<li id="fn14"><p><a href="https://archive.org/details/songalogueofamer00ball_0/page/2/mode/2up">Song-a-Logue of America</a>↩︎</p></li>
<li id="fn15"><p><a href="https://archive.org/details/americansongbag029895mbp/page/20/mode/2up">American Songbag</a>↩︎</p></li>
<li id="fn16"><p><a href="https://www.originals.be/en/originals/12409">Recordings</a>↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>Music</category>
  <category>featured</category>
  <category>History</category>
  <category>Analysis</category>
  <guid>https://connorhanan.com/posts/20250802-bury-me-not/</guid>
  <pubDate>Sat, 02 Aug 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 9: Disk Fragmenter</title>
  <link>https://connorhanan.com/posts/20250711-advent-of-code/</link>
  <description><![CDATA[ 




<p><a href="https://adventofcode.com/2024/day/9">Day 9</a>!</p>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>To begin, we need a function that will let us partition our disk based on the rules of the problem. In the input, numbers alternate between being a file or being free space, so we need to split up which are which with an odd/even split:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="44" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 43;"><span id="cb1-44"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">partition</span>(disk_map) {</span>
<span id="cb1-45">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> disk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb1-46">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// for all numbers</span></span>
<span id="cb1-47">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> disk_map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb1-48">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// even case</span></span>
<span id="cb1-49">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) {</span>
<span id="cb1-50">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// file, repeat number</span></span>
<span id="cb1-51">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> disk_map[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> j<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>( <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">String</span>(i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) )</span>
<span id="cb1-52">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//odd case</span></span>
<span id="cb1-53">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb1-54">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// spacer, print "." instead</span></span>
<span id="cb1-55">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> disk_map[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span>)</span>
<span id="cb1-56">    }</span>
<span id="cb1-57">  }</span>
<span id="cb1-58">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> disk</span>
<span id="cb1-59">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<p>Now that we are actually able to build out what the disk looks like, it gets a whole lot easier to solve, especially if we work backwards. Working forwards, we would keep expanding the string, and our indices would be off; however, by working backwards, we can insert whatever we want and still keep track of where we are in the string.</p>
<p>With that in mind, it’s really not difficult – we just map through the empty spaces, and fill with whatever needs to go there!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="69" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 68;"><span id="cb2-69">part_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-70"></span>
<span id="cb2-71">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// partition disk into array of pieces</span></span>
<span id="cb2-72">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> disk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">partition</span>(raw)</span>
<span id="cb2-73"></span>
<span id="cb2-74">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// work backwards</span></span>
<span id="cb2-75">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">--</span>) {</span>
<span id="cb2-76"></span>
<span id="cb2-77">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get index of next spacer in seq</span></span>
<span id="cb2-78">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> next_space <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">indexOf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span>)</span>
<span id="cb2-79">    </span>
<span id="cb2-80">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if next digit is a '.' or if index is below last '.' in array</span></span>
<span id="cb2-81">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (disk[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span>) {</span>
<span id="cb2-82">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">continue</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// skip</span></span>
<span id="cb2-83">    }</span>
<span id="cb2-84"></span>
<span id="cb2-85">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if no more spacers before our current position</span></span>
<span id="cb2-86">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (next_space <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> i) {</span>
<span id="cb2-87">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// exit early to avoid cycling through a bunch of continue reps</span></span>
<span id="cb2-88">    }</span>
<span id="cb2-89"></span>
<span id="cb2-90">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// replace that position with the digit we are on</span></span>
<span id="cb2-91">    disk[next_space] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> disk[i]</span>
<span id="cb2-92"></span>
<span id="cb2-93">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// replace with '.' to mark it is now empty</span></span>
<span id="cb2-94">    disk[i] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span></span>
<span id="cb2-95">    </span>
<span id="cb2-96">  }</span>
<span id="cb2-97">  </span>
<span id="cb2-98">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-99">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> nxt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span></span>
<span id="cb2-100">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">acc</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb2-101">      acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Number</span>(nxt)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>i</span>
<span id="cb2-102">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb2-103">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="110" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 109;"><span id="cb3-110">part_1</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>In part 2, we can no longer move one file (character in our string) at a time – we have to move whole blocks at once. While this may seem daunting, it’s fairly similar to what we did before, but instead of iterating through characters, we are now going to iterate through blocks.</p>
<p>To make this easier, let’s first parse the input a little more than before, and create an object with the blocks, and empty arrays as our spacers. That way, as we iterate through, we can dump the blocks into available spacers all by manipulating our arrays.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="122" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 121;"><span id="cb4-122">part_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb4-123">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> disk_map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Number</span>)</span>
<span id="cb4-124"></span>
<span id="cb4-125">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// split into blocks and empty array spacers</span></span>
<span id="cb4-126">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> disk <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb4-127">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">blocks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> disk_map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>( (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>( (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-128">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">spacers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> disk_map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>( (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>( (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> [d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> []])</span>
<span id="cb4-129">  }</span>
<span id="cb4-130">  </span>
<span id="cb4-131">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// going backwards (without doing the last one, as that will lead our array)</span></span>
<span id="cb4-132">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">--</span>) {</span>
<span id="cb4-133">    </span>
<span id="cb4-134">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// go through gaps up to the backwards run</span></span>
<span id="cb4-135">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> j <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> j<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb4-136"></span>
<span id="cb4-137">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// check if block space is &lt;= available spacer size </span></span>
<span id="cb4-138">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span>[j][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]) {</span>
<span id="cb4-139">        </span>
<span id="cb4-140">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// decrement the space counter</span></span>
<span id="cb4-141">        disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span>[j][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-=</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb4-142"></span>
<span id="cb4-143">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// fill space with block</span></span>
<span id="cb4-144">        disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span>[j][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>( </span>
<span id="cb4-145">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) </span>
<span id="cb4-146">        )</span>
<span id="cb4-147"></span>
<span id="cb4-148">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// replace block empty char</span></span>
<span id="cb4-149">        disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span></span>
<span id="cb4-150"></span>
<span id="cb4-151">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// exit because slot found for block</span></span>
<span id="cb4-152">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">break</span></span>
<span id="cb4-153">      } <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// no else statement since we want to leave as-is if no space</span></span>
<span id="cb4-154">    }</span>
<span id="cb4-155">  }</span>
<span id="cb4-156"></span>
<span id="cb4-157">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// output arr</span></span>
<span id="cb4-158">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> defrag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb4-159"></span>
<span id="cb4-160">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// build output arr</span></span>
<span id="cb4-161">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb4-162"></span>
<span id="cb4-163">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// push block</span></span>
<span id="cb4-164">    defrag<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb4-165">               <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">blocks</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) )</span>
<span id="cb4-166"></span>
<span id="cb4-167">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// push spacer fill</span></span>
<span id="cb4-168">    defrag<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb4-169"></span>
<span id="cb4-170">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// push remaining unfilled spacers</span></span>
<span id="cb4-171">    defrag<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(disk<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">spacers</span>[i][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>) )</span>
<span id="cb4-172">    </span>
<span id="cb4-173">  }</span>
<span id="cb4-174"></span>
<span id="cb4-175">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> defrag<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> nxt <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb4-176">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="183" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 182;"><span id="cb5-183">part_2</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="expression">

</div>
</div>
</div>
<p>⭐</p>
<hr>
<p>The hardest part here was deciding to work backwards through the disk. Initially, I took a recursive-heavy approach to work forwards, and that became a pain fast. The good news is, other days benefit from this reversed approach, so it was a good reminder to keep it as an option.</p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20250711-advent-of-code/</guid>
  <pubDate>Fri, 11 Jul 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 8: Resonant Collinearity</title>
  <link>https://connorhanan.com/posts/20250710-advent-of-code/</link>
  <description><![CDATA[ 




<p>I’m back with more 2024 Advent of Code! Back in December, I solved about 18/25, though never copied them over from my Observable Notebooks. It’s about time I post them here, so I’ll be both catching up on old days as well as working to finish out the rest of the 2024 puzzles.</p>
<p>With further ado, let’s get started with <a href="https://adventofcode.com/2024/day/8">day 8</a>!</p>
<p>First, let’s parse the input – this is fairly standard fare for Advent of Code. Grid parsing is probably one of the most common problem setups, so it’s nothing a little regex can’t fix. However, based on the problem (matching antennae based on matching character sets), I chose to use a <code>Map</code> object type. It could have easily been done with regular objects, but why not try something new?</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="105" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 104;"><span id="cb1-105">input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-106">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// split on newlines and separate each char</span></span>
<span id="cb1-107">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> parsed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>))</span>
<span id="cb1-108"></span>
<span id="cb1-109">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// create map of each antenna type</span></span>
<span id="cb1-110">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> antennae <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> parsed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-111">    nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>((elem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-112">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (elem <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span>) {</span>
<span id="cb1-113">        acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>( </span>
<span id="cb1-114">            elem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-115">            [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(elem) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">row</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">col</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> col}] </span>
<span id="cb1-116">        )</span>
<span id="cb1-117">      }</span>
<span id="cb1-118">    })</span>
<span id="cb1-119">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> acc</span>
<span id="cb1-120">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>())</span>
<span id="cb1-121"></span>
<span id="cb1-122">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// return map and general grid info</span></span>
<span id="cb1-123">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb1-124">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">antennae</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> antennae<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-125">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">nrow</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> parsed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-126">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">ncol</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> parsed[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-127">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> parsed</span>
<span id="cb1-128">  }</span>
<span id="cb1-129">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>In part 1, we need to find all the possible antinode locations, which are derived from pairs of matching antennae sets. To do so, we’ll need to create a little bit of infrastructure below:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="139" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 138;"><span id="cb2-139"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairwise</span>(arrays<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dupes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>) {</span>
<span id="cb2-140">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// recursive so we need a short circuit</span></span>
<span id="cb2-141">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (arrays<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> []</span>
<span id="cb2-142">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// extract matching item</span></span>
<span id="cb2-143">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [first<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>rest] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> arrays</span>
<span id="cb2-144">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get all other pairs recursively</span></span>
<span id="cb2-145">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> end <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairwise</span>(rest)</span>
<span id="cb2-146">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if we allow dupes, nest them together</span></span>
<span id="cb2-147">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> other <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> end<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(([first2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rest2]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-148">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> dupes</span>
<span id="cb2-149">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> [first2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [first<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>rest2]]</span>
<span id="cb2-150">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [first2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>rest2]]</span>
<span id="cb2-151">  }) </span>
<span id="cb2-152">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [[first<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> rest]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>other]</span>
<span id="cb2-153">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<p>Above, we created a function to create all pairwise matches from an array. Using this, we can find all the locations of antinodes, since the new ones must be on the same plane as the existing antennae.</p>
<p>Once we have our pairs, then we actually have to find the possible locations. Luckily for us, this is quite simple, since we can use the good ol’ slope formula to calculate the possible positions.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="163" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 162;"><span id="cb3-163"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_antinodes</span>(a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> n) {</span>
<span id="cb3-164">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// y2 - y1 / x2 - x1</span></span>
<span id="cb3-165">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> slope <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [ a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ]</span>
<span id="cb3-166">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// return the new positions in both directions</span></span>
<span id="cb3-167">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [</span>
<span id="cb3-168">      [ a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>slope[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> a[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>slope[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-169">      [ b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>slope[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>slope[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ]</span>
<span id="cb3-170">    ]</span>
<span id="cb3-171">  }</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<p>With these in hand, the solution becomes fairly trivial; all we need to do now is iterate through our input Map to:</p>
<ol type="1">
<li>Get all the pairwise matches of antennae in each group</li>
<li>Calculate the slope of each sub-pair</li>
<li>Count all unique antinode locations</li>
</ol>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="183" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 182;"><span id="cb4-183">part_1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb4-184"></span>
<span id="cb4-185">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> antinodes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb4-186"></span>
<span id="cb4-187">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// for each set</span></span>
<span id="cb4-188">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">antennae</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(antenna_set <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-189">    antinodes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(</span>
<span id="cb4-190">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get all pairwise matches</span></span>
<span id="cb4-191">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairwise</span>(antenna_set<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(([ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pair]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-192">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pair</span>
<span id="cb4-193">            <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get the possible locations for each pair</span></span>
<span id="cb4-194">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_antinodes</span>( </span>
<span id="cb4-195">                [ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-196">                [d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-197">                <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> )</span>
<span id="cb4-198">            )</span>
<span id="cb4-199">          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// remove any outside grid boundaries</span></span>
<span id="cb4-200">      })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(([row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> </span>
<span id="cb4-201">                row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb4-202">                row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb4-203">                col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb4-204">                col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol</span>            </span>
<span id="cb4-205">      )</span>
<span id="cb4-206">    )</span>
<span id="cb4-207">  })</span>
<span id="cb4-208"></span>
<span id="cb4-209">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(</span>
<span id="cb4-210">    antinodes</span>
<span id="cb4-211">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()</span>
<span id="cb4-212">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// combine coords with left shift and bitwise OR</span></span>
<span id="cb4-213">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb4-214">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span></span>
<span id="cb4-215"></span>
<span id="cb4-216">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb5" data-startfrom="223" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 222;"><span id="cb5-223">part_1</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="expression">

</div>
</div>
</div>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>In part 2, the difference is that antinodes may be more than 1-step away from existing antennae. This makes it fairly easy, since we can just extend our functions from before to look at a longer range!</p>
<p>With a quick tweak to <code>n</code> in our <code>find_antinodes()</code> function (by using number of rows we can be sure that we will exceed the bounds for each antennae set in both directions), we can easily cross this day off our list!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="237" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 236;"><span id="cb6-237">part_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb6-238">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> antinodes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []</span>
<span id="cb6-239">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get array of row count to iterate across as N</span></span>
<span id="cb6-240">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> n_mults <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb6-241">  </span>
<span id="cb6-242">  input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">antennae</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(antenna_set <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-243">    antinodes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>(</span>
<span id="cb6-244">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// same as before</span></span>
<span id="cb6-245">      <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pairwise</span>(antenna_set<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(([ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pair]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-246">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> n_mults<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-247">          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// map across all N distances</span></span>
<span id="cb6-248">          <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pair<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">find_antinodes</span>( [ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ref<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> n ))</span>
<span id="cb6-249">        })</span>
<span id="cb6-250">          <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// same filter as before to check boundaries</span></span>
<span id="cb6-251">      })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(([row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col]) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> </span>
<span id="cb6-252">                  row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb6-253">                  row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nrow</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb6-254">                  col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span></span>
<span id="cb6-255">                  col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">ncol</span>            </span>
<span id="cb6-256">      )</span>
<span id="cb6-257">    )</span>
<span id="cb6-258">  })</span>
<span id="cb6-259"></span>
<span id="cb6-260">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// left shift and bitwise OR</span></span>
<span id="cb6-261">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> all_antinode <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> antinodes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb6-262">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// do the same for antennae positions, since they count in this part</span></span>
<span id="cb6-263">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> all_antennae <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">antennae</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">entries</span>()]</span>
<span id="cb6-264">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])</span>
<span id="cb6-265">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()</span>
<span id="cb6-266">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">row</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">col</span>)</span>
<span id="cb6-267"></span>
<span id="cb6-268">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// count unique antinodes AND antennae</span></span>
<span id="cb6-269">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>( [ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>all_antinode<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>all_antennae ] )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span></span>
<span id="cb6-270">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb7" data-startfrom="277" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 276;"><span id="cb7-277">part_2</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="expression">

</div>
</div>
</div>
<p>⭐</p>
<hr>
<p>Pretty fun day! I always enjoy a bit of regex, and some classic math to boot.</p>
<p>I’m looking forward to catching up on a bunch of these AoC days, so stay tuned for more soon!</p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20250710-advent-of-code/</guid>
  <pubDate>Thu, 10 Jul 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>A Visualization About Nothing</title>
  <link>https://connorhanan.com/posts/20250629-seinfeld-relationships/</link>
  <description><![CDATA[ 




<p>Across all of Seinfeld, we see many relationships develop between the main four characters and many others. Explore the visualisation below to view all the many friends, family, girlfriends/boyfriends, and foes of the series!</p>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
<span class="screen-reader-only">Tip</span>Interactivity
</div>
</div>
<div class="callout-body-container callout-body">
<p>Many of the peripheral characters have relationships with multiple of the main characters (ex: Morty Seinfeld is obviously Jerry’s father, and also goes into business with Kramer) – which leads to very tight clusters.</p>
<p>Click and drag the centroids apart for better visibility.</p>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="29" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 28;"><span id="cb1-29">relationship_chart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-30">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">800</span></span>
<span id="cb1-31">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1200</span></span>
<span id="cb1-32"></span>
<span id="cb1-33">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scaleOrdinal</span>()</span>
<span id="cb1-34">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">domain</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb1-35">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color</span>))</span>
<span id="cb1-36"></span>
<span id="cb1-37">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> links <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> relationships<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">From</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">To</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type</span>}))</span>
<span id="cb1-38">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> nodes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> relationships<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>d}))</span>
<span id="cb1-39"></span>
<span id="cb1-40">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sim <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceSimulation</span>(nodes)</span>
<span id="cb1-41">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"link"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceLink</span>(links)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">id</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distance</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>))</span>
<span id="cb1-42">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"charge"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceManyBody</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>))</span>
<span id="cb1-43">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collide"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceCollide</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">radius</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span>
<span id="cb1-44">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceCenter</span>( width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>))</span>
<span id="cb1-45">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tick"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ticked)</span>
<span id="cb1-46"></span>
<span id="cb1-47">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"svg"</span>)</span>
<span id="cb1-48">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width)</span>
<span id="cb1-49">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height)</span>
<span id="cb1-50">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viewBox"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height])</span>
<span id="cb1-51">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"style"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max-width: 100%; height: auto;"</span>)</span>
<span id="cb1-52"></span>
<span id="cb1-53">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> link <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-54">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#999"</span>)</span>
<span id="cb1-55">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-opacity"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)</span>
<span id="cb1-56">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>()</span>
<span id="cb1-57">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(links)</span>
<span id="cb1-58">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>)</span>
<span id="cb1-59">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>)</span>
<span id="cb1-60">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb1-61"></span>
<span id="cb1-62">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> globs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-63">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#fff"</span>)</span>
<span id="cb1-64">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>)</span>
<span id="cb1-65">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-66">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(nodes)</span>
<span id="cb1-67">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter</span>()</span>
<span id="cb1-68">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-69"></span>
<span id="cb1-70">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> node <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>)</span>
<span id="cb1-71">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb1-72"></span>
<span id="cb1-73">  node<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>)</span>
<span id="cb1-74">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)`</span>)</span>
<span id="cb1-75"></span>
<span id="cb1-76">  globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb1-77">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span>)</span>
<span id="cb1-78">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1em"</span>)</span>
<span id="cb1-79">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb1-80">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>)</span>
<span id="cb1-81">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb1-82">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12px"</span>)</span>
<span id="cb1-83">  </span>
<span id="cb1-84">  globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drag</span>()</span>
<span id="cb1-85">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragstarted)</span>
<span id="cb1-86">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drag"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragged)</span>
<span id="cb1-87">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"end"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragended))</span>
<span id="cb1-88"></span>
<span id="cb1-89">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendDots <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-90">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendDots"</span>)</span>
<span id="cb1-91">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb1-92">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>)</span>
<span id="cb1-93">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">170</span>)</span>
<span id="cb1-94">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb1-95">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb1-96">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color</span>(d))</span>
<span id="cb1-97"></span>
<span id="cb1-98">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendText <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-99">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendText"</span>)</span>
<span id="cb1-100">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb1-101">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb1-102">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">160</span>)</span>
<span id="cb1-103">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb1-104">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb1-105">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alignment-baseline"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb1-106">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d)</span>
<span id="cb1-107"></span>
<span id="cb1-108">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendTitle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb1-109">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendTitle"</span>)</span>
<span id="cb1-110">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relationship Types"</span>])</span>
<span id="cb1-111">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb1-112">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">190</span>)</span>
<span id="cb1-113">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">155</span>)</span>
<span id="cb1-114">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relationship Types"</span>)</span>
<span id="cb1-115">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb1-116">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-decoration"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"underline"</span>)</span>
<span id="cb1-117">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alignment-baseline"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb1-118"></span>
<span id="cb1-119">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ticked</span>() {</span>
<span id="cb1-120">    globs</span>
<span id="cb1-121">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"transform"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`translate(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">, </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)`</span>)</span>
<span id="cb1-122">    </span>
<span id="cb1-123">    link</span>
<span id="cb1-124">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span>)</span>
<span id="cb1-125">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span>)</span>
<span id="cb1-126">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span>)</span>
<span id="cb1-127">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span>)</span>
<span id="cb1-128"></span>
<span id="cb1-129">  }</span>
<span id="cb1-130"></span>
<span id="cb1-131">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragstarted</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb1-132">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">active</span>) sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alphaTarget</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">restart</span>()</span>
<span id="cb1-133">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span></span>
<span id="cb1-134">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span></span>
<span id="cb1-135">  }</span>
<span id="cb1-136"></span>
<span id="cb1-137">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragged</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb1-138">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span></span>
<span id="cb1-139">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span></span>
<span id="cb1-140">  }</span>
<span id="cb1-141"></span>
<span id="cb1-142">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragended</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb1-143">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">active</span>) sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alphaTarget</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-144">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span></span>
<span id="cb1-145">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span></span>
<span id="cb1-146">  }</span>
<span id="cb1-147"></span>
<span id="cb1-148">  invalidation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">then</span>(() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>())</span>
<span id="cb1-149">  </span>
<span id="cb1-150">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">node</span>()</span>
<span id="cb1-151"></span>
<span id="cb1-152">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<p>Filter the visualization below:</p>
<div class="cell">
<details class="code-fold hidden">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="159" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 158;"><span id="cb2-159">viewof characters <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb2-160">  lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">characters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-161">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">characters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-162">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;b&gt;Main Characters&lt;/b&gt;`</span></span>
<span id="cb2-163">  }</span>
<span id="cb2-164">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold hidden">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb3" data-startfrom="169" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 168;"><span id="cb3-169">viewof types <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb3-170">  lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb3-171">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb3-172">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;b&gt;Relationship Types&lt;/b&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb3-173">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">format</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;span style="text-transform: capitalize; border-bottom: solid 2px </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">; margin-bottom: -2px;"&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb3-174">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<hr>
<p>I took some inspiration from other visualizations<sup>1</sup>, but I really wanted to find a way to make it more interactive and dynamic. I’ve been slowly feeling my way through D3, so I figured it would be a great way to learn some of the <code>d3.force*</code> modules.</p>
<p>Unfortunately, due to how tightly clustered these relationships are around the main characters, I did have to remove some links entirely which had no connection to the main four (ex: Micky Abbot’s mother). Due to the math of the forces involved, these disconnected nodes were being shot out into the void outside the canvas as soon as their connection to the main characters disappeared, rendering them pointless. From here, I’d explore different ways to dynamically render the text, as I’m not entirely satisfied with it – perhaps there is a way to check for overlaps, then only print the text that belongs to the larger node?</p>
<p>Seinfeld is probably my all-time favorite series, so this was a lot of fun to make. While going through this project, I was hemming and hawing about which episode was my absolute favorite. In doing so, I couldn’t decide between two: The Stake Out and The Marine Biologist. The latter is as classic as it gets; I’m sure this is on most everyone’s lists. However, I think The Stake Out is a slept on episode for a few reasons:</p>
<ol type="1">
<li>Though the second episode of the series, it’s the first with Elaine</li>
<li>Jerry’s parents are also in it for the first time, with Liz Sheridan as Helen and Phil Bruns as Morty (the only one)</li>
<li>George’s oft-used persona of the importer-exporter Art Vandelay is created</li>
</ol>
<p>If you’d like to explore the code behind the visualisation, continue below to the Appendix.</p>
<p>-CH</p>
<p><br></p>
<section id="appendix" class="level2">
<h2 class="anchored" data-anchor-id="appendix">Appendix</h2>
<div class="cell">
<details class="code-fold">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="200" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 199;"><span id="cb4-200"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Read in data and parse</span></span>
<span id="cb4-201">relationships <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb4-202">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> raw <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">await</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">FileAttachment</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"seinfeld_relationships@7.json"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">json</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-203">      counts <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Object</span>()</span>
<span id="cb4-204">  raw <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (characters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">To</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> characters<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">From</span>)) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> (types<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type</span>)))</span>
<span id="cb4-205">  raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">From</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-206">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> counts[d] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> counts[d]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> counts[d] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span></span>
<span id="cb4-207">  })</span>
<span id="cb4-208">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb4-209">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">nodes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">From</span>)))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">id</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> counts[d]}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb4-210">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">links</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> raw</span>
<span id="cb4-211">  }</span>
<span id="cb4-212">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<details class="code-fold">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="216" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 215;"><span id="cb5-216"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Build lookup for values</span></span>
<span id="cb5-217">lookups <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> ({</span>
<span id="cb5-218">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb5-219">    {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Friend"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2ca02c"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-220">    {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Family"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#d62728"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-221">    {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Antagonistic"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#ff7f0e"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-222">    {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Romantic"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#1f77b4"</span>}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-223">    {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Professional"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#9467bd"</span>}</span>
<span id="cb5-224">  ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb5-225">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">characters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Jerry Seinfeld"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"George Costanza"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Elaine Benes"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cosmo Kramer"</span>]</span>
<span id="cb5-226">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell" data-eval="false">
<details class="code-fold">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="231" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 230;"><span id="cb6-231"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Create character selection</span></span>
<span id="cb6-232">viewof characters <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb6-233">  lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">characters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb6-234">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">characters</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-235">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;b&gt;Main Characters&lt;/b&gt;`</span></span>
<span id="cb6-236">  }</span>
<span id="cb6-237">)</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell" data-eval="false">
<details class="code-fold">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" data-startfrom="242" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 241;"><span id="cb7-242"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Create relationship type selection</span></span>
<span id="cb7-243">viewof types <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">checkbox</span>(</span>
<span id="cb7-244">  lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb7-245">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb7-246">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;b&gt;Relationship Types&lt;/b&gt;`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb7-247">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">format</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">html</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`&lt;span style="text-transform: capitalize; border-bottom: solid 2px </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> x)[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">; margin-bottom: -2px;"&gt;</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>x<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span></span>
<span id="cb7-248">})</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell" data-eval="false">
<details class="code-fold">
<summary>Show the Code</summary>
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" data-startfrom="253" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 252;"><span id="cb8-253"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Build D3 chart</span></span>
<span id="cb8-254">relationship_chart <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb8-255">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">800</span></span>
<span id="cb8-256">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1200</span></span>
<span id="cb8-257"></span>
<span id="cb8-258">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> color <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">scaleOrdinal</span>()</span>
<span id="cb8-259">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">domain</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb8-260">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">color</span>))</span>
<span id="cb8-261"></span>
<span id="cb8-262">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> links <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> relationships<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">links</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">From</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">To</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">Type</span>}))</span>
<span id="cb8-263">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> nodes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> relationships<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">nodes</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ({<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>d}))</span>
<span id="cb8-264"></span>
<span id="cb8-265">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sim <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceSimulation</span>(nodes)</span>
<span id="cb8-266">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"link"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceLink</span>(links)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">id</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">distance</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>))</span>
<span id="cb8-267">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"charge"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceManyBody</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>))</span>
<span id="cb8-268">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"collide"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceCollide</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">radius</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>))</span>
<span id="cb8-269">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">force</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"center"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forceCenter</span>( width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">strength</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>))</span>
<span id="cb8-270">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"tick"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ticked)</span>
<span id="cb8-271"></span>
<span id="cb8-272">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> svg <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">create</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"svg"</span>)</span>
<span id="cb8-273">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width)</span>
<span id="cb8-274">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"height"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height)</span>
<span id="cb8-275">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"viewBox"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height])</span>
<span id="cb8-276">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"style"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"max-width: 100%; height: auto;"</span>)</span>
<span id="cb8-277"></span>
<span id="cb8-278">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> link <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-279">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#999"</span>)</span>
<span id="cb8-280">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-opacity"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.6</span>)</span>
<span id="cb8-281">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>()</span>
<span id="cb8-282">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(links)</span>
<span id="cb8-283">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"line"</span>)</span>
<span id="cb8-284">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>)</span>
<span id="cb8-285">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb8-286"></span>
<span id="cb8-287">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> globs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-288">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#fff"</span>)</span>
<span id="cb8-289">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.1</span>)</span>
<span id="cb8-290">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-291">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(nodes)</span>
<span id="cb8-292">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">enter</span>()</span>
<span id="cb8-293">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-294"></span>
<span id="cb8-295">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> node <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>)</span>
<span id="cb8-296">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sqrt</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>))</span>
<span id="cb8-297"></span>
<span id="cb8-298">  node<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"title"</span>)</span>
<span id="cb8-299">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> (</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)`</span>)</span>
<span id="cb8-300"></span>
<span id="cb8-301">  globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb8-302">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">id</span>)</span>
<span id="cb8-303">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"dy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"-1em"</span>)</span>
<span id="cb8-304">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb8-305">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"black"</span>)</span>
<span id="cb8-306">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"stroke-width"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)</span>
<span id="cb8-307">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"font-size"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"12px"</span>)</span>
<span id="cb8-308">  </span>
<span id="cb8-309">  globs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">call</span>(d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">drag</span>()</span>
<span id="cb8-310">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragstarted)</span>
<span id="cb8-311">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"drag"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragged)</span>
<span id="cb8-312">           <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">on</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"end"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dragended))</span>
<span id="cb8-313"></span>
<span id="cb8-314">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendDots <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-315">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendDots"</span>)</span>
<span id="cb8-316">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb8-317">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"circle"</span>)</span>
<span id="cb8-318">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cx"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">170</span>)</span>
<span id="cb8-319">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cy"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb8-320">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"r"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)</span>
<span id="cb8-321">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"fill"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">color</span>(d))</span>
<span id="cb8-322"></span>
<span id="cb8-323">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendText <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-324">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendText"</span>)</span>
<span id="cb8-325">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>(lookups<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>))</span>
<span id="cb8-326">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb8-327">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">160</span>)</span>
<span id="cb8-328">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">20</span>)</span>
<span id="cb8-329">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb8-330">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alignment-baseline"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb8-331">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d)</span>
<span id="cb8-332"></span>
<span id="cb8-333">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> legendTitle <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">append</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"g"</span>)</span>
<span id="cb8-334">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">selectAll</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"legendTitle"</span>)</span>
<span id="cb8-335">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">data</span>([<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relationship Types"</span>])</span>
<span id="cb8-336">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text"</span>)</span>
<span id="cb8-337">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> width <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">190</span>)</span>
<span id="cb8-338">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> height <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">155</span>)</span>
<span id="cb8-339">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Relationship Types"</span>)</span>
<span id="cb8-340">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-anchor"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"left"</span>)</span>
<span id="cb8-341">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"text-decoration"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"underline"</span>)</span>
<span id="cb8-342">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">style</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"alignment-baseline"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"middle"</span>)</span>
<span id="cb8-343"></span>
<span id="cb8-344">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ticked</span>() {</span>
<span id="cb8-345">    globs</span>
<span id="cb8-346">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"transform"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`translate(</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">, </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">)`</span>)</span>
<span id="cb8-347">    </span>
<span id="cb8-348">    link</span>
<span id="cb8-349">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span>)</span>
<span id="cb8-350">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y1"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">source</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span>)</span>
<span id="cb8-351">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span>)</span>
<span id="cb8-352">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">attr</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y2"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span>)</span>
<span id="cb8-353"></span>
<span id="cb8-354">  }</span>
<span id="cb8-355"></span>
<span id="cb8-356">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragstarted</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb8-357">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">active</span>) sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alphaTarget</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">restart</span>()</span>
<span id="cb8-358">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span></span>
<span id="cb8-359">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span></span>
<span id="cb8-360">  }</span>
<span id="cb8-361"></span>
<span id="cb8-362">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragged</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb8-363">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">x</span></span>
<span id="cb8-364">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">y</span></span>
<span id="cb8-365">  }</span>
<span id="cb8-366"></span>
<span id="cb8-367">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dragended</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span>) {</span>
<span id="cb8-368">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">active</span>) sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">alphaTarget</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb8-369">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fx</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span></span>
<span id="cb8-370">    <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">event</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">subject</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">fy</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">null</span></span>
<span id="cb8-371">  }</span>
<span id="cb8-372"></span>
<span id="cb8-373">  invalidation<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">then</span>(() <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> sim<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stop</span>())</span>
<span id="cb8-374">  </span>
<span id="cb8-375">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> svg<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">node</span>()</span>
<span id="cb8-376"></span>
<span id="cb8-377">}</span></code></pre></div></div>
</details>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>https://flowingdata.com/2009/09/02/the-world-of-seinfeld/↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>OJS</category>
  <category>TV</category>
  <category>Analysis</category>
  <guid>https://connorhanan.com/posts/20250629-seinfeld-relationships/</guid>
  <pubDate>Sun, 29 Jun 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Exploring Lambda Calculus (Part 3)</title>
  <link>https://connorhanan.com/posts/20250615-lambda-calculus/</link>
  <description><![CDATA[ 




<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="19" data-source-offset="-0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 18;"><span id="cb1-19">TRUE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a</span>
<span id="cb1-20">FALSE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b</span>
<span id="cb1-21">N0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a</span>
<span id="cb1-22">N1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)</span>
<span id="cb1-23">N2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a))</span>
<span id="cb1-24">N3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)))</span>
<span id="cb1-25">N4 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a))))</span>
<span id="cb1-26">SUCC <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f)(x))</span>
<span id="cb1-27">PLUS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(f)(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f)(x))</span>
<span id="cb1-28">MULT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f))</span>
<span id="cb1-29">POW <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">e</span>(b)</span>
<span id="cb1-30">lambda_to_js <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (bool) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bool</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>)(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span>)</span>
<span id="cb1-31">lambda_to_int <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (int) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-32">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">int</span>(x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-33">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-9" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-10" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-1-13" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<section id="recap" class="level2">
<h2 class="anchored" data-anchor-id="recap">Recap</h2>
<p>Last time, we left off with our second truth table exploring Church Numerals and some incrementing mathematical operations. If you missed it, <a href="../../posts/20250520-lambda-calculus/index.html">catch up here</a> before moving on to this post’s topic: data structures and some new mathematical operations. <sup>1</sup></p>
</section>
<section id="data-structures" class="level2">
<h2 class="anchored" data-anchor-id="data-structures">Data Structures</h2>
<p>Now that we can represent numbers as functions, and critically, operate on them doing basic arithmetic, we need to find a way to store values for reference later. For example, the most basic of data structures is the <em>n-tuple</em>, which is an ordered list of <em>n</em> values.</p>
<p>Storing values gets pretty tricky in lambda calculus – remember, everything is a function, and functions naturally want to execute their operations on their arguments. However, we can get around this by using a form of encapsulation.</p>
<p>Our outer function will wrap the arguments, doing nothing with them. Then, when we need a value, we pass an successor function to the stored value, finally executing on it, and retrieving the real value. Straightforward? Not in the least.</p>
<p>Let’s make some functions, then walk through them on the other side:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="52" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 51;"><span id="cb2-52">BUILD_3TUPLE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)(b)(c)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="56" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 55;"><span id="cb3-56">GET_A <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="60" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 59;"><span id="cb4-60">GET_B <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="64" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 63;"><span id="cb5-64">GET_C <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> c)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<p>In the above <code>BUILD_3TUPLE</code>, can you decipher which part is our “tuple”? Indeed, it is the portion <code>f =&gt; f(a)(b)(c)</code>! This is because the function <em>f</em> doesn’t actually do anything, it’s just going to hold on to the tuple <em>(a,b,c)</em> until we need them.</p>
<p>Once we do need them, it’s time to call our accessor functions! These <code>GET_*</code> functions all do the same thing: retrieve the positional value by using <em>t</em> to unwrap the tuple, and only return the position we need.</p>
<p>Let’s try an example, where we want to extract the middle value from the tuple (0, 1, 2).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="74" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 73;"><span id="cb6-74">{</span>
<span id="cb6-75">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> tuple <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">BUILD_3TUPLE</span>(N0)(N1)(N2)</span>
<span id="cb6-76">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> b_val <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">GET_B</span>(tuple)</span>
<span id="cb6-77">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( b_val )</span>
<span id="cb6-78">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="expression">

</div>
</div>
</div>
<p>Using this idea, we can now implement a <em>decrementing</em> function – a procedure that seems fairly trivial, considering we have it’s counterpart already defined. However, it’s not so straight forward as it appears.</p>
<p>Incrementing something is easy with functions; if you recall, we just wrap another layer around the outside. However, to get the predecessor, you would have to unwrap a layer of the nested functions, which we have no great way of doing.</p>
<p>Instead, we’ll have to keep values “in memory”. Let’s start by defining a 2-tuple (PAIR), and the needed accessors:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" data-startfrom="88" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 87;"><span id="cb7-88">PAIR <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)(b)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" data-startfrom="92" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 91;"><span id="cb8-92">FIRST <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" data-startfrom="96" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 95;"><span id="cb9-96">SECOND <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> t <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">t</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<p>With this in hand, we can create a function known as <em>shift-and-increment</em> (or <em>phi</em>), which takes a pair of numbers and returns a new pair of the second number and its increment: <code>(a, b) =&gt; (b, b+1)</code>.</p>
<p>There can be many uses for this (looking at you, linked lists), but for now, we will use the concept to achieve our decrement function. The <em>phi</em> of a pair will always contain it’s predecessor, so we can back our way into coming up with the previous number:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" data-startfrom="104" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 103;"><span id="cb10-104">PHI <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> p <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PAIR</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SECOND</span>(p) )( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SUCC</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SECOND</span>(p) ) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="declaration">

</div>
</div>
</div>
<p>Above, we are forming a <code>PAIR</code> based on <em>p</em> (prior pair). This means that we want the second element of <em>p</em> to become the first of <em>PHI</em>: (<code>SECOND(p)</code>), and the increment/successor of the second element of <em>p</em> as the second element of <em>PHI</em>: (<code>SUCC(SECOND(p))</code>).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" data-startfrom="110" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 109;"><span id="cb11-110">PRED <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">FIRST</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(PHI)( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PAIR</span>(N0)(N0) ) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" data-startfrom="114" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 113;"><span id="cb12-114">SUB <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(PRED)(m)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="declaration">

</div>
</div>
</div>
<p>In the above, we are implementing <code>PRED</code> and then <code>SUB</code>, which utilizes <code>PRED</code> in its underlying logic.</p>
<p><code>PRED</code> is our decrement function, which takes a 2-tuple and starts counting up to it from (0,0). Once we hit our target number in the second position, we can then return the number in the first position, since we know that should be one less.</p>
<p><code>SUB</code> takes this farther by adding framework around <code>PRED</code>. Specifically, we are applying <code>PRED</code> <em>n</em> times to <em>m</em>. In other words, starting at <em>m</em>, we are then subtracting 1 from it <em>n</em> times. I will note this is not an efficient implementation whatsoever – for each step, we have to count up from 0 to get the prior number. It works fine here since our numbers are low, but if you imagine doing 1000-999, or something even more drastic, you can imagine how long it would take.</p>
<p>Using this idea, we can use a neat trick of the number functions themselves to check whether the number is 0 or not. Remember, a number is just the number of nested functions are in a stack - so 0 is represented by no functions in the stack. This is helpful because we can now check how many functions are called: any number of times &gt; 1 means it is not equal to 0, no calls means it is:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" data-startfrom="126" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 125;"><span id="cb13-126">ISZERO <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> FALSE)(TRUE)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-13" data-nodetype="declaration">

</div>
</div>
</div>
<p>Similarly, we can take advantage of a feature of subtraction to find if a value is less than or equal to another. Technically, since none of our numbers are signed (how would you even add a sign based on nested functions???), we can just check if the result of subtracting the terms is 0. It’s ambiguous, yes (0 could mean the value is negative or 0), but in this case, we can use that “feature” to determine our inequality:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" data-startfrom="132" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 131;"><span id="cb14-132">LEQ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ISZERO</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SUB</span>(m)(n) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-14" data-nodetype="declaration">

</div>
</div>
</div>
<p>With these brand new operations in hand, let’s update our truth table from last post with our newest functions:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" data-startfrom="138" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 137;"><span id="cb15-138">part_3_math_table <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb15-139">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> output <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb15-140">  </span>
<span id="cb15-141">  [N0<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N4]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {    </span>
<span id="cb15-142">    output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb15-143">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>(a)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-144">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">succ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SUCC</span>(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-145">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">plus</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PLUS</span>(a)(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-146">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">mult</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">MULT</span>(a)(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-147">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">pow</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">POW</span>(a)(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-148">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">pred</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PRED</span>(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-149">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"sub(2)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SUB</span>(a)(N2) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-150">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">iszero</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ISZERO</span>(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb15-151">      <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"leq(2)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">LEQ</span>(a)(N2) )</span>
<span id="cb15-152">    })</span>
<span id="cb15-153">  })</span>
<span id="cb15-154"></span>
<span id="cb15-155">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> output</span>
<span id="cb15-156">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-15" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" data-startfrom="160" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 159;"><span id="cb16-160">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(part_3_math_table)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-16" data-nodetype="expression">

</div>
</div>
</div>
<hr>
<p>In the immortal words of Bill and Ted, excellent! We’ve got some basic data structures and even more operations built out.</p>
<p>I’m not yet sure if I’ll continue this series past this point, as I feel like I have a solid feel for lambda calculus at this point.</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Inspired by <a href="http://hexatlas.com/entries/7">Eric Wastl’s</a> and <a href="https://www.driverlesscrocodile.com/tools-and-techniques/lambda-calculus-for-people-a-step-behind-me-2-boolean-logic/">Stuart Patience’s</a> posts.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20250615-lambda-calculus/</guid>
  <pubDate>Sun, 15 Jun 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Exploring Lambda Calculus (Part 2)</title>
  <link>https://connorhanan.com/posts/20250520-lambda-calculus/</link>
  <description><![CDATA[ 




<section id="recap" class="level2">
<h2 class="anchored" data-anchor-id="recap">Recap</h2>
<p>Last time, we left off with our first truth table exploring all the logic gate test permutations. If you missed it, <a href="../../posts/20250430-lambda-calculus/index.html">catch up here</a> before moving on to this post’s topic: math and simple calculation. <sup>1</sup></p>
</section>
<section id="church-numerals" class="level2">
<h2 class="anchored" data-anchor-id="church-numerals">Church Numerals</h2>
<p>Now that we have basic operations and logic gates, we need to advance past 1’s and 0’s to be able to represent more complex numerals. The difficulty here is going to be representing numerals with functions, for a few reasons:</p>
<ol type="1">
<li>There are an infinite number of numerals to represent</li>
<li>How can we combine the numerals using different functions, without defining the numerals themselves?</li>
</ol>
<p>We are going to explore Church Numerals, which define a numeral <em>N</em> by encapsulating a function <em>N</em> times. This is pretty cool, as we are then no longer representing the numeral <em>N</em> as a “count”; instead, it becomes more of a “timer”. Let’s take a look:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="32" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 31;"><span id="cb1-32">N0 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// apply f 0 times</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="36" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 35;"><span id="cb2-36">N1 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// apply f 1 time</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="40" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 39;"><span id="cb3-40">N2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// apply f 2 times</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="44" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 43;"><span id="cb4-44">N3 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a))) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// apply f 3 times</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="48" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 47;"><span id="cb5-48">N4 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(a)))) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// apply f 4 times</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<p>… and so on. However, the absolute <em>last</em> thing I want to do is sit here and write more functions to define every number ever. So, let’s call it good here, and use this (admittedly) short list to test our operations with.</p>
</section>
<section id="mathematical-operations" class="level2">
<h2 class="anchored" data-anchor-id="mathematical-operations">Mathematical Operations</h2>
<p>Similar to the idea of a “wrapper” function from last post (see <code>NOT()</code>), we need to define functions that will wrap around numbers to perform operations on them.</p>
<p>The first of these is the most simple, the successor function <code>SUCC()</code>. A fancy name for a basic operation, all this does is increment the number by 1. All it really is going to do is add another layer of wrapping around the number – that way, when we count the layers by “time”, our count, and therefore value, will have increased by 1.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="60" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 59;"><span id="cb6-60">SUCC <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">f</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f)(x))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<p>In the above, <code>f =&gt; x =&gt; f(n(f)(x))</code> creates our new number. To break it down further, <em>n</em> is the amount of times we are wrapping <em>f</em> around <em>x</em>, which means on its own, <code>n(f)(x)</code> is equal to <em>n</em>, the input number.</p>
<p>The crucial part of this function is the wrapper <em>f()</em> – as that is the piece which adds another “layer” to our number function, thereby incrementing its “count” by 1. If we substitute out the <em>n</em> discussed above for <em>N</em> (our numeral), this simplifies down to <code>N =&gt; f(N)</code>, where the incrementation is far easier to spot.</p>
<p>Now, we can move towards addition using the same principles. Instead of wrapping the “number” with one additional function call (successor), we need to wrap it with a variable number of functions:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" data-startfrom="70" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 69;"><span id="cb7-70">PLUS <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(f)(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f)(x))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<p>In the above, we achieve this by using the same “inner” variable for both functions, <em>x</em>. Accordingly, we want to apply <em>f</em> to <em>x</em> for each nested “number” function (<em>m</em> and <em>n</em>). Thus, we are applying <em>f</em> to <em>x</em> for <em>m</em> + <em>n</em> times, and following the same pattern of counting nested levels, we end up with our sum.</p>
<p>This principle is very extensible to multiplication – rather than operating on the same variable <em>x</em>, we want the “number” functions to operate on each other:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" data-startfrom="78" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 77;"><span id="cb8-78">MULT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> m <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> n <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> f <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">m</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">n</span>(f))</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<p>Rather than increasing the variable <em>x</em> first <em>m</em> times, then <em>n</em> times, we need to (increase the variable <em>f</em> <em>n</em> times) <em>m</em> times.</p>
<p>A more verbose way to write <code>MULT()</code> would be to add the <em>x</em> variable back in:</p>
<p><code>MULT = m =&gt; n =&gt; f =&gt; x =&gt; m(n(f))(x)</code></p>
<p>In this form, it is easier to see that instead of both <em>m</em> and <em>n</em> operating on <em>f(x)</em>, we are instead having <em>m</em> operate on <em>n</em>, which is in turn operating on <em>f(x)</em>.</p>
<p>Exponentiation takes this idea farther, and instead of using <em>f(x)</em> as the base we are incrementing, we want to increase the base, <em>b</em>, itself by <em>e</em> (exponent) amount of times.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" data-startfrom="92" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 91;"><span id="cb9-92">POW <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> e <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">e</span>(b)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<p>Just like in <code>MULT()</code>, there is a more verbose way to show this:</p>
<p><code>POW = b =&gt; e =&gt; f =&gt; x =&gt; e(b)(f)(x)</code></p>
<p>Here, it’s less clean, but much clearer that <em>e</em> and <em>b</em> operate independently of <em>f(x)</em>, and only once calculated, adds <em>e(b)</em> wrappers around <em>f(x)</em>. Also, note that we are using <em>f(x)</em> here as the base, which is equal to 1 – if we had only <em>x</em> instead, we would end up with an incorrect amount of wrappers.</p>
<p>With these basic arithmetic functions, let’s test our shiny new operation functions on a (drumroll please…) new truth table with our short list of numbers!</p>
<p>As we did last time, we’ll need to create a helper function to convert the lambda functions to actual numerals…</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" data-startfrom="106" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 105;"><span id="cb10-106">lambda_to_int <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (int) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb10-107">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">int</span>(x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb10-108">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="declaration">

</div>
</div>
</div>
<p>… letting us build our table!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" data-startfrom="114" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 113;"><span id="cb11-114">part_2_math_table <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb11-115">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> output <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb11-116">  </span>
<span id="cb11-117">  [N0<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N1<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N2<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> N4]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {    </span>
<span id="cb11-118">    output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb11-119">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>(a)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-120">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">succ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">SUCC</span>(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-121">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">plus</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">PLUS</span>(a)(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-122">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">mult</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">MULT</span>(a)(a) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb11-123">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">pow</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_int</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">POW</span>(a)(a) )</span>
<span id="cb11-124">    })</span>
<span id="cb11-125">  })</span>
<span id="cb11-126"></span>
<span id="cb11-127">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> output</span>
<span id="cb11-128">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" data-startfrom="132" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 131;"><span id="cb12-132">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(part_2_math_table)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="expression">

</div>
</div>
</div>
<hr>
<p>Woohoo! We’ve got some basic operations working now. However, you might have noticed that these operations are strictly incrementing our value.</p>
<p>Next time, we’ll take a look at how to reverse the direction with subtraction, and the underlying data structures that that will require.</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Inspired by <a href="http://hexatlas.com/entries/7">Eric Wastl’s</a> and <a href="https://www.driverlesscrocodile.com/tools-and-techniques/lambda-calculus-for-people-a-step-behind-me-2-boolean-logic/">Stuart Patience’s</a> posts.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20250520-lambda-calculus/</guid>
  <pubDate>Tue, 20 May 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>Exploring Lambda Calculus</title>
  <link>https://connorhanan.com/posts/20250430-lambda-calculus/</link>
  <description><![CDATA[ 




<section id="introduction" class="level2">
<h2 class="anchored" data-anchor-id="introduction">Introduction</h2>
<p>In short, lambda calculus is a pre-Turing machine implementation of computer programming. Rather than relying on memory, instructions, data structures, &amp;c, lambda calculus only has functions. These functions carry a few rules:</p>
<ol type="1">
<li>Functions can only take 1 argument, and have 1 statement.</li>
<li>Closures (encapsulated function environments) are allowed, and needed.</li>
<li>We can create aliases to help in shorthand, but all of the code muse be operable without doing anything that the original function cannot.</li>
</ol>
<p>With those out of the way, let’s begin… <sup>1</sup></p>
</section>
<section id="basics" class="level2">
<h2 class="anchored" data-anchor-id="basics">Basics</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="31" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 30;"><span id="cb1-31">IDENTITY <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> x <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> x</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<p>Our first function is very simple, but will show the foundation of what we are after.</p>
<p>This is the <em>identity</em> function, which returns exactly what the input is. Notice we are following all rules above: 1 argument &amp; statement, &amp;c</p>
<p>Let’s extend that a little farther:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="41" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 40;"><span id="cb2-41">RETURN_FIRST <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="45" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 44;"><span id="cb3-45"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RETURN_FIRST</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="49" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 48;"><span id="cb4-49">RETURN_SECOND <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="53" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 52;"><span id="cb5-53"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">RETURN_SECOND</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="expression">

</div>
</div>
</div>
<p>In the above functions, we are technically nesting a function within another, such that the argument of the first may or may not be called by the second function. <code>RETURN_FIRST()</code> and <code>RETURN_SECOND()</code> do exactly as they say, and this ‘switch’ ability is going to be key to start adding logic.</p>
</section>
<section id="booleans-and-logic-gates" class="level2">
<h2 class="anchored" data-anchor-id="booleans-and-logic-gates">Booleans and Logic Gates</h2>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="61" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 60;"><span id="cb6-61">TRUE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" data-startfrom="65" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 64;"><span id="cb7-65">FALSE <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="declaration">

</div>
</div>
</div>
<p>This may not seem like a lot, or more like a regurgitation of the sample switch return functions above, but this is critical to the base of our logic. The above are our replication of boolean states, which are identical to <code>RETURN_FIRST</code> and <code>RETURN_SECOND</code> – in fact, as we go on, it will be helpful to keep in mind that <code>TRUE</code> will always return the first argument, and <code>FALSE</code> the second.</p>
<p>Naturally, these booleans can be combined together, creating <code>AND</code>/<code>OR</code> logic gates:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb8" data-startfrom="73" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 72;"><span id="cb8-73">AND <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(d)(c)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-8" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb9" data-startfrom="77" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 76;"><span id="cb9-77">OR <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(c)(d)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-9" data-nodetype="declaration">

</div>
</div>
</div>
<p>As you can see, the arguments to the functions above are all functions, and will return functions. For example (below), calling <code>AND(TRUE)(FALSE)</code> and <code>OR(TRUE)(FALSE)</code> will return the appropriate functions, either <code>FALSE()</code>, or <code>TRUE()</code>.</p>
<p>As an example, let’s examine the <code>AND()</code> &amp; <code>OR()</code> step by step:</p>
<ol type="1">
<li>First, they accept two arguments, which we’ve seen before. In this function, the shorthand is <em>c</em> and <em>d</em>, but we’ll refer to them now as <em>first</em> and <em>second</em> arguments.</li>
<li>Once the arguments are collected, the bulk of the function is <code>c(d)(c)</code> or <code>c(c)(d)</code>.</li>
<li>Within these blocks, the order is critical, as the positions of the arguments of <code>TRUE()</code> and <code>FALSE()</code> dictate what the end result will be.</li>
</ol>
<p>We’re able to use creative permutations of returning the first (<code>TRUE</code>) and second (<code>FALSE</code>) values, giving us our basic <code>AND</code>/<code>OR</code> logic gates. As a thought experiment, let’s walk through all the possible permutations:</p>
<ul>
<li><code>AND(TRUE)(TRUE)</code> will call <code>TRUE(TRUE)(TRUE)</code>, returning: <code>TRUE()</code></li>
<li><code>AND(TRUE)(FALSE)</code> will call <code>TRUE(FALSE)(TRUE)</code>, returning: <code>FALSE()</code></li>
<li><code>AND(FALSE)(FALSE)</code> will call <code>FALSE(FALSE)(FALSE)</code>, returning: <code>FALSE()</code></li>
<li><code>AND(FALSE)(TRUE)</code> will call <code>FALSE(TRUE)(FALSE)</code>, returning: <code>FALSE()</code></li>
</ul>
<p>Likewise, for <code>OR()</code>:</p>
<ul>
<li><code>OR(TRUE)(TRUE)</code> will call <code>TRUE(TRUE)(TRUE)</code>, returning: <code>TRUE()</code></li>
<li><code>OR(TRUE)(FALSE)</code> will call <code>TRUE(TRUE)(FALSE)</code>, returning: <code>TRUE()</code></li>
<li><code>OR(FALSE)(FALSE)</code> will call <code>FALSE(FALSE)(FALSE)</code>, returning: <code>FALSE()</code></li>
<li><code>OR(FALSE)(TRUE)</code> will call <code>FALSE(FALSE)(TRUE)</code>, returning: <code>TRUE()</code></li>
</ul>
<p>And just to confirm that this is working as expected:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb10" data-startfrom="105" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 104;"><span id="cb10-105"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">AND</span>(TRUE)(FALSE) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> FALSE</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-10" data-nodetype="expression">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb11" data-startfrom="109" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 108;"><span id="cb11-109"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">OR</span>(TRUE)(FALSE) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> TRUE</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-11" data-nodetype="expression">

</div>
</div>
</div>
<p>As opposed to the above, <code>NOT()</code> looks like it will take 3 arguments rather than the 2 we’ve seen so far. However, the best way to think about it is that it takes only 1 argument: one of the other logic functions: <code>AND()</code>, <code>OR()</code>, &amp;c.</p>
<p>In the function, consider <code>c</code> as the outer function (<code>AND</code>, <code>OR</code>, &amp;c.), so instead of calling <code>AND(a)(b)</code>, it acts as a wrapper around the logic gate and will flip the inputs, translating it into <code>AND(b)(a)</code>. If you refer back to the <code>AND()</code>/<code>OR()</code> tables above, you can pretty clearly see how this would negate all the results.</p>
<p>Let’s take a look:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb12" data-startfrom="119" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 118;"><span id="cb12-119">NOT <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(b)(a)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-12" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb13" data-startfrom="123" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 122;"><span id="cb13-123"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOT</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">AND</span>(TRUE)(TRUE) ) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> FALSE</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-13" data-nodetype="expression">

</div>
</div>
</div>
<p>To extend this idea of a wrapper, we can leave the input order the same, and get a ternary operator (<code>IF</code>) out of it (just as a shorthand), of the form <code>IF(condition)(value if true)(value if false)</code> like so:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb14" data-startfrom="129" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 128;"><span id="cb14-129">IF <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(a)(b)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-14" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb15" data-startfrom="133" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 132;"><span id="cb15-133"><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">IF</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">AND</span>(TRUE)(FALSE) )(TRUE)(FALSE) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> FALSE</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-15" data-nodetype="expression">

</div>
</div>
</div>
<p>Now the incredible part – using these, we can now create all the rest of the core logic gates:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb16" data-startfrom="139" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 138;"><span id="cb16-139">NAND <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOT</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">AND</span>(c)(d) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-16" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb17" data-startfrom="143" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 142;"><span id="cb17-143">NOR <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOT</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">OR</span>(c)(d) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-17" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb18" data-startfrom="147" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 146;"><span id="cb18-147">XOR <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOT</span>(d) )(d)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-18" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb19" data-startfrom="151" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 150;"><span id="cb19-151">XNOR <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> c <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">c</span>(d)( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOT</span>(d) )</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-19" data-nodetype="declaration">

</div>
</div>
</div>
<p>And finally, with all these logic gates in hand, let’s extend the fledgling truth table from earlier to test all of these out. To do so, let’s build a helper function to let us parse out the values (since everything is a function, we need some real strings to populate the table).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb20" data-startfrom="157" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 156;"><span id="cb20-157">lambda_to_js <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (bool) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">bool</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"TRUE"</span>)(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"FALSE"</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-20" data-nodetype="declaration">

</div>
</div>
</div>
<p>And now we can map across all permutations of our logic gates:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb21" data-startfrom="163" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 162;"><span id="cb21-163">part_1_truth_table <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb21-164">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> output <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb21-165">  </span>
<span id="cb21-166">  [TRUE<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> FALSE]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(a <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {    </span>
<span id="cb21-167">    [TRUE<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> FALSE]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(b <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb21-168">      output<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb21-169">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">a</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>(a)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-170">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>(b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-171">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">and</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">AND</span>(a)(b) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-172">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">or</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">OR</span>(a)(b) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-173">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">nand</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NAND</span>(a)(b) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-174">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">nor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">NOR</span>(a)(b) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-175">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">xor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">XOR</span>(a)(b) )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb21-176">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">xnor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">lambda_to_js</span>( <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">XNOR</span>(a)(b) )</span>
<span id="cb21-177">      })</span>
<span id="cb21-178">    })</span>
<span id="cb21-179">  })</span>
<span id="cb21-180"></span>
<span id="cb21-181">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> output</span>
<span id="cb21-182">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-21" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb22" data-startfrom="187" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode numberSource js number-lines code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 186;"><span id="cb22-187">Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">table</span>(part_1_truth_table)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-22" data-nodetype="expression">

</div>
</div>
</div>
<hr>
<p>Great! We have created a full lambda calculus implementation of some logic gates! Now, this may seem trivial, but consider what is happening under the hood - we are using only functions to represent both values and operations.</p>
<p>As you’ll see next time, this can spiral out of control very quickly once we take a look at representing numbers and more complex operations.</p>
<p>-CH</p>


</section>


<div id="quarto-appendix" class="default"><section id="footnotes" class="footnotes footnotes-end-of-document"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Inspired by <a href="http://hexatlas.com/entries/7">Eric Wastl’s</a> and <a href="https://www.driverlesscrocodile.com/tools-and-techniques/lambda-calculus-for-people-a-step-behind-me-2-boolean-logic/">Stuart Patience’s</a> posts.↩︎</p></li>
</ol>
</section></div> ]]></description>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20250430-lambda-calculus/</guid>
  <pubDate>Wed, 30 Apr 2025 04:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 7: Bridge Repair</title>
  <link>https://connorhanan.com/posts/20241207-advent-of-code/</link>
  <description><![CDATA[ 




<p><a href="https://adventofcode.com/2024/day/7">Day 7</a>!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="901" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 900;"><span id="cb1-901">input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-902">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> clean <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)</span>
<span id="cb1-903">  clean<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pop</span>()</span>
<span id="cb1-904"></span>
<span id="cb1-905">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> clean<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-906">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> parsed <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\d+</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> elem[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb1-907">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> {</span>
<span id="cb1-908">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>parsed[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-909">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">operands</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> parsed<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>elem)</span>
<span id="cb1-910">    }</span>
<span id="cb1-911">  })</span>
<span id="cb1-912">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>In this puzzle, we are given a bunch of numbers, and have to figure out how to reach the result by different operations. Those pesky elves stole all the operators!</p>
<div class="cell" data-eval="false">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="923" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 922;"><span id="cb2-923"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// go backwards along input -- if mod div === 0 then it's multiply, else add</span></span>
<span id="cb2-924">check_eq_step <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-925">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// final check</span></span>
<span id="cb2-926">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> target</span>
<span id="cb2-927"></span>
<span id="cb2-928">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if div by last factor</span></span>
<span id="cb2-929">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb2-930">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if subtractable by last factor</span></span>
<span id="cb2-931">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb2-932"></span>
<span id="cb2-933">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if can't divide or subtract evenly then fail upwards</span></span>
<span id="cb2-934">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>sub) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span></span>
<span id="cb2-935"></span>
<span id="cb2-936">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (</span>
<span id="cb2-937">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// div case</span></span>
<span id="cb2-938">    (div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step</span>(  target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) )) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span></span>
<span id="cb2-939">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// sub case</span></span>
<span id="cb2-940">    (sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step</span>( target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) ))</span>
<span id="cb2-941">  )</span>
<span id="cb2-942">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<p>I first thought of trying to work through the equation recursively, left to right, but it quickly expanded into so many possible routes of combinations. After a while of tinkering, I landed on the above – working backwards through the equation. I realized that if the operation doesn’t cleanly work, then it’s invalid, and we can trim that route of options.</p>
<p>This way, we can prune the options as we go, without having to calculate to the end of the equation. For example, if we know the result is 200, and we know the last number in the equation is 201, we know the calculation is impossible because (a) 200 / 201 is not an integer, and (b) 200 - 201 is negative. Therefore, with one check, we can toss the whole equation, instead of only realizing it at the end!</p>
<div class="cell" data-eval="false">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="953" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 952;"><span id="cb3-953">input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">operands</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()))</span>
<span id="cb3-954">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-955">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span></span>
<span id="cb3-956">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="expression">

</div>
</div>
</div>
<p>Once we have our function, it’s as easy as recursively applying it across the equation, and accumulating the result.</p>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>In part 2, we now have to worry about string concatenation as a possible operator, instead of only multiplication and addition.</p>
<div class="cell" data-eval="false">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="971" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 970;"><span id="cb4-971"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// go backwards again, but add check for string end</span></span>
<span id="cb4-972">check_eq_step_2 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb4-973">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// final check</span></span>
<span id="cb4-974">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> target</span>
<span id="cb4-975"></span>
<span id="cb4-976">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if div by last factor</span></span>
<span id="cb4-977">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span></span>
<span id="cb4-978">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if subtractable by last factor</span></span>
<span id="cb4-979">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]</span>
<span id="cb4-980">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if concat happened</span></span>
<span id="cb4-981">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">String</span>(target)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">endsWith</span>(operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])</span>
<span id="cb4-982"></span>
<span id="cb4-983">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if can't divide or subtract evenly then fail upwards</span></span>
<span id="cb4-984">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>cat) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span></span>
<span id="cb4-985">  </span>
<span id="cb4-986">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> (</span>
<span id="cb4-987">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// div case</span></span>
<span id="cb4-988">    (div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step_2</span>( target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) )) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span></span>
<span id="cb4-989">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// sub case</span></span>
<span id="cb4-990">    (sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step_2</span>( target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) )) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span></span>
<span id="cb4-991">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// concat case</span></span>
<span id="cb4-992">    (cat <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step_2</span>( <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Number</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">String</span>(target)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="bu" style="color: null;
background-color: null;
font-style: inherit;">String</span>(operands[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb4-993">                             operands<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) ))</span>
<span id="cb4-994">  )</span>
<span id="cb4-995">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="declaration">

</div>
</div>
</div>
<p>However, this ends up being not too bad, as we can add an extra recursive step, and check the result and operator via slicing. For example, if the target is 156, and our operand is 6, then we have a match, since that would leave us with 15 (still working backwards here).</p>
<div class="cell" data-eval="false">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="1004" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 1003;"><span id="cb5-1004">input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_eq_step_2</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">operands</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()))</span>
<span id="cb5-1005">  <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb5-1006">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">target</span></span>
<span id="cb5-1007">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="expression">

</div>
</div>
</div>
<p>With that little adjustment, we are all set!</p>
<p>⭐</p>
<hr>
<p>Not too bad once you recognize going backwards will prune your sample space.</p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20241207-advent-of-code/</guid>
  <pubDate>Sat, 07 Dec 2024 05:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 6: Guard Gallivant</title>
  <link>https://connorhanan.com/posts/20241206-advent-of-code/</link>
  <description><![CDATA[ 




<p><a href="https://adventofcode.com/2024/day/6">Day 6</a>!</p>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>Today, it feels like we are designing a videogame! I usually hide the input parsing, though I thought today’s was notable in that I found a better way to map out a grid using integer and mod division to calculate the starting position:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="174" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 173;"><span id="cb1-174">input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-175">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 2D array</span></span>
<span id="cb1-176">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [nrow<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ncol] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> map[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span>] <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// dims</span></span>
<span id="cb1-177">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> start_index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flat</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">indexOf</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"^"</span>) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// guard start</span></span>
<span id="cb1-178">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// use integer &amp; mod div to find location</span></span>
<span id="cb1-179">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [curr_row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> curr_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(start_index<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span>ncol)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> start_index <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> ncol]</span>
<span id="cb1-180">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> clean_map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()</span>
<span id="cb1-181">  clean_map[curr_row][curr_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'.'</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// replace so it's counted as an empty spot</span></span>
<span id="cb1-182"></span>
<span id="cb1-183">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-184">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [curr_row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> curr_col]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-185">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">layout</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> clean_map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-186">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dir</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// up</span></span>
<span id="cb1-187">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">dims</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [nrow<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ncol]</span>
<span id="cb1-188">  }</span>
<span id="cb1-189">  </span>
<span id="cb1-190">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> input</span>
<span id="cb1-191">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<p>Now that that is sorted, let’s proceed to part 1…</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="199" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 198;"><span id="cb2-199">possible_moves <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb2-200">  [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// up</span></span>
<span id="cb2-201">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// right</span></span>
<span id="cb2-202">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// down</span></span>
<span id="cb2-203">  [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// left</span></span>
<span id="cb2-204">]</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<p>First, since we know we are navigating around a grid, let’s define movements in the four cardinal directions.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="212" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 211;"><span id="cb3-212">move_guard <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> possible_moves) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-213">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [] <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// positions</span></span>
<span id="cb3-214">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> [[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dir] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dir</span>]</span>
<span id="cb3-215"></span>
<span id="cb3-216">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>) { <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// until guard leaves grid</span></span>
<span id="cb3-217">    </span>
<span id="cb3-218">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// add current position and heading</span></span>
<span id="cb3-219">    pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>([row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dir])</span>
<span id="cb3-220"></span>
<span id="cb3-221">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get next pos and direction</span></span>
<span id="cb3-222">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [next_row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> next_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb3-223">                                  col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb3-224">    </span>
<span id="cb3-225">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// OOB check</span></span>
<span id="cb3-226">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (next_row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> next_row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dims</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> </span>
<span id="cb3-227">          next_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> next_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dims</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) {</span>
<span id="cb3-228">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pos</span>
<span id="cb3-229">    } </span>
<span id="cb3-230"></span>
<span id="cb3-231">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if blocked, turn right</span></span>
<span id="cb3-232">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout</span>[next_row][next_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#"</span>) {</span>
<span id="cb3-233">      dir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (dir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb3-234">    }</span>
<span id="cb3-235"></span>
<span id="cb3-236">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// update position so it gets pushed for next iter</span></span>
<span id="cb3-237">    [row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb3-238">                  col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb3-239">    </span>
<span id="cb3-240">  }</span>
<span id="cb3-241">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-3" data-nodetype="declaration">

</div>
</div>
</div>
<p>Now we’re getting serious – the main bulk of the problem!</p>
<p>This function traces the guard’s path by running through each step in a while loop. This way, we can set the condition to break on the guard leaving the bounds of our grid. Also, since we are keeping track of the direction using an integer, we can utilize it as an index with a little creative math.</p>
<p>Though this function looks clean, it was not my first attempt. I originally thought that this would be a great use case for a recursive function – each call would move the guard a step forward, then call itself again (assuming it stayed in bounds). However, as soon as I scaled up to the full input, I exceeded the call stack, so I went back to the drawing board.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="253" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 252;"><span id="cb4-253"><span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">move_guard</span>(input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> possible_moves)</span>
<span id="cb4-254">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">JSON</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">stringify</span>( [ d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ] )))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span></span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
<p>Once we have our function, it’s just a matter of finding the number of unique positions visited. I chose to do this with <code>JSON.stringify()</code>, then creating a Set from those strings and counting the length. After the fact, I saw someone’s solution for another day that used bitwise shifts and joins to calculate uniques (which I’ll use in Part 2).</p>
<p>Part 1 complete!</p>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>Uh oh, more complex now… we have to check how many discrete locations we can add an extra obstacle to in the guard’s path to send him into an infinite loop. This was daunting to start with, because anything that has to deal with checking for infinite loops seems difficult to do without launching into an infinite loop yourself. For example, if you revisit a specific location, who’s to say that your next step will continue the loop?</p>
<p>However, after some pondering, I realized that that is <strong>not</strong> the case here. We have very specific rules about movement, so we can say with certainty that if a position is repeated, and a guard is facing the same way as before, then a loop is happening. In fact, we can abstract it away farther, and only care about checking the turn points for overlaps, since those are the ‘decision points’ where a loop could be entered.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="272" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 271;"><span id="cb5-272">check_loop <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> possible_moves) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb5-273">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()</span>
<span id="cb5-274">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> [[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> dir] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">start</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dir</span>]</span>
<span id="cb5-275">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> turn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span></span>
<span id="cb5-276"></span>
<span id="cb5-277">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">while</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span>) {</span>
<span id="cb5-278">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// if move is a turn</span></span>
<span id="cb5-279">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (turn) {</span>
<span id="cb5-280">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// check if position and heading exists</span></span>
<span id="cb5-281">      <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> current_pos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">16</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> (col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> dir</span>
<span id="cb5-282">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">has</span>(current_pos)) {</span>
<span id="cb5-283">        <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// exit and say yes loop exists</span></span>
<span id="cb5-284">        <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb5-285">      }</span>
<span id="cb5-286">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// otherwise add and keep going</span></span>
<span id="cb5-287">      pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(current_pos)</span>
<span id="cb5-288">    }</span>
<span id="cb5-289"></span>
<span id="cb5-290">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get next pos and direction</span></span>
<span id="cb5-291">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [next_row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> next_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb5-292">                                  col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> possible_moves[dir][<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]]</span>
<span id="cb5-293"></span>
<span id="cb5-294">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// OOB check</span></span>
<span id="cb5-295">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (next_row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> next_row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dims</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> </span>
<span id="cb5-296">          next_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> next_col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;=</span> input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">dims</span>[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]) {</span>
<span id="cb5-297">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// no loop, exits grid</span></span>
<span id="cb5-298">    }</span>
<span id="cb5-299"></span>
<span id="cb5-300">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout</span>[next_row][next_col] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#"</span>) {</span>
<span id="cb5-301">      dir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (dir <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span></span>
<span id="cb5-302">      turn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">true</span></span>
<span id="cb5-303">    } <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">else</span> {</span>
<span id="cb5-304">      row <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> next_row</span>
<span id="cb5-305">      col <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> next_col</span>
<span id="cb5-306">      turn <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">false</span></span>
<span id="cb5-307">    }</span>
<span id="cb5-308">  }</span>
<span id="cb5-309">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<p>To start, let’s modify the previous function to log all the positions as a Set, as well as tracking the heading in the position Set, as that will be critical to determining if we are in a loop.</p>
<p>Another change of note is we are now keeping a boolean flag <code>turn</code> to keep track of whether each move is a turn or not. This way, we can say that if the guard is turning, check if the position has been reached before; otherwise, continue as is onto the next step.</p>
<p>If you look closely, you’ll also see the bit shifting mentioned above being used to collapse row, col, and dir down to one number.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="321" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 320;"><span id="cb6-321">{</span>
<span id="cb6-322">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get unique route positions</span></span>
<span id="cb6-323">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> all_route <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">move_guard</span>(input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> possible_moves)</span>
<span id="cb6-324">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] )</span>
<span id="cb6-325">  </span>
<span id="cb6-326">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> unique_pos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>(all_route))</span>
<span id="cb6-327">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// multiply by masking hex codes to shorten down the bits </span></span>
<span id="cb6-328">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> ( [(d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&gt;&gt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">0xFF</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;</span> <span class="bn" style="color: #AD0000;
background-color: null;
font-style: inherit;">0xFF</span>] ))</span>
<span id="cb6-329">  </span>
<span id="cb6-330">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// keep track of new obstacles</span></span>
<span id="cb6-331">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> loop_counter <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()</span>
<span id="cb6-332"></span>
<span id="cb6-333">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// for each position on the route</span></span>
<span id="cb6-334">  unique_pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-335">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// add obstacle</span></span>
<span id="cb6-336">    input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout</span>[ d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] ][ d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#"</span></span>
<span id="cb6-337">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if loop exists</span></span>
<span id="cb6-338">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_loop</span>(input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> possible_moves)) {</span>
<span id="cb6-339">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// add to tracker</span></span>
<span id="cb6-340">      loop_counter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>( (d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;&lt;</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">8</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">|</span> d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] )</span>
<span id="cb6-341">    }</span>
<span id="cb6-342">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// reset layout for next iter</span></span>
<span id="cb6-343">    input<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">layout</span>[ d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] ][ d[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"."</span></span>
<span id="cb6-344">  })</span>
<span id="cb6-345">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// return unique counts</span></span>
<span id="cb6-346">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> loop_counter<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">size</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// duped the start position</span></span>
<span id="cb6-347">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="expression">

</div>
</div>
</div>
<p>Unfortunately, there wasn’t many better ways to find all the loops than to try each one, adding an obstacle to a different location each time. To shrink the search space some, I decided to only try adding obstacles to the locations that the guard visited in Part 1 – after all, if he never runs into it, then it won’t be a loop since we know that he exits cleanly with the default map.</p>
<p>Anyways, we just need to iterate through those positions, modifying the grid and running our <code>check_loop()</code> function on each; once we have the resultant positions, we just need the count of uniques.</p>
<p>⭐</p>
<hr>
<p>Ramping up in difficulty for sure now!</p>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20241206-advent-of-code/</guid>
  <pubDate>Fri, 06 Dec 2024 05:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 5: Print Queue</title>
  <link>https://connorhanan.com/posts/20241205-advent-of-code/</link>
  <description><![CDATA[ 




<p><a href="https://adventofcode.com/2024/day/4">Day 5</a>!</p>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>Let’s jump in – today’s parts are both quite similar.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="1446" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 1445;"><span id="cb1-1446">{</span>
<span id="cb1-1447">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>))</span>
<span id="cb1-1448">  </span>
<span id="cb1-1449">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pages <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-1450">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">numbers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// unique pages</span></span>
<span id="cb1-1451">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">orders</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>() <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// page =&gt; before</span></span>
<span id="cb1-1452">  }</span>
<span id="cb1-1453">  </span>
<span id="cb1-1454">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// add all inputs to set &amp; map</span></span>
<span id="cb1-1455">  input[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>(({numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> orders}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-1456">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [<span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> to] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(\d+)|(\d+)</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/g</span>)</span>
<span id="cb1-1457">    numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span>)</span>
<span id="cb1-1458">    numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>to)</span>
<span id="cb1-1459">    orders<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>( <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (orders<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>())<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>to) )</span>
<span id="cb1-1460">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pages</span>
<span id="cb1-1461">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pages)</span>
<span id="cb1-1462"></span>
<span id="cb1-1463">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// clean up all books</span></span>
<span id="cb1-1464">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> updates <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> input[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>elem))</span>
<span id="cb1-1465"></span>
<span id="cb1-1466">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// custom sort function</span></span>
<span id="cb1-1467">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> page_sort <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (update<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> order) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-1468">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> update<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> order<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb1-1469">  }</span>
<span id="cb1-1470"></span>
<span id="cb1-1471">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// see if all are in order, if yes, then sum middle numbers</span></span>
<span id="cb1-1472">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> updates</span>
<span id="cb1-1473">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>((d) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-1474">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">every</span>((elem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> elem <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">page_sort</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">orders</span>)[i])</span>
<span id="cb1-1475">    })</span>
<span id="cb1-1476">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d[(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb1-1477">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb1-1478">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="expression">

</div>
</div>
</div>
<p>For the first part, the parsing was the most diffcult part. And by difficult, I just mean more involved than usual – I opted to read it all into one object that has both a Set and a Map. This is my standard read option when we have ordering in the input. The set will give us all unique options, and the Map will maintain orderings and relationships, which comes in great use for this part.</p>
<p>To start, we have to use all the page numbering rules to check the orders of the updates (which I will call books going forward, since it flows better). This is fairly easy, all we have to do is sort the pages in each book using our custom comparator, then make sure that that array matches the initial array. All we have to do then is filter on those books that pass the test, extract their middle number (thankfully all of them are odd in length), and sum!</p>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>Part 2 was one of the easiest by far – all we have to do is negate our comparator function results. This time, we only want to keep the ones that are out of order, sort them, then pull out the middle numbers and sum!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="1494" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 1493;"><span id="cb2-1494">{</span>
<span id="cb2-1495">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> input <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"</span>))</span>
<span id="cb2-1496"></span>
<span id="cb2-1497">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pages <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-1498">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">numbers</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-1499">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">orders</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>()</span>
<span id="cb2-1500">  }</span>
<span id="cb2-1501">  </span>
<span id="cb2-1502">  input[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>(({numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> orders}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-1503">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> [<span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> to] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">match</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">(\d+)|(\d+)</span><span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/g</span>)</span>
<span id="cb2-1504">    numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span>)</span>
<span id="cb2-1505">    numbers<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">add</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>to)</span>
<span id="cb2-1506">    orders<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>( <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> (orders<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="im" style="color: #00769E;
background-color: null;
font-style: inherit;">from</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>())<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>to) )</span>
<span id="cb2-1507">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> pages</span>
<span id="cb2-1508">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pages)</span>
<span id="cb2-1509"></span>
<span id="cb2-1510">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> updates <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> input[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">","</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>elem))</span>
<span id="cb2-1511"></span>
<span id="cb2-1512">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> page_sort <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (update<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> order) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-1513">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> update<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> b) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> order<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(b)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(a) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)</span>
<span id="cb2-1514">  }</span>
<span id="cb2-1515"></span>
<span id="cb2-1516">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// negate the every() statement from part 1</span></span>
<span id="cb2-1517">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> updates</span>
<span id="cb2-1518">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>((d) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-1519">      <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">every</span>((elem<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> elem <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">page_sort</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">orders</span>)[i])</span>
<span id="cb2-1520">    })</span>
<span id="cb2-1521">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// sort then count since they are in wrong order</span></span>
<span id="cb2-1522">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">page_sort</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> pages<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">orders</span>))</span>
<span id="cb2-1523">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d[(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>])</span>
<span id="cb2-1524">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb2-1525">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="expression">

</div>
</div>
</div>
<p>⭐</p>
<hr>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20241205-advent-of-code/</guid>
  <pubDate>Thu, 05 Dec 2024 05:00:00 GMT</pubDate>
</item>
<item>
  <title>2024 Day 4: Ceres Search</title>
  <link>https://connorhanan.com/posts/20241204-advent-of-code/</link>
  <description><![CDATA[ 




<p><a href="https://adventofcode.com/2024/day/4">Day 4</a>!</p>
<section id="part-1" class="level3">
<h3 class="anchored" data-anchor-id="part-1">Part 1</h3>
<p>Alright, now we are starting to get a little trickier – today we are doing a word search.</p>
<p>In the past, I have started by just brute forcing a grid traversal, checking all the neighbors as I go. However, I typically get burned by it, as part 2 ends up being more expensive of an operation than part 1. So, this time, I resolved to fins another method, and I landed on rotations!</p>
<p>Instead of checking every direction from each letter, I check the whole grid as is (forward and back), then rotate and repeat – let’s begin:</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb1" data-startfrom="188" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 187;"><span id="cb1-188">rotate_grid_90 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-189">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// take first row, map across with indices and reverse the column order</span></span>
<span id="cb1-190">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>( (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>( row <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> row[i] )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>() )</span>
<span id="cb1-191">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<p>In the above, this is the simplest of the rotations – we are taking each row and translating it into a column, and vice versa.</p>
<p>Since we are checking forward and backward, it doesn’t matter too much about which direction we spin the 2D array. An issue I had for a while was that I was missing the <code>reverse()</code> call, which led to me reflecting the 2D array across the diagonal instead of rotating. I’m sure that there is a D3 method for some of this (maybe Arquero too?), but I wanted to do it from scratch.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb2" data-startfrom="201" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 200;"><span id="cb2-201">rotate_grid_45 <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-202">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// col, row (x, y)</span></span>
<span id="cb2-203">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> dims <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [ grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> ]</span>
<span id="cb2-204">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// build array of indices of all values in the grids</span></span>
<span id="cb2-205">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> pos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>(</span>
<span id="cb2-206">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Set</span>( <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// unique</span></span>
<span id="cb2-207">      <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i)</span>
<span id="cb2-208">        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>(dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>i)))</span>
<span id="cb2-209">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// create array and fill with values (indices)</span></span>
<span id="cb2-210">    )</span>
<span id="cb2-211">  ) <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// [0, 1, 2, 3, 4, 5, 6, 7, 8]</span></span>
<span id="cb2-212"></span>
<span id="cb2-213">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// create separate length calculations of pyramid</span></span>
<span id="cb2-214">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// based on even odd split</span></span>
<span id="cb2-215">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> lengths <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">%</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> </span>
<span id="cb2-216">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// even</span></span>
<span id="cb2-217">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i)</span>
<span id="cb2-218">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)</span>
<span id="cb2-219">                        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>()) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span></span>
<span id="cb2-220">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// odd</span></span>
<span id="cb2-221">    <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i)</span>
<span id="cb2-222">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(<span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">floor</span>(pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>))</span>
<span id="cb2-223">                        <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> i)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reverse</span>())</span>
<span id="cb2-224">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// [1, 2, 3, 2, 1]</span></span>
<span id="cb2-225"></span>
<span id="cb2-226">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// create index map based on diffs from translation</span></span>
<span id="cb2-227">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> all_positions <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> lengths<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>((d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-228">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> [pos<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()[i]]</span>
<span id="cb2-229">      <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>( </span>
<span id="cb2-230">        <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span>(d)</span>
<span id="cb2-231">          <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fill</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>)</span>
<span id="cb2-232">          <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>( (_<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> (i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>(dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) )</span>
<span id="cb2-233">      )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>( </span>
<span id="cb2-234">          (acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-235">          <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> </span>
<span id="cb2-236">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> [nxt] </span>
<span id="cb2-237">            <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(acc[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> nxt)</span>
<span id="cb2-238">          }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-239">        []</span>
<span id="cb2-240">      )</span>
<span id="cb2-241">  })</span>
<span id="cb2-242">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// [[0]        // 1 length</span></span>
<span id="cb2-243">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//  [1, 3]     // 2</span></span>
<span id="cb2-244">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//  [2, 4, 6]  // 3</span></span>
<span id="cb2-245">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//  [5, 7]     // 2</span></span>
<span id="cb2-246">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">//  [8]]       // 1</span></span>
<span id="cb2-247"></span>
<span id="cb2-248">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> grid_vals <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> nxt) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">concat</span>(nxt))</span>
<span id="cb2-249">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> all_positions<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(row <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(col <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> grid_vals[col]))</span>
<span id="cb2-250">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-2" data-nodetype="declaration">

</div>
</div>
</div>
<p>Now this function is to rotate 45 degrees to check the diagonals. This ends up being far more complex than a 90 degree rotation because the resultant arrays aren’t of equal length.</p>
<p>First, in <code>pos</code> we need to create an array that has all the indices of the input 2D array. This was easier mentally to arrange, then just substitute at the end, though I’m sure this step could now be refactored if desired. Next, with <code>lengths</code> I wanted to calculate the lengths of each array in the pyramid arrangement of arrays after the rotation. This will allow a mapping function later to iterate through and fill with the needed values.</p>
<p>Finally, the last step of our prepatory steps is to wrap all the indices into the correct positions (thus <code>all_positions</code>). Of note, this includes a calculation to increase the step of each index by the dimensions of the original 2D array – since the example is 3x3, the outer indices are <code>[0, 1, 2, 5, 8]</code>, which wraps the first row and last column. With how we are rotating, those become the first indices in each resulting array, as they lead all the diagonals of our 45 degree rotation.</p>
<p>This means that each step is <code>width of array - 1 = 2</code> in our example. If you picture it, you can concatenate all the arrays into one long number line, and you want 1 less than a perfect row in order to create a diagonal. Lastly, we just map across the resulting indices and substitute our actual values back in.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb3" data-startfrom="266" data-source-offset="-1" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 265;"><span id="cb3-266">check_rows <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-267">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// check matches for XMAS</span></span>
<span id="cb3-268">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> forward <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid</span>
<span id="cb3-269">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-270">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/XMAS/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-271">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// check matches for SAMX -- could also reverse() string I guess</span></span>
<span id="cb3-272">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> backward <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid</span>
<span id="cb3-273">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-274">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/SAMX/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-275">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> forward <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> backward</span>
<span id="cb3-276">}</span>
<span id="cb3-277"></span>
<span id="cb3-278">check_cols <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-279">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> col_grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rotate_grid_90</span>(grid)</span>
<span id="cb3-280">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> up <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col_grid</span>
<span id="cb3-281">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-282">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/XMAS/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-283">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> down <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> col_grid</span>
<span id="cb3-284">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-285">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/SAMX/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-286">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> up <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> down</span>
<span id="cb3-287">}</span>
<span id="cb3-288"></span>
<span id="cb3-289">check_diag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb3-290">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> up_diag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rotate_grid_45</span>(grid)</span>
<span id="cb3-291">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-292">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/XMAS/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-293">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> down_diag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rotate_grid_45</span>(grid)</span>
<span id="cb3-294">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">reduce</span>((acc<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> acc <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">join</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>)</span>
<span id="cb3-295">                                    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">matchAll</span>(<span class="ss" style="color: #20794D;
background-color: null;
font-style: inherit;">/SAMX/g</span>)]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> )</span>
<span id="cb3-296">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> up_diag <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> down_diag</span>
<span id="cb3-297">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-3-3" data-nodetype="declaration">

</div>
</div>
</div>
</div>
<p>Finally, all we have to do is create helper functions for each direction – horizontal, vertical (rotated horizontal), and diagonal (rotated 45 horizontal). Each of them checks for both <code>XMAS</code> and <code>SAMX</code>, that way we can minimize rotations.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb4" data-startfrom="303" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 302;"><span id="cb4-303">{</span>
<span id="cb4-304">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>))</span>
<span id="cb4-305">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_rows</span>(grid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_cols</span>(grid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> </span>
<span id="cb4-306">         <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_diag</span>(grid) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">check_diag</span>(<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">rotate_grid_90</span>(grid))</span>
<span id="cb4-307">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-4" data-nodetype="expression">

</div>
</div>
</div>
<p>Once the helpers are made, we just have to sum them! Note that we have two 45 degree rotations – one is to get the upper-left to lower-right diagonal, and the other is the upper-right to lower-left diagonal. Since we already have a 90 degree rotation, we can get the perpendicular diagonal by combining a 90 + 45 rotation, giving us our 0 degree, 90 degree, 45 degree, and 135 degree totals!</p>
<p>⭐</p>
</section>
<section id="part-2" class="level3">
<h3 class="anchored" data-anchor-id="part-2">Part 2</h3>
<p>Unfortunately, I out-thought myself. Part 2 was far simpler than part 1 in this case, so I went back and created a new process to walk each cell (excluding the border):</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb5" data-startfrom="319" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 318;"><span id="cb5-319">walk_grid_no_border <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> fn) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb5-320">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// row, col</span></span>
<span id="cb5-321">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> inner_dims <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> grid[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>]</span>
<span id="cb5-322">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// copy grid</span></span>
<span id="cb5-323">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> output_grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()</span>
<span id="cb5-324">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// map across every inner cell (not borders)</span></span>
<span id="cb5-325">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> inner_dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb5-326">    <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">let</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> inner_dims[<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> k<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb5-327">      <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// call function on each cell, store result in new grid</span></span>
<span id="cb5-328">      output_grid[i][k] <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fn</span>(grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">slice</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> k)</span>
<span id="cb5-329">    }</span>
<span id="cb5-330">  }</span>
<span id="cb5-331">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> output_grid</span>
<span id="cb5-332">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-5" data-nodetype="declaration">

</div>
</div>
</div>
<p>As mentioned, this walks each cell, and performs a lambda function on it, passed through as an argument. This way, if I need to walk a grid in the future, I should be able to reuse this one!</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb6" data-startfrom="338" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 337;"><span id="cb6-338">check_cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> col) <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb6-339">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// get cell</span></span>
<span id="cb6-340">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> grid[row][col]</span>
<span id="cb6-341">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// A will always be the intersection</span></span>
<span id="cb6-342">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">if</span> (cell <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">!==</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"A"</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> cell</span>
<span id="cb6-343">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// look up diagonal characters</span></span>
<span id="cb6-344">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> diags <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb6-345">    [ grid[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> grid[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb6-346">    [ grid[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> grid[row<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>][col<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>] ]</span>
<span id="cb6-347">  ]</span>
<span id="cb6-348">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// make sure each diagonal has an 'M' and an 'S'</span></span>
<span id="cb6-349">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> diags<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"M"</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&amp;&amp;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">includes</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"S"</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">every</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> elem)</span>
<span id="cb6-350">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-6" data-nodetype="declaration">

</div>
</div>
</div>
<p>Again, fairly straightforward, for each cell, I want to check each adjacent diagonal to see if they qualify, using <code>A</code> as the pivot point. I also had to pass a shallow copy of the the grid in so that when I replace a cell value with the boolen answer, it won’t impact further checks in the next row(s).</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code" id="cb7" data-startfrom="356" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 355;"><span id="cb7-356">{</span>
<span id="cb7-357">  <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">const</span> grid <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> raw<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">\n</span><span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">split</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">""</span>))</span>
<span id="cb7-358">  <span class="cf" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">return</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">walk_grid_no_border</span>(grid<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> check_cell)</span>
<span id="cb7-359">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">flatMap</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">filter</span>(elem <span class="kw" style="color: #003B4F;
background-color: null;
font-weight: bold;
font-style: inherit;">=&gt;</span> elem <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">==</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>))</span>
<span id="cb7-360">    <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span></span>
<span id="cb7-361">}</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-7" data-nodetype="expression">

</div>
</div>
</div>
<p>Once we have those two functions, it’s just a matter of mapping them across the input! We should be fairly well set up for future grid questions where we have to walk the input – and any rotations!</p>
<p>⭐</p>
<hr>
<p>-CH</p>


</section>

 ]]></description>
  <category>Advent of Code</category>
  <category>OJS</category>
  <guid>https://connorhanan.com/posts/20241204-advent-of-code/</guid>
  <pubDate>Wed, 04 Dec 2024 05:00:00 GMT</pubDate>
</item>
</channel>
</rss>
