- Scan ID:
- 62ba5790-4968-4ef4-94c8-f315615580aeFinished
- Submitted URL:
- https://tgragnato.it/2023/12/20/Pulse-Propagation.html
- Report Finished:
Links · 6 found
The outgoing links identified from the page
Link | Text |
---|---|
https://adventofcode.com/2023/day/20 | If you’re new to Advent of Code, it’s an annual event that takes place throughout December, featuring a series of programming puzzles that get progressively more challenging as Christmas approaches. |
https://github.com/tgragnato | |
https://linkedin.com/in/tgragnato | |
https://news.ycombinator.com/user?id=tg180 | |
https://gitlab.torproject.org/tgragnato | |
https://signal.me/#eu/iN-evzfy1ywTQ4WRFeumNrXHYS90EdCWyu_3MT8AzGf46ktEL0RC-ZJnbaow6UD4 |
JavaScript Variables · 4 found
Global JavaScript variables loaded on the window object of a page, are variables declared outside of functions and accessible from anywhere in the code within the current scope
Name | Type |
---|---|
onbeforetoggle | object |
documentPictureInPicture | object |
onscrollend | object |
__cfBeacon | object |
Console log messages · 10 found
Messages logged to the web console
Type | Category | Log |
---|---|---|
warning | other |
|
warning | other |
|
warning | other |
|
warning | other |
|
warning | other |
|
warning | other |
|
warning | security |
|
warning | security |
|
log | javascript |
|
warning | other |
|
HTML
The raw HTML body of the page
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="index, follow, noarchive"><meta name="twitter:card" content="summary"><title>Pulse Propagation | Tommaso Gragnato</title><meta property="og:title" content="Pulse Propagation | Tommaso Gragnato"><meta name="twitter:title" content="Pulse Propagation | Tommaso Gragnato"><meta name="author" content="Tommaso Gragnato"><meta name="keywords" content="Advent of Code 2023 [Day 20] | Pulse Propagation | Tommaso Gragnato | With your help, the Elves manage to find the right parts and fix all of the mach"><meta name="description" content="Advent of Code 2023 [Day 20] | Pulse Propagation | Tommaso Gragnato | With your help, the Elves manage to find the right parts and fix all of the mach"><meta property="og:description" content="Advent of Code 2023 [Day 20] | Pulse Propagation | Tommaso Gragnato | With your help, the Elves manage to find the right parts and fix all of the mach"><meta name="twitter:description" content="Advent of Code 2023 [Day 20] | Pulse Propagation | Tommaso Gragnato | With your help, the Elves manage to find the right parts and fix all of the mach"><meta property="og:type" content="article"><meta property="og:image" content="https://tgragnato.it/icons/apple-touch-icon-precomposed.png"><meta name="twitter:image" content="https://tgragnato.it/icons/apple-touch-icon-precomposed.png"><meta property="og:url" content="https://tgragnato.it/2023/12/20/Pulse-Propagation.html"><meta property="og:locale" content="en"><link rel="canonical" href="https://tgragnato.it/2023/12/20/Pulse-Propagation.html"><link rel="dns-prefetch" href="https://tgragnato.it/"><link rel="dns-prefetch" href="https://www.tgragnato.it/"><link rel="dns-prefetch" href="https://stun.tgragnato.it/"><link rel="dns-prefetch" href="https://dht.tgragnato.it/"><link rel="dns-prefetch" href="https://static.cloudflareinsights.com/"><link rel="dns-prefetch" href="https://cloudflareinsights.com/"><link rel="dns-prefetch" href="https://github.com/"><link rel="dns-prefetch" href="https://news.ycombinator.com/"><link rel="dns-prefetch" href="https://keys.openpgp.org/"><link rel="dns-prefetch" href="https://gitlab.torproject.org/"><link rel="dns-prefetch" href="https://signal.me/"><link rel="dns-prefetch" href="https://adventofcode.com/"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="preload" href="/style.css" as="style"><link rel="preload" href="/fonts/GrechenFuemen-Regular.woff2" as="font"><link rel="preload" href="/fonts/square-github.svg" as="image"><link rel="preload" href="/fonts/square-hn.svg" as="image"><link rel="preload" href="/fonts/square-linkedin.svg" as="image"><link rel="preload" href="/fonts/tor.svg" as="image"><link rel="preload" href="/fonts/square-signal.svg" as="image"><link rel="stylesheet" href="/style.css"><link rel="icon" type="image/x-icon" href="/icons/favicon.ico"><link rel="apple-touch-icon-precomposed" href="/icons/apple-touch-icon-precomposed.png"><link rel="apple-touch-icon" href="/icons/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="57x57" href="/icons/apple-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="/icons/apple-icon-60x60.png"><link rel="apple-touch-icon" sizes="72x72" href="/icons/apple-icon-72x72.png"><link rel="apple-touch-icon" sizes="76x76" href="/icons/apple-icon-76x76.png"><link rel="apple-touch-icon" sizes="114x114" href="/icons/apple-icon-114x114.png"><link rel="apple-touch-icon" sizes="120x120" href="/icons/apple-icon-120x120.png"><link rel="apple-touch-icon" sizes="144x144" href="/icons/apple-icon-144x144.png"><link rel="apple-touch-icon" sizes="152x152" href="/icons/apple-icon-152x152.png"><link rel="apple-touch-icon" sizes="180x180" href="/icons/apple-icon-180x180.png"><link rel="icon" type="image/png" sizes="16x16" href="/icons/favicon-16x16.png"><link rel="icon" type="image/png" sizes="32x32" href="/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="36x36" href="/icons/android-icon-36x36.png"><link rel="icon" type="image/png" sizes="48x48" href="/icons/android-icon-48x48.png"><link rel="icon" type="image/png" sizes="72x72" href="/icons/android-icon-72x72.png"><link rel="icon" type="image/png" sizes="96x96" href="/icons/favicon-96x96.png"><link rel="icon" type="image/png" sizes="144x144" href="/icons/android-icon-144x144.png"><link rel="icon" type="image/png" sizes="192x192" href="/icons/android-icon-192x192.png"><link rel="manifest" href="/manifest.json"> <script> if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(registration => { console.log('Service Worker registration:', registration); }) .catch(error => { console.log('Service Worker error:', error); }); } </script> <script type="application/ld+json">{ "@context": "https://schema.org", "@type": "BlogPosting", "headline": "Pulse Propagation", "description": "Advent of Code 2023 [Day 20]", "datePublished": "2023-12-20T00:00:00+00:00", "dateModified": "2023-12-20T00:00:00+00:00", "author": [{ "@type": "Person", "name": "Tommaso Gragnato", "url": "https://tgragnato.it/" }] }</script> <script defer="" src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon="{"token": "929b9085cda74c07b2e2976a05c31231"}"></script></head><body><header><h1>Pulse Propagation</h1><p class="subtitle">Advent of Code 2023 [Day 20]</p><p class="subtitle">20-12-2023</p></header><section class="content"><p>With your help, the Elves manage to find the right parts and fix all of the machines. Now, they just need to send the command to boot up the machines and get the sand flowing again.</p><p>The machines are far apart and wired together with long <strong>cables</strong>. The cables don’t connect to the machines directly, but rather to communication <strong>modules</strong> attached to the machines that perform various initialization tasks and also act as communication relays.</p><p>Modules communicate using <strong>pulses</strong>. Each pulse is either a <strong>high pulse</strong> or a <strong>low pulse</strong>. When a module sends a pulse, it sends that type of pulse to each module in its list of <strong>destination modules</strong>.</p><p>There are several different types of modules:</p><p><strong>Flip-flop</strong> modules (prefix <code class="language-plaintext highlighter-rouge">%</code>) are either <strong>on</strong> or <strong>off</strong>; they are initially <strong>off</strong>. If a flip-flop module receives a high pulse, it is ignored and nothing happens. However, if a flip-flop module receives a low pulse, it <strong>flips between on and off</strong>. If it was off, it turns on and sends a high pulse. If it was on, it turns off and sends a low pulse.</p><p><strong>Conjunction</strong> modules (prefix <code class="language-plaintext highlighter-rouge">&</code>) <strong>remember</strong> the type of the most recent pulse received from <strong>each</strong> of their connected input modules; they initially default to remembering a <strong>low pulse</strong> for each input. When a pulse is received, the conjunction module first updates its memory for that input. Then, if it remembers <strong>high pulses</strong> for all inputs, it sends a <strong>low pulse</strong>; otherwise, it sends a <strong>high pulse</strong>.</p><p>There is a single <strong>broadcast module</strong> (named <code class="language-plaintext highlighter-rouge">broadcaster</code>). When it receives a pulse, it sends the same pulse to all of its destination modules.</p><p>Here at Desert Machine Headquarters, there is a module with a single button on it called, aptly, the <strong>button module</strong>. When you push the button, a single <strong>low pulse</strong> is sent directly to the <code class="language-plaintext highlighter-rouge">broadcaster</code> module.</p><p>After pushing the button, you must wait until all pulses have been delivered and fully handled before pushing it again. Never push the button if modules are still processing pulses.</p><p>Pulses are always processed <strong>in the order they are sent</strong>. So, if a pulse is sent to modules <code class="language-plaintext highlighter-rouge">a</code>, <code class="language-plaintext highlighter-rouge">b</code>, and <code class="language-plaintext highlighter-rouge">c</code>, and then module <code class="language-plaintext highlighter-rouge">a</code> processes its pulse and sends more pulses, the pulses sent to modules <code class="language-plaintext highlighter-rouge">b</code> and <code class="language-plaintext highlighter-rouge">c</code> would have to be handled first.</p><p>The module configuration (your puzzle input) lists each module. The name of the module is preceded by a symbol identifying its type, if any. The name is then followed by an arrow and a list of its destination modules. For example:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>broadcaster -> a, b, c
%a -> b
%b -> c
%c -> inv
&inv -> a
</code></pre></div></div><p>In this module configuration, the broadcaster has three destination modules named <code class="language-plaintext highlighter-rouge">a</code>, <code class="language-plaintext highlighter-rouge">b</code>, and <code class="language-plaintext highlighter-rouge">c</code>. Each of these modules is a flip-flop module (as indicated by the <code class="language-plaintext highlighter-rouge">%</code> prefix). <code class="language-plaintext highlighter-rouge">a</code> outputs to <code class="language-plaintext highlighter-rouge">b</code> which outputs to <code class="language-plaintext highlighter-rouge">c</code> which outputs to another module named <code class="language-plaintext highlighter-rouge">inv</code>. <code class="language-plaintext highlighter-rouge">inv</code> is a conjunction module (as indicated by the <code class="language-plaintext highlighter-rouge">&</code> prefix) which, because it has only one input, acts like an inverter (it sends the opposite of the pulse type it receives); it outputs to <code class="language-plaintext highlighter-rouge">a</code>.</p><p>By pushing the button once, the following pulses are sent:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>button -low-> broadcaster
broadcaster -low-> a
broadcaster -low-> b
broadcaster -low-> c
a -high-> b
b -high-> c
c -high-> inv
inv -low-> a
a -low-> b
b -low-> c
c -low-> inv
inv -high-> a
</code></pre></div></div><p>After this sequence, the flip-flop modules all end up <strong>off</strong>, so pushing the button again repeats the same sequence.</p><p>Here’s a more interesting example:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>broadcaster -> a
%a -> inv, con
&inv -> b
%b -> con
&con -> output
</code></pre></div></div><p>This module configuration includes the <code class="language-plaintext highlighter-rouge">broadcaster</code>, two flip-flops (named <code class="language-plaintext highlighter-rouge">a</code> and <code class="language-plaintext highlighter-rouge">b</code>), a single-input conjunction module (<code class="language-plaintext highlighter-rouge">inv</code>), a multi-input conjunction module (<code class="language-plaintext highlighter-rouge">con</code>), and an untyped module named <code class="language-plaintext highlighter-rouge">output</code> (for testing purposes). The multi-input conjunction module <code class="language-plaintext highlighter-rouge">con</code> watches the two flip-flop modules and, if they’re both on, sends a <strong>low pulse</strong> to the <code class="language-plaintext highlighter-rouge">output</code> module.</p><p>Here’s what happens if you push the button once:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>button -low-> broadcaster
broadcaster -low-> a
a -high-> inv
a -high-> con
inv -low-> b
con -high-> output
b -high-> con
con -low-> output
</code></pre></div></div><p>Both flip-flops turn on and a low pulse is sent to <code class="language-plaintext highlighter-rouge">output</code>! However, now that both flip-flops are on and <code class="language-plaintext highlighter-rouge">con</code> remembers a high pulse from each of its two inputs, pushing the button a second time does something different:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>button -low-> broadcaster
broadcaster -low-> a
a -low-> inv
a -low-> con
inv -high-> b
con -high-> output
</code></pre></div></div><p>Flip-flop <code class="language-plaintext highlighter-rouge">a</code> turns off! Now, <code class="language-plaintext highlighter-rouge">con</code> remembers a low pulse from module <code class="language-plaintext highlighter-rouge">a</code>, and so it sends only a high pulse to <code class="language-plaintext highlighter-rouge">output</code>.</p><p>Push the button a third time:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>button -low-> broadcaster
broadcaster -low-> a
a -high-> inv
a -high-> con
inv -low-> b
con -low-> output
b -low-> con
con -high-> output
</code></pre></div></div><p>This time, flip-flop <code class="language-plaintext highlighter-rouge">a</code> turns on, then flip-flop <code class="language-plaintext highlighter-rouge">b</code> turns off. However, before <code class="language-plaintext highlighter-rouge">b</code> can turn off, the pulse sent to <code class="language-plaintext highlighter-rouge">con</code> is handled first, so <strong>it briefly remembers all high pulses</strong> for its inputs and sends a low pulse to <code class="language-plaintext highlighter-rouge">output</code>. After that, flip-flop <code class="language-plaintext highlighter-rouge">b</code> turns off, which causes <code class="language-plaintext highlighter-rouge">con</code> to update its state and send a high pulse to <code class="language-plaintext highlighter-rouge">output</code>.</p><p>Finally, with <code class="language-plaintext highlighter-rouge">a</code> on and <code class="language-plaintext highlighter-rouge">b</code> off, push the button a fourth time:</p><div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>button -low-> broadcaster
broadcaster -low-> a
a -low-> inv
a -low-> con
inv -high-> b
con -high-> output
</code></pre></div></div><p>This completes the cycle: <code class="language-plaintext highlighter-rouge">a</code> turns off, causing <code class="language-plaintext highlighter-rouge">con</code> to remember only low pulses and restoring all modules to their original states.</p><p>To get the cables warmed up, the Elves have pushed the button <code class="language-plaintext highlighter-rouge">1000</code> times. How many pulses got sent as a result (including the pulses sent by the button itself)?</p><p>In the first example, the same thing happens every time the button is pushed: <code class="language-plaintext highlighter-rouge">8</code> low pulses and <code class="language-plaintext highlighter-rouge">4</code> high pulses are sent. So, after pushing the button <code class="language-plaintext highlighter-rouge">1000</code> times, <code class="language-plaintext highlighter-rouge">8000</code> low pulses and <code class="language-plaintext highlighter-rouge">4000</code> high pulses are sent. Multiplying these together gives <code class="language-plaintext highlighter-rouge">32000000</code>.</p><p>In the second example, after pushing the button <code class="language-plaintext highlighter-rouge">1000</code> times, <code class="language-plaintext highlighter-rouge">4250</code> low pulses and <code class="language-plaintext highlighter-rouge">2750</code> high pulses are sent. Multiplying these together gives <code class="language-plaintext highlighter-rouge">11687500</code>.</p><p>Consult your module configuration; determine the number of low pulses and high pulses that would be sent after pushing the button <code class="language-plaintext highlighter-rouge">1000</code> times, waiting for all pulses to be fully handled after each push of the button. <strong>What do you get if you multiply the total number of low pulses sent by the total number of high pulses sent?</strong></p><div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">ModuleType</span> <span class="kt">int</span>
<span class="k">const</span> <span class="p">(</span>
<span class="n">Broadcaster</span> <span class="n">ModuleType</span> <span class="o">=</span> <span class="no">iota</span>
<span class="n">FlipFlop</span>
<span class="n">Conjunction</span>
<span class="p">)</span>
<span class="k">type</span> <span class="n">Pulse</span> <span class="k">struct</span> <span class="p">{</span>
<span class="n">source</span> <span class="kt">string</span>
<span class="n">dest</span> <span class="kt">string</span>
<span class="n">high</span> <span class="kt">bool</span>
<span class="p">}</span>
<span class="k">type</span> <span class="n">Module</span> <span class="k">struct</span> <span class="p">{</span>
<span class="n">name</span> <span class="kt">string</span>
<span class="n">mtype</span> <span class="n">ModuleType</span>
<span class="n">destinations</span> <span class="p">[]</span><span class="kt">string</span>
<span class="n">state</span> <span class="kt">bool</span>
<span class="n">memory</span> <span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">bool</span>
<span class="p">}</span>
<span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
<span class="n">modules</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="o">*</span><span class="n">Module</span><span class="p">)</span>
<span class="n">file</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">os</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="s">"input.txt"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
<span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">err</span><span class="o">.</span><span class="n">Error</span><span class="p">())</span>
<span class="n">os</span><span class="o">.</span><span class="n">Exit</span><span class="p">(</span><span class="m">1</span><span class="p">)</span>
<span class="p">}</span>
<span class="k">defer</span> <span class="n">file</span><span class="o">.</span><span class="n">Close</span><span class="p">()</span>
<span class="n">scanner</span> <span class="o">:=</span> <span class="n">bufio</span><span class="o">.</span><span class="n">NewScanner</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">for</span> <span class="n">scanner</span><span class="o">.</span><span class="n">Scan</span><span class="p">()</span> <span class="p">{</span>
<span class="n">line</span> <span class="o">:=</span> <span class="n">scanner</span><span class="o">.</span><span class="n">Text</span><span class="p">()</span>
<span class="n">parts</span> <span class="o">:=</span> <span class="n">strings</span><span class="o">.</span><span class="n">Split</span><span class="p">(</span><span class="n">line</span><span class="p">,</span> <span class="s">" -> "</span><span class="p">)</span>
<span class="n">name</span> <span class="o">:=</span> <span class="n">parts</span><span class="p">[</span><span class="m">0</span><span class="p">]</span>
<span class="n">dests</span> <span class="o">:=</span> <span class="n">strings</span><span class="o">.</span><span class="n">Split</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="m">1</span><span class="p">],</span> <span class="s">", "</span><span class="p">)</span>
<span class="k">var</span> <span class="n">m</span> <span class="n">Module</span>
<span class="n">m</span><span class="o">.</span><span class="n">destinations</span> <span class="o">=</span> <span class="n">dests</span>
<span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">"broadcaster"</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">Broadcaster</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="n">name</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'%'</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">FlipFlop</span>
<span class="n">m</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="no">false</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="n">name</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'&'</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">Conjunction</span>
<span class="n">m</span><span class="o">.</span><span class="n">memory</span> <span class="o">=</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">bool</span><span class="p">)</span>
<span class="p">}</span>
<span class="n">modules</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">&</span><span class="n">m</span>
<span class="p">}</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">module</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">modules</span> <span class="p">{</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="k">if</span> <span class="n">m</span><span class="p">,</span> <span class="n">exists</span> <span class="o">:=</span> <span class="n">modules</span><span class="p">[</span><span class="n">dest</span><span class="p">];</span> <span class="n">exists</span> <span class="o">&&</span> <span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">==</span> <span class="n">Conjunction</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">memory</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="no">false</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">lowCount</span><span class="p">,</span> <span class="n">highCount</span> <span class="o">:=</span> <span class="m">0</span><span class="p">,</span> <span class="m">0</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">:=</span> <span class="m">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="m">1000</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">:=</span> <span class="p">[]</span><span class="n">Pulse</span>
<span class="k">for</span> <span class="nb">len</span><span class="p">(</span><span class="n">queue</span><span class="p">)</span> <span class="o">></span> <span class="m">0</span> <span class="p">{</span>
<span class="n">pulse</span> <span class="o">:=</span> <span class="n">queue</span><span class="p">[</span><span class="m">0</span><span class="p">]</span>
<span class="n">queue</span> <span class="o">=</span> <span class="n">queue</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="k">if</span> <span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="p">{</span>
<span class="n">highCount</span><span class="o">++</span>
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
<span class="n">lowCount</span><span class="o">++</span>
<span class="p">}</span>
<span class="n">module</span><span class="p">,</span> <span class="n">exists</span> <span class="o">:=</span> <span class="n">modules</span><span class="p">[</span><span class="n">pulse</span><span class="o">.</span><span class="n">dest</span><span class="p">]</span>
<span class="k">if</span> <span class="o">!</span><span class="n">exists</span> <span class="p">{</span>
<span class="k">continue</span>
<span class="p">}</span>
<span class="k">switch</span> <span class="n">module</span><span class="o">.</span><span class="n">mtype</span> <span class="p">{</span>
<span class="k">case</span> <span class="n">Broadcaster</span><span class="o">:</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="n">pulse</span><span class="o">.</span><span class="n">high</span><span class="p">})</span>
<span class="p">}</span>
<span class="k">case</span> <span class="n">FlipFlop</span><span class="o">:</span>
<span class="k">if</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="p">{</span>
<span class="n">module</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="o">!</span><span class="n">module</span><span class="o">.</span><span class="n">state</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">state</span><span class="p">})</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">case</span> <span class="n">Conjunction</span><span class="o">:</span>
<span class="n">module</span><span class="o">.</span><span class="n">memory</span><span class="p">[</span><span class="n">pulse</span><span class="o">.</span><span class="n">source</span><span class="p">]</span> <span class="o">=</span> <span class="n">pulse</span><span class="o">.</span><span class="n">high</span>
<span class="n">allHigh</span> <span class="o">:=</span> <span class="no">true</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">high</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">memory</span> <span class="p">{</span>
<span class="k">if</span> <span class="o">!</span><span class="n">high</span> <span class="p">{</span>
<span class="n">allHigh</span> <span class="o">=</span> <span class="no">false</span>
<span class="k">break</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="o">!</span><span class="n">allHigh</span><span class="p">})</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">fmt</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"Result: %d</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">lowCount</span><span class="o">*</span><span class="n">highCount</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div><p>The final machine responsible for moving the sand down to Island Island has a module attached named <code class="language-plaintext highlighter-rouge">rx</code>. The machine turns on when a <strong>single low pulse</strong> is sent to <code class="language-plaintext highlighter-rouge">rx</code>.</p><p>Reset all modules to their default states. Waiting for all pulses to be fully handled after each button press, <strong>what is the fewest number of button presses required to deliver a single low pulse to the module named rx?</strong></p><div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">ModuleType</span> <span class="kt">int</span>
<span class="k">const</span> <span class="p">(</span>
<span class="n">Broadcaster</span> <span class="n">ModuleType</span> <span class="o">=</span> <span class="no">iota</span>
<span class="n">FlipFlop</span>
<span class="n">Conjunction</span>
<span class="p">)</span>
<span class="k">type</span> <span class="n">Pulse</span> <span class="k">struct</span> <span class="p">{</span>
<span class="n">source</span> <span class="kt">string</span>
<span class="n">dest</span> <span class="kt">string</span>
<span class="n">high</span> <span class="kt">bool</span>
<span class="p">}</span>
<span class="k">type</span> <span class="n">Module</span> <span class="k">struct</span> <span class="p">{</span>
<span class="n">name</span> <span class="kt">string</span>
<span class="n">mtype</span> <span class="n">ModuleType</span>
<span class="n">destinations</span> <span class="p">[]</span><span class="kt">string</span>
<span class="n">state</span> <span class="kt">bool</span>
<span class="n">memory</span> <span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">bool</span>
<span class="p">}</span>
<span class="k">func</span> <span class="n">GCD</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="kt">int</span><span class="p">)</span> <span class="kt">int</span> <span class="p">{</span>
<span class="k">for</span> <span class="n">b</span> <span class="o">!=</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">t</span> <span class="o">:=</span> <span class="n">b</span>
<span class="n">b</span> <span class="o">=</span> <span class="n">a</span> <span class="o">%</span> <span class="n">b</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">t</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">a</span>
<span class="p">}</span>
<span class="k">func</span> <span class="n">LCM</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="kt">int</span><span class="p">,</span> <span class="n">integers</span> <span class="o">...</span><span class="kt">int</span><span class="p">)</span> <span class="kt">int</span> <span class="p">{</span>
<span class="n">result</span> <span class="o">:=</span> <span class="n">a</span> <span class="o">*</span> <span class="n">b</span> <span class="o">/</span> <span class="n">GCD</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
<span class="k">for</span> <span class="n">i</span> <span class="o">:=</span> <span class="m">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="nb">len</span><span class="p">(</span><span class="n">integers</span><span class="p">);</span> <span class="n">i</span><span class="o">++</span> <span class="p">{</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">LCM</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">integers</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
<span class="p">}</span>
<span class="k">return</span> <span class="n">result</span>
<span class="p">}</span>
<span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
<span class="n">modules</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="o">*</span><span class="n">Module</span><span class="p">)</span>
<span class="n">initialStates</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="o">*</span><span class="n">Module</span><span class="p">)</span>
<span class="n">file</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">os</span><span class="o">.</span><span class="n">Open</span><span class="p">(</span><span class="s">"input.txt"</span><span class="p">)</span>
<span class="k">if</span> <span class="n">err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
<span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">err</span><span class="o">.</span><span class="n">Error</span><span class="p">())</span>
<span class="n">os</span><span class="o">.</span><span class="n">Exit</span><span class="p">(</span><span class="m">1</span><span class="p">)</span>
<span class="p">}</span>
<span class="k">defer</span> <span class="n">file</span><span class="o">.</span><span class="n">Close</span><span class="p">()</span>
<span class="n">scanner</span> <span class="o">:=</span> <span class="n">bufio</span><span class="o">.</span><span class="n">NewScanner</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">for</span> <span class="n">scanner</span><span class="o">.</span><span class="n">Scan</span><span class="p">()</span> <span class="p">{</span>
<span class="n">line</span> <span class="o">:=</span> <span class="n">scanner</span><span class="o">.</span><span class="n">Text</span><span class="p">()</span>
<span class="n">parts</span> <span class="o">:=</span> <span class="n">strings</span><span class="o">.</span><span class="n">Split</span><span class="p">(</span><span class="n">line</span><span class="p">,</span> <span class="s">" -> "</span><span class="p">)</span>
<span class="n">name</span> <span class="o">:=</span> <span class="n">parts</span><span class="p">[</span><span class="m">0</span><span class="p">]</span>
<span class="n">dests</span> <span class="o">:=</span> <span class="n">strings</span><span class="o">.</span><span class="n">Split</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="m">1</span><span class="p">],</span> <span class="s">", "</span><span class="p">)</span>
<span class="k">var</span> <span class="n">m</span> <span class="n">Module</span>
<span class="n">m</span><span class="o">.</span><span class="n">destinations</span> <span class="o">=</span> <span class="n">dests</span>
<span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s">"broadcaster"</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">Broadcaster</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="n">name</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'%'</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">FlipFlop</span>
<span class="n">m</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="no">false</span>
<span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="n">name</span><span class="p">[</span><span class="m">0</span><span class="p">]</span> <span class="o">==</span> <span class="sc">'&'</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">=</span> <span class="n">Conjunction</span>
<span class="n">m</span><span class="o">.</span><span class="n">memory</span> <span class="o">=</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">bool</span><span class="p">)</span>
<span class="p">}</span>
<span class="n">modules</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">&</span><span class="n">m</span>
<span class="n">initialStates</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="o">&</span><span class="n">Module</span><span class="p">{</span>
<span class="n">name</span><span class="o">:</span> <span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="n">mtype</span><span class="o">:</span> <span class="n">m</span><span class="o">.</span><span class="n">mtype</span><span class="p">,</span>
<span class="n">destinations</span><span class="o">:</span> <span class="nb">append</span><span class="p">([]</span><span class="kt">string</span><span class="p">{},</span> <span class="n">m</span><span class="o">.</span><span class="n">destinations</span><span class="o">...</span><span class="p">),</span>
<span class="n">state</span><span class="o">:</span> <span class="n">m</span><span class="o">.</span><span class="n">state</span><span class="p">,</span>
<span class="n">memory</span><span class="o">:</span> <span class="nb">make</span><span class="p">(</span><span class="k">map</span><span class="p">[</span><span class="kt">string</span><span class="p">]</span><span class="kt">bool</span><span class="p">),</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">m</span><span class="o">.</span><span class="n">memory</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">m</span><span class="o">.</span><span class="n">memory</span> <span class="p">{</span>
<span class="n">initialStates</span><span class="p">[</span><span class="n">m</span><span class="o">.</span><span class="n">name</span><span class="p">]</span><span class="o">.</span><span class="n">memory</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">v</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">module</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">modules</span> <span class="p">{</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="k">if</span> <span class="n">m</span><span class="p">,</span> <span class="n">exists</span> <span class="o">:=</span> <span class="n">modules</span><span class="p">[</span><span class="n">dest</span><span class="p">];</span> <span class="n">exists</span> <span class="o">&&</span> <span class="n">m</span><span class="o">.</span><span class="n">mtype</span> <span class="o">==</span> <span class="n">Conjunction</span> <span class="p">{</span>
<span class="n">m</span><span class="o">.</span><span class="n">memory</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="no">false</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="n">lk</span> <span class="o">:=</span> <span class="m">0</span>
<span class="n">zv</span> <span class="o">:=</span> <span class="m">0</span>
<span class="n">sp</span> <span class="o">:=</span> <span class="m">0</span>
<span class="n">xt</span> <span class="o">:=</span> <span class="m">0</span>
<span class="n">buttonPresses</span> <span class="o">:=</span> <span class="m">0</span>
<span class="k">for</span> <span class="p">{</span>
<span class="n">buttonPresses</span><span class="o">++</span>
<span class="n">queue</span> <span class="o">:=</span> <span class="p">[]</span><span class="n">Pulse</span>
<span class="k">for</span> <span class="nb">len</span><span class="p">(</span><span class="n">queue</span><span class="p">)</span> <span class="o">></span> <span class="m">0</span> <span class="p">{</span>
<span class="n">pulse</span> <span class="o">:=</span> <span class="n">queue</span><span class="p">[</span><span class="m">0</span><span class="p">]</span>
<span class="n">queue</span> <span class="o">=</span> <span class="n">queue</span><span class="p">[</span><span class="m">1</span><span class="o">:</span><span class="p">]</span>
<span class="k">if</span> <span class="n">pulse</span><span class="o">.</span><span class="n">dest</span> <span class="o">==</span> <span class="s">"lk"</span> <span class="o">&&</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="o">&&</span> <span class="n">lk</span> <span class="o">==</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">lk</span> <span class="o">=</span> <span class="n">buttonPresses</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">pulse</span><span class="o">.</span><span class="n">dest</span> <span class="o">==</span> <span class="s">"zv"</span> <span class="o">&&</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="o">&&</span> <span class="n">zv</span> <span class="o">==</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">zv</span> <span class="o">=</span> <span class="n">buttonPresses</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">pulse</span><span class="o">.</span><span class="n">dest</span> <span class="o">==</span> <span class="s">"sp"</span> <span class="o">&&</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="o">&&</span> <span class="n">sp</span> <span class="o">==</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">sp</span> <span class="o">=</span> <span class="n">buttonPresses</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">pulse</span><span class="o">.</span><span class="n">dest</span> <span class="o">==</span> <span class="s">"xt"</span> <span class="o">&&</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="o">&&</span> <span class="n">xt</span> <span class="o">==</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">xt</span> <span class="o">=</span> <span class="n">buttonPresses</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">lk</span> <span class="o">!=</span> <span class="m">0</span> <span class="o">&&</span> <span class="n">zv</span> <span class="o">!=</span> <span class="m">0</span> <span class="o">&&</span> <span class="n">sp</span> <span class="o">!=</span> <span class="m">0</span> <span class="o">&&</span> <span class="n">xt</span> <span class="o">!=</span> <span class="m">0</span> <span class="p">{</span>
<span class="n">fmt</span><span class="o">.</span><span class="n">Println</span><span class="p">(</span><span class="n">lk</span><span class="p">,</span> <span class="n">zv</span><span class="p">,</span> <span class="n">sp</span><span class="p">,</span> <span class="n">xt</span><span class="p">,</span> <span class="n">LCM</span><span class="p">(</span><span class="n">lk</span><span class="p">,</span> <span class="n">zv</span><span class="p">,</span> <span class="n">sp</span><span class="p">,</span> <span class="n">xt</span><span class="p">))</span>
<span class="k">return</span>
<span class="p">}</span>
<span class="n">module</span><span class="p">,</span> <span class="n">exists</span> <span class="o">:=</span> <span class="n">modules</span><span class="p">[</span><span class="n">pulse</span><span class="o">.</span><span class="n">dest</span><span class="p">]</span>
<span class="k">if</span> <span class="o">!</span><span class="n">exists</span> <span class="p">{</span>
<span class="k">continue</span>
<span class="p">}</span>
<span class="k">switch</span> <span class="n">module</span><span class="o">.</span><span class="n">mtype</span> <span class="p">{</span>
<span class="k">case</span> <span class="n">Broadcaster</span><span class="o">:</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="n">pulse</span><span class="o">.</span><span class="n">high</span><span class="p">})</span>
<span class="p">}</span>
<span class="k">case</span> <span class="n">FlipFlop</span><span class="o">:</span>
<span class="k">if</span> <span class="o">!</span><span class="n">pulse</span><span class="o">.</span><span class="n">high</span> <span class="p">{</span>
<span class="n">module</span><span class="o">.</span><span class="n">state</span> <span class="o">=</span> <span class="o">!</span><span class="n">module</span><span class="o">.</span><span class="n">state</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">state</span><span class="p">})</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">case</span> <span class="n">Conjunction</span><span class="o">:</span>
<span class="n">module</span><span class="o">.</span><span class="n">memory</span><span class="p">[</span><span class="n">pulse</span><span class="o">.</span><span class="n">source</span><span class="p">]</span> <span class="o">=</span> <span class="n">pulse</span><span class="o">.</span><span class="n">high</span>
<span class="n">allHigh</span> <span class="o">:=</span> <span class="no">true</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">high</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">memory</span> <span class="p">{</span>
<span class="k">if</span> <span class="o">!</span><span class="n">high</span> <span class="p">{</span>
<span class="n">allHigh</span> <span class="o">=</span> <span class="no">false</span>
<span class="k">break</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="k">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">dest</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">module</span><span class="o">.</span><span class="n">destinations</span> <span class="p">{</span>
<span class="n">queue</span> <span class="o">=</span> <span class="nb">append</span><span class="p">(</span><span class="n">queue</span><span class="p">,</span> <span class="n">Pulse</span><span class="p">{</span><span class="n">source</span><span class="o">:</span> <span class="n">module</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">dest</span><span class="o">:</span> <span class="n">dest</span><span class="p">,</span> <span class="n">high</span><span class="o">:</span> <span class="o">!</span><span class="n">allHigh</span><span class="p">})</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div><h2 id="links">Links</h2><p><a href="https://adventofcode.com/2023/day/20">If you’re new to Advent of Code, it’s an annual event that takes place throughout December, featuring a series of programming puzzles that get progressively more challenging as Christmas approaches.</a></p><details> <summary>Click to show the input</summary><pre>%hs -> sl
&dg -> rx
%vp -> fd, dv
%kz -> jc, mc
%nv -> dv
%hx -> gf
%mm -> vh
%fd -> td
&dv -> hx, bl, rc, fd, xt
%hg -> xq
%td -> dv, hx
%bl -> jt
%br -> jq
%qh -> ln
&xq -> zl, cx, qh, hs, nt, sp
%sg -> vv, tr
%dm -> bl, dv
%gt -> xq, hg
%ln -> mq, xq
%mc -> xv, jc
%tx -> rv, jc
&lk -> dg
%mg -> hl, jc
&vv -> zv, br, kx, mm, tr
%nt -> xq, cx
&zv -> dg
%cd -> jc, ps
%rc -> rm, dv
%nj -> pt, xq
broadcaster -> nt, kx, rc, mg
%gf -> dc, dv
%rm -> dm, dv
%xx -> vv, cz
%jt -> dv, vp
%zl -> nj
&sp -> dg
%xc -> jc, kz
&xt -> dg
%tp -> jc
%lc -> vv, vn
%vh -> xx, vv
%mq -> hs, xq
%cc -> vv
%vn -> vv, cc
%tr -> br
%hl -> qb, jc
%dc -> dv, nv
%jq -> mm, vv
%kx -> vv, sg
%cx -> qh
%sl -> zl, xq
%cz -> lc, vv
%qb -> jc, cd
&jc -> ps, xv, lk, mg
%xv -> tx
%pt -> xq, gt
%rv -> jc, tp
%ps -> xc
</pre></details></section><footer><div itemscope="" itemtype="https://schema.org/BreadcrumbList"><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/"><span itemprop="name">日付不明 - <code class="language-plaintext highlighter-rouge">tgragnato.it - Tommaso Gragnato</code> - Homepage</span></a><meta itemprop="position" content="1"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/snippets.html"><span itemprop="name">日付不明 - <code class="language-plaintext highlighter-rouge">Snippets / Gists</code> - Welcome to the Chronicles of Nonchalance!</span></a><meta itemprop="position" content="2"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/10/Hoof-It.html"><span itemprop="name">10-12-2024 - <code class="language-plaintext highlighter-rouge">Hoof It</code> - Advent of Code 2024 [Day 10]</span></a><meta itemprop="position" content="3"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/09/Disk-Fragmenter.html"><span itemprop="name">09-12-2024 - <code class="language-plaintext highlighter-rouge">Disk Fragmenter</code> - Advent of Code 2024 [Day 9]</span></a><meta itemprop="position" content="4"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/08/Resonant-Collinearity.html"><span itemprop="name">08-12-2024 - <code class="language-plaintext highlighter-rouge">Resonant Collinearity</code> - Advent of Code 2024 [Day 8]</span></a><meta itemprop="position" content="5"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/07/Bridge-Repair.html"><span itemprop="name">07-12-2024 - <code class="language-plaintext highlighter-rouge">Bridge Repair</code> - Advent of Code 2024 [Day 7]</span></a><meta itemprop="position" content="6"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/06/Guard-Gallivant.html"><span itemprop="name">06-12-2024 - <code class="language-plaintext highlighter-rouge">Guard Gallivant</code> - Advent of Code 2024 [Day 6]</span></a><meta itemprop="position" content="7"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/05/Print-Queue.html"><span itemprop="name">05-12-2024 - <code class="language-plaintext highlighter-rouge">Print Queue</code> - Advent of Code 2024 [Day 5]</span></a><meta itemprop="position" content="8"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/04/Ceres-Search.html"><span itemprop="name">04-12-2024 - <code class="language-plaintext highlighter-rouge">Ceres Search</code> - Advent of Code 2024 [Day 4]</span></a><meta itemprop="position" content="9"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/03/Mull-It-Over.html"><span itemprop="name">03-12-2024 - <code class="language-plaintext highlighter-rouge">Mull It Over</code> - Advent of Code 2024 [Day 3]</span></a><meta itemprop="position" content="10"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/02/Red-Nosed-Reports.html"><span itemprop="name">02-12-2024 - <code class="language-plaintext highlighter-rouge">Red-Nosed Reports</code> - Advent of Code 2024 [Day 2]</span></a><meta itemprop="position" content="11"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/12/01/Historian-Hysteria.html"><span itemprop="name">01-12-2024 - <code class="language-plaintext highlighter-rouge">Historian Hysteria</code> - Advent of Code 2024 [Day 1]</span></a><meta itemprop="position" content="12"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/10/31/usenix-srecon24.html"><span itemprop="name">31-10-2024 - <code class="language-plaintext highlighter-rouge">USENIX SREcon24 Europe/Middle East/Africa</code> - 29-31 Oct 2024 The Convention Centre Dublin</span></a><meta itemprop="position" content="13"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/10/20/Risks.html"><span itemprop="name">20-10-2024 - <code class="language-plaintext highlighter-rouge">Risks</code> - The dichotomy that exists between genius and the solitude of failure</span></a><meta itemprop="position" content="14"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/09/08/Covert-Communications.html"><span itemprop="name">08-09-2024 - <code class="language-plaintext highlighter-rouge">US Covert Communications</code> - Channels uncovered by the counter intelligence of Iran, Russia and China</span></a><meta itemprop="position" content="15"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/07/22/WeAreDevelopers.html"><span itemprop="name">22-07-2024 - <code class="language-plaintext highlighter-rouge">We Are Developers 2024</code> - 17-19 Jul 2024 Messe Berlin</span></a><meta itemprop="position" content="16"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/07/05/BPF-HTTP-Replay.html"><span itemprop="name">05-07-2024 - <code class="language-plaintext highlighter-rouge">BPF HTTP Replay</code> - Midpoint network interception for HTTP traffic mirroring</span></a><meta itemprop="position" content="17"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2024/05/14/DxDay.html"><span itemprop="name">14-05-2024 - <code class="language-plaintext highlighter-rouge">DxDay 2024 (1st edition)</code> - Bologna - Hotel Savoia Regency</span></a><meta itemprop="position" content="18"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/19/Aplenty.html"><span itemprop="name">19-12-2023 - <code class="language-plaintext highlighter-rouge">Aplenty</code> - Advent of Code 2023 [Day 19]</span></a><meta itemprop="position" content="19"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/18/Lavaduct-Lagoon.html"><span itemprop="name">18-12-2023 - <code class="language-plaintext highlighter-rouge">Lavaduct Lagoon</code> - Advent of Code 2023 [Day 18]</span></a><meta itemprop="position" content="20"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/17/Clumsy-Crucible.html"><span itemprop="name">17-12-2023 - <code class="language-plaintext highlighter-rouge">Clumsy Crucible</code> - Advent of Code 2023 [Day 17]</span></a><meta itemprop="position" content="21"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/16/The-Floor-Will-Be-Lava.html"><span itemprop="name">16-12-2023 - <code class="language-plaintext highlighter-rouge">The Floor Will Be Lava</code> - Advent of Code 2023 [Day 16]</span></a><meta itemprop="position" content="22"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/15/Lens-Library.html"><span itemprop="name">15-12-2023 - <code class="language-plaintext highlighter-rouge">Lens Library</code> - Advent of Code 2023 [Day 15]</span></a><meta itemprop="position" content="23"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/14/Parabolic-Reflector-Dish.html"><span itemprop="name">14-12-2023 - <code class="language-plaintext highlighter-rouge">Parabolic Reflector Dish</code> - Advent of Code 2023 [Day 14]</span></a><meta itemprop="position" content="24"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/13/Point-Of-Incidence.html"><span itemprop="name">13-12-2023 - <code class="language-plaintext highlighter-rouge">Point Of Incidence</code> - Advent of Code 2023 [Day 13]</span></a><meta itemprop="position" content="25"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/12/Hot-Springs.html"><span itemprop="name">12-12-2023 - <code class="language-plaintext highlighter-rouge">Hot Springs</code> - Advent of Code 2023 [Day 12]</span></a><meta itemprop="position" content="26"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/11/Cosmic-Expansion.html"><span itemprop="name">11-12-2023 - <code class="language-plaintext highlighter-rouge">Cosmic Expansion</code> - Advent of Code 2023 [Day 11]</span></a><meta itemprop="position" content="27"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/09/Mirage-Maintenance.html"><span itemprop="name">09-12-2023 - <code class="language-plaintext highlighter-rouge">Mirage Maintenance</code> - Advent of Code 2023 [Day 9]</span></a><meta itemprop="position" content="28"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/08/Haunted-Wasteland.html"><span itemprop="name">08-12-2023 - <code class="language-plaintext highlighter-rouge">Haunted Wasteland</code> - Advent of Code 2023 [Day 8]</span></a><meta itemprop="position" content="29"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/07/Camel-Cards.html"><span itemprop="name">07-12-2023 - <code class="language-plaintext highlighter-rouge">Camel Cards</code> - Advent of Code 2023 [Day 7]</span></a><meta itemprop="position" content="30"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/06/Wait-For-It.html"><span itemprop="name">06-12-2023 - <code class="language-plaintext highlighter-rouge">Wait For It</code> - Advent of Code 2023 [Day 6]</span></a><meta itemprop="position" content="31"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/05/If-You-Give-A-Seed-A-Fertilizer.html"><span itemprop="name">05-12-2023 - <code class="language-plaintext highlighter-rouge">If You Give A Seed A Fertilizer</code> - Advent of Code 2023 [Day 5]</span></a><meta itemprop="position" content="32"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/04/Scratchcards.html"><span itemprop="name">04-12-2023 - <code class="language-plaintext highlighter-rouge">Scratchcards</code> - Advent of Code 2023 [Day 4]</span></a><meta itemprop="position" content="33"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/03/Gear-Ratios.html"><span itemprop="name">03-12-2023 - <code class="language-plaintext highlighter-rouge">Gear Ratios</code> - Advent of Code 2023 [Day 3]</span></a><meta itemprop="position" content="34"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/02/Cube-Conundrum.html"><span itemprop="name">02-12-2023 - <code class="language-plaintext highlighter-rouge">Cube Conundrum</code> - Advent of Code 2023 [Day 2]</span></a><meta itemprop="position" content="35"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/12/01/Trebuchet.html"><span itemprop="name">01-12-2023 - <code class="language-plaintext highlighter-rouge">Trebuchet?!</code> - Advent of Code 2023 [Day 1]</span></a><meta itemprop="position" content="36"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/09/20/ebmbtreebench.html"><span itemprop="name">20-09-2023 - <code class="language-plaintext highlighter-rouge">EBMBTreeBench</code> - a naive measurement tool for ebmb trees</span></a><meta itemprop="position" content="37"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/08/20/n5105-j6413.html"><span itemprop="name">20-08-2023 - <code class="language-plaintext highlighter-rouge">Topton N5105 e Kingnovy J6413</code> - Due schede efficienti e potenti, con un mucchio di porte</span></a><meta itemprop="position" content="38"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/06/04/Cloudflare-SEO.html"><span itemprop="name">04-06-2023 - <code class="language-plaintext highlighter-rouge">Fondamenti SEO con Cloudflare</code> - Una guida completa su come Cloudflare può migliorare la SEO del tuo sito web</span></a><meta itemprop="position" content="39"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/03/26/memory.html"><span itemprop="name">26-03-2023 - <code class="language-plaintext highlighter-rouge">Browser's "memory management"</code> - A common memory leak in JS engines</span></a><meta itemprop="position" content="40"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2023/03/12/Micro-Miniature.html"><span itemprop="name">12-03-2023 - <code class="language-plaintext highlighter-rouge">Микро Миниатюра / Micro Miniatura</code> - Транзисторные Усилители / Amplificatori e Transistor</span></a><meta itemprop="position" content="41"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2022/12/07/APIs.html"><span itemprop="name">07-12-2022 - <code class="language-plaintext highlighter-rouge">Application Programming Interface</code> - We followed your API documentation to the letter!</span></a><meta itemprop="position" content="42"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2022/10/03/apple-silicon-decompilation.html"><span itemprop="name">03-10-2022 - <code class="language-plaintext highlighter-rouge">Apple Silicon Decompilation</code> - When you wish you didn't know how to use a decompiler</span></a><meta itemprop="position" content="43"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2022/09/06/pilsung.html"><span itemprop="name">06-09-2022 - <code class="language-plaintext highlighter-rouge">붉은별 사용자용체계</code> - pilsung 암호화 알고리즘</span></a><meta itemprop="position" content="44"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2020/08/27/Geiger.html"><span itemprop="name">27-08-2020 - <code class="language-plaintext highlighter-rouge">Geiger Counter</code> - A nuclear side project</span></a><meta itemprop="position" content="45"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2019/12/28/grizzly-steppe.html"><span itemprop="name">28-12-2019 - <code class="language-plaintext highlighter-rouge">Grizzly Steppe</code> - Samples from Russian cyber operations</span></a><meta itemprop="position" content="46"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2018/07/13/traffic-analysis.html"><span itemprop="name">13-07-2018 - <code class="language-plaintext highlighter-rouge">Traffic Analysis</code> - Exfiltrating (meta)data while minimising lateral movements</span></a><meta itemprop="position" content="47"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2018/07/01/dlink-botnet.html"><span itemprop="name">01-07-2018 - <code class="language-plaintext highlighter-rouge">D-Link botnet</code> - Extracting binaries from a botnet of compromised NAS devices</span></a><meta itemprop="position" content="48"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2018/05/10/FASTGate-RCE.html"><span itemprop="name">10-05-2018 - <code class="language-plaintext highlighter-rouge">FASTGate-RCE</code> - Abusing DNS to exploit a command injection and obtain root</span></a><meta itemprop="position" content="49"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2017/05/14/DNS323-Toolchain.html"><span itemprop="name">14-05-2017 - <code class="language-plaintext highlighter-rouge">D-Link DNS-323 toolchain</code> - An in-depth guide for DNS-323 hacking with patches, binaries, and helpful resources</span></a><meta itemprop="position" content="50"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2017/03/23/integrity-check.html"><span itemprop="name">23-03-2017 - <code class="language-plaintext highlighter-rouge">macOS firmware integrity check</code> - Looking how Apple's security features are implemented across architectures</span></a><meta itemprop="position" content="51"></p><p itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="/2015/06/24/sudoku.html"><span itemprop="name">24-06-2015 - <code class="language-plaintext highlighter-rouge">Generatore di sudoku in coffeescript</code> - Permutazioni, rimozione validazione e backtracking</span></a><meta itemprop="position" content="52"></p><hr></div><div class="columns is-mobile"><div class="column"> <a href="https://github.com/tgragnato"> <img class="image is-32x32 m-auto" src="/fonts/square-github.svg" alt="GitHub" loading="lazy"> </a></div><div class="column"> <a href="https://linkedin.com/in/tgragnato"> <img class="image is-32x32 m-auto" src="/fonts/square-linkedin.svg" alt="LinkedIn" loading="lazy"> </a></div><div class="column"> <a href="https://news.ycombinator.com/user?id=tg180"> <img class="image is-32x32 m-auto" src="/fonts/square-hn.svg" alt="Hacker News" loading="lazy"> </a></div><div class="column"> <a href="https://gitlab.torproject.org/tgragnato"> <img class="image is-32x32 m-auto" src="/fonts/tor.svg" alt="Tor Project" loading="lazy"> </a></div><div class="column"> <a href="https://signal.me/#eu/iN-evzfy1ywTQ4WRFeumNrXHYS90EdCWyu_3MT8AzGf46ktEL0RC-ZJnbaow6UD4"> <img class="image is-32x32 m-auto" src="/fonts/square-signal.svg" alt="Signal" loading="lazy"> </a></div></div></footer>
</body></html>