<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
  <id>https://inesiscosta.com/writing</id>
  <title>Inês Costa — Writing</title>
  <subtitle>Technical deep dives, things I&apos;ve learned, and the occasional write-up about something I&apos;ve built.</subtitle>
  <updated>2026-11-14T00:00:00.000Z</updated>
  <author>
    <name>Inês Costa</name>
    <uri>https://inesiscosta.com</uri>
  </author>
  <link rel="self" type="application/atom+xml" href="https://inesiscosta.com/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://inesiscosta.com/writing"/>
  <entry>
    <id>https://inesiscosta.com/writing/nuruomino</id>
    <title>LITS (ヌルオミノ) Solver</title>
    <link rel="alternate" type="text/html" href="https://inesiscosta.com/writing/nuruomino"/>
    <published>2026-11-14T00:00:00.000Z</published>
    <updated>2026-11-14T00:00:00.000Z</updated>
    <summary>A LITS puzzle solver using depth-first search, constraint propagation, and forward checking.</summary>
    <category term="Algorithms"/>
    <category term="AI"/>
    <category term="Python"/>
    <content type="html" xml:base="https://inesiscosta.com/writing/nuruomino">&lt;p&gt;LITS, formerly known as Nuruomino &lt;span lang=&quot;ja&quot; style=&quot;white-space: nowrap&quot;&gt;(ヌルオミノ)&lt;/span&gt;, is a binary determination puzzle published by Nikoli: the grid is cut into regions, and every region must hold exactly one tetromino. Below are the rules, a board to play on, and how the solver we built for our Artificial Intelligence class tackles this NP-hard problem.&lt;small&gt;(At least as hard as every problem in NP, so no known algorithm solves every puzzle quickly. Deciding whether a LITS grid has a solution is NP-complete, as &lt;a href=&quot;https://itn-web.it.liu.se/~chrsc91/papers/norinori-lits.pdf&quot;&gt;Biro and Schmidt&lt;/a&gt; proved (EuroCG 2017).)&lt;/small&gt;&lt;/p&gt; &lt;h2 id=&quot;the-puzzle&quot;&gt;The puzzle&lt;/h2&gt; &lt;p&gt;Shade exactly four connected cells in every region so that each region holds one tetromino. Pieces may be rotated and flipped, so there are only four shapes&lt;small&gt;(&lt;svg class=&quot;o-piece svelte-1jedj87&quot; viewBox=&quot;0 0 42 42&quot; role=&quot;img&quot; aria-label=&quot;The O tetromino: a 2 by 2 square&quot;&gt;&lt;rect x=&quot;1&quot; y=&quot;1&quot; width=&quot;19&quot; height=&quot;19&quot; rx=&quot;3&quot; class=&quot;svelte-1jedj87&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;22&quot; y=&quot;1&quot; width=&quot;19&quot; height=&quot;19&quot; rx=&quot;3&quot; class=&quot;svelte-1jedj87&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1&quot; y=&quot;22&quot; width=&quot;19&quot; height=&quot;19&quot; rx=&quot;3&quot; class=&quot;svelte-1jedj87&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;22&quot; y=&quot;22&quot; width=&quot;19&quot; height=&quot;19&quot; rx=&quot;3&quot; class=&quot;svelte-1jedj87&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;There is no &lt;span class=&quot;chip svelte-yrsjh2 round&quot; style=&quot;background: var(--piece-o);&quot;&gt;O&lt;/span&gt; piece. The square tetromino is itself a filled 2×2 block, so it would break rule 3 below wherever it went.)&lt;/small&gt;: &lt;span style=&quot;white-space: nowrap&quot;&gt;&lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-l);&quot;&gt;L&lt;/span&gt; &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-i);&quot;&gt;I&lt;/span&gt; &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-t);&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-s);&quot;&gt;S&lt;/span&gt;.&lt;/span&gt; A finished board must obey three more rules.&lt;/p&gt; &lt;aside class=&quot;margin-note margin-note-left&quot; aria-label=&quot;Margin note&quot; style=&quot;--side-offset: 9.6rem;&quot;&gt;&lt;p&gt;Under each piece are its 8 versions: four rotations, then the same four mirrored. Some come out identical (an &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-i);&quot;&gt;I&lt;/span&gt; turned 180° is the same &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-i);&quot;&gt;I&lt;/span&gt;), so the solver keeps only the distinct ones; the faded versions are the repeats it skips.&lt;/p&gt;&lt;/aside&gt; &lt;aside class=&quot;margin-note margin-note-right&quot; aria-label=&quot;Margin note&quot; style=&quot;--side-offset: 5rem;&quot;&gt;&lt;p&gt;Try the pieces: &lt;strong&gt;click&lt;/strong&gt; one to rotate it 90°, &lt;strong&gt;swipe&lt;/strong&gt; across it to mirror it (or use Enter and the arrow keys).&lt;/p&gt;&lt;/aside&gt; &lt;div class=&quot;pieces svelte-lokgx5&quot;&gt;&lt;div class=&quot;card svelte-lokgx5&quot; style=&quot;--piece: var(--piece-l);&quot;&gt;&lt;span class=&quot;badge svelte-lokgx5&quot; aria-hidden=&quot;true&quot;&gt; &lt;/span&gt; &lt;div class=&quot;stage svelte-lokgx5&quot; role=&quot;button&quot; tabindex=&quot;0&quot; title=&quot;Click to rotate · swipe to mirror&quot; aria-label=&quot;L piece, rotated 0 degrees. Enter rotates, the arrow keys mirror.&quot;&gt;&lt;div class=&quot;mirror svelte-lokgx5&quot; style=&quot;transform: scaleX(1);&quot;&gt;&lt;svg class=&quot;big svelte-lokgx5&quot; viewBox=&quot;0 0 84 84&quot; aria-hidden=&quot;true&quot; style=&quot;transform: rotate(0deg);&quot;&gt;&lt;rect x=&quot;23&quot; y=&quot;13&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;23&quot; y=&quot;33&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;23&quot; y=&quot;53&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;43&quot; y=&quot;53&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt;&lt;/div&gt; &lt;p class=&quot;name svelte-lokgx5&quot;&gt;L&lt;/p&gt; &lt;div class=&quot;versions svelte-lokgx5&quot; role=&quot;img&quot; aria-label=&quot;L: 8 distinct orientations out of 8&quot;&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt; &lt;p class=&quot;kept svelte-lokgx5&quot;&gt;8 of 8 kept&lt;/p&gt;&lt;/div&gt;&lt;div class=&quot;card svelte-lokgx5&quot; style=&quot;--piece: var(--piece-i);&quot;&gt;&lt;span class=&quot;badge svelte-lokgx5&quot; aria-hidden=&quot;true&quot;&gt; &lt;/span&gt; &lt;div class=&quot;stage svelte-lokgx5&quot; role=&quot;button&quot; tabindex=&quot;0&quot; title=&quot;Click to rotate · swipe to mirror&quot; aria-label=&quot;I piece, rotated 0 degrees. Enter rotates, the arrow keys mirror.&quot;&gt;&lt;div class=&quot;mirror svelte-lokgx5&quot; style=&quot;transform: scaleX(1);&quot;&gt;&lt;svg class=&quot;big svelte-lokgx5&quot; viewBox=&quot;0 0 84 84&quot; aria-hidden=&quot;true&quot; style=&quot;transform: rotate(0deg);&quot;&gt;&lt;rect x=&quot;33&quot; y=&quot;3&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;43&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;63&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt;&lt;/div&gt; &lt;p class=&quot;name svelte-lokgx5&quot;&gt;I&lt;/p&gt; &lt;div class=&quot;versions svelte-lokgx5&quot; role=&quot;img&quot; aria-label=&quot;I: 2 distinct orientations out of 8&quot;&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;1.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;19.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;19.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;1.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;19.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;19.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;1.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;19.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;19.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;1.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;19.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;19.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt; &lt;p class=&quot;kept svelte-lokgx5&quot;&gt;2 of 8 kept&lt;/p&gt;&lt;/div&gt;&lt;div class=&quot;card svelte-lokgx5&quot; style=&quot;--piece: var(--piece-t);&quot;&gt;&lt;span class=&quot;badge svelte-lokgx5&quot; aria-hidden=&quot;true&quot;&gt; &lt;/span&gt; &lt;div class=&quot;stage svelte-lokgx5&quot; role=&quot;button&quot; tabindex=&quot;0&quot; title=&quot;Click to rotate · swipe to mirror&quot; aria-label=&quot;T piece, rotated 0 degrees. Enter rotates, the arrow keys mirror.&quot;&gt;&lt;div class=&quot;mirror svelte-lokgx5&quot; style=&quot;transform: scaleX(1);&quot;&gt;&lt;svg class=&quot;big svelte-lokgx5&quot; viewBox=&quot;0 0 84 84&quot; aria-hidden=&quot;true&quot; style=&quot;transform: rotate(0deg);&quot;&gt;&lt;rect x=&quot;13&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;53&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;43&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt;&lt;/div&gt; &lt;p class=&quot;name svelte-lokgx5&quot;&gt;T&lt;/p&gt; &lt;div class=&quot;versions svelte-lokgx5&quot; role=&quot;img&quot; aria-label=&quot;T: 4 distinct orientations out of 8&quot;&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt; &lt;p class=&quot;kept svelte-lokgx5&quot;&gt;4 of 8 kept&lt;/p&gt;&lt;/div&gt;&lt;div class=&quot;card svelte-lokgx5&quot; style=&quot;--piece: var(--piece-s);&quot;&gt;&lt;span class=&quot;badge svelte-lokgx5&quot; aria-hidden=&quot;true&quot;&gt; &lt;/span&gt; &lt;div class=&quot;stage svelte-lokgx5&quot; role=&quot;button&quot; tabindex=&quot;0&quot; title=&quot;Click to rotate · swipe to mirror&quot; aria-label=&quot;S piece, rotated 0 degrees. Enter rotates, the arrow keys mirror.&quot;&gt;&lt;div class=&quot;mirror svelte-lokgx5&quot; style=&quot;transform: scaleX(1);&quot;&gt;&lt;svg class=&quot;big svelte-lokgx5&quot; viewBox=&quot;0 0 84 84&quot; aria-hidden=&quot;true&quot; style=&quot;transform: rotate(0deg);&quot;&gt;&lt;rect x=&quot;33&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;53&quot; y=&quot;23&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13&quot; y=&quot;43&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;33&quot; y=&quot;43&quot; width=&quot;18&quot; height=&quot;18&quot; rx=&quot;2&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt;&lt;/div&gt; &lt;p class=&quot;name svelte-lokgx5&quot;&gt;S&lt;/p&gt; &lt;div class=&quot;versions svelte-lokgx5&quot; role=&quot;img&quot; aria-label=&quot;S: 4 distinct orientations out of 8&quot;&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;4.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;7.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;4.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;7.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;10.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;13.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;svg viewBox=&quot;0 0 26 26&quot; class=&quot;svelte-lokgx5 repeat&quot;&gt;&lt;rect x=&quot;13.5&quot; y=&quot;4.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;13.5&quot; y=&quot;10.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;7.5&quot; y=&quot;16.5&quot; width=&quot;5&quot; height=&quot;5&quot; rx=&quot;1&quot; class=&quot;svelte-lokgx5&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/div&gt; &lt;p class=&quot;kept svelte-lokgx5&quot;&gt;4 of 8 kept&lt;/p&gt;&lt;/div&gt;&lt;/div&gt; &lt;ol class=&quot;rules svelte-io1ug7&quot;&gt;&lt;li class=&quot;svelte-io1ug7&quot;&gt;&lt;div class=&quot;text svelte-io1ug7&quot;&gt;&lt;strong class=&quot;svelte-io1ug7&quot;&gt;No identical shapes touching&lt;/strong&gt; &lt;p class=&quot;svelte-io1ug7&quot;&gt;Two pieces of the same shape may not share an edge. Different shapes may.&lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;47&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;broken svelte-io1ug7&quot;&gt;broken&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;47&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-s);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-s);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-s);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-s);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;valid svelte-io1ug7&quot;&gt;valid&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;svelte-io1ug7&quot;&gt;&lt;div class=&quot;text svelte-io1ug7&quot;&gt;&lt;strong class=&quot;svelte-io1ug7&quot;&gt;Everything is connected&lt;/strong&gt; &lt;p class=&quot;svelte-io1ug7&quot;&gt;All shaded cells form one group, joined by edges (corners do not count).&lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;77&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;broken svelte-io1ug7&quot;&gt;broken&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;77&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;61.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;valid svelte-io1ug7&quot;&gt;valid&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;svelte-io1ug7&quot;&gt;&lt;div class=&quot;text svelte-io1ug7&quot;&gt;&lt;strong class=&quot;svelte-io1ug7&quot;&gt;No 2×2 blocks&lt;/strong&gt; &lt;p class=&quot;svelte-io1ug7&quot;&gt;Four shaded cells may never form a square.&lt;/p&gt;&lt;/div&gt; &lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;62&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 bad&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;broken svelte-io1ug7&quot;&gt;broken&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;example svelte-io1ug7&quot;&gt;&lt;svg width=&quot;62&quot; height=&quot;62&quot; aria-hidden=&quot;true&quot; class=&quot;svelte-io1ug7&quot;&gt;&lt;rect x=&quot;1.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;1.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;16.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7 empty&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;31.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;1.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-i);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;16.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;31.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;46.5&quot; y=&quot;46.5&quot; width=&quot;13&quot; height=&quot;13&quot; rx=&quot;1.5&quot; class=&quot;svelte-io1ug7&quot; style=&quot;fill: var(--piece-l);&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;valid svelte-io1ug7&quot;&gt;valid&lt;/span&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h2 id=&quot;try-it&quot;&gt;Try it&lt;/h2&gt; &lt;p&gt;Click or drag to shade cells&lt;small&gt;(A piece becomes coloured once its four cells form a valid shape; until then its cells stay grey.)&lt;/small&gt;; use &lt;em&gt;Mark&lt;/em&gt; (or right-click) to note cells you know are empty. You get three hints, refilled when you start over. If you get stuck, &lt;em&gt;Solve&lt;/em&gt; picks up where you left off and finishes the board: it keeps your pieces where they can be part of a solution and explains any it has to remove, and you see every attempt, dead end and backtrack it makes. Use &lt;em&gt;Step&lt;/em&gt; and &lt;em&gt;Back&lt;/em&gt; to move through it one attempt at a time.&lt;/p&gt; &lt;div class=&quot;play svelte-1c99fe6&quot;&gt;&lt;div class=&quot;board-column svelte-1c99fe6&quot;&gt;&lt;svg class=&quot;board svelte-1iun6io&quot; viewBox=&quot;0 0 222 222&quot; role=&quot;img&quot; aria-label=&quot;Puzzle board&quot;&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;3&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;39&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;75&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;111&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;183&quot; y=&quot;3&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;3&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;39&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;75&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;111&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;183&quot; y=&quot;39&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;3&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;39&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;75&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t1&quot; x=&quot;111&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;183&quot; y=&quot;75&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;3&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;39&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;75&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;111&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;183&quot; y=&quot;111&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;3&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;39&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;75&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;111&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;183&quot; y=&quot;147&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;3&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;39&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;75&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;111&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t2&quot; x=&quot;147&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;rect class=&quot;tile t0&quot; x=&quot;183&quot; y=&quot;183&quot; width=&quot;36&quot; height=&quot;36&quot;/&gt;&lt;path class=&quot;grid&quot; d=&quot;M39 3V39M111 3V39M183 3V39M75 39V75M111 39V75M183 39V75M75 75V111M39 111V147M75 111V147M111 111V147M147 111V147M39 147V183M75 147V183M147 147V183M75 183V219M111 183V219M147 183V219M3 39H39M75 39H111M111 39H147M147 39H183M183 39H219M3 75H39M111 75H147M147 75H183M39 111H75M75 111H111M147 111H183M183 111H219M111 147H147M147 147H183M183 147H219M3 183H39M111 183H147M147 183H183M183 183H219&quot;/&gt;&lt;path class=&quot;borders&quot; d=&quot;M3 3V39M75 3V39M147 3V39M219 3V39M3 39V75M39 39V75M147 39V75M219 39V75M3 75V111M39 75V111M111 75V111M147 75V111M183 75V111M219 75V111M3 111V147M183 111V147M219 111V147M3 147V183M111 147V183M183 147V183M219 147V183M3 183V219M39 183V219M183 183V219M219 183V219M3 3H39M39 3H75M75 3H111M111 3H147M147 3H183M183 3H219M39 39H75M39 75H75M75 75H111M183 75H219M3 111H39M111 111H147M3 147H39M39 147H75M75 147H111M39 183H75M75 183H111M3 219H39M39 219H75M75 219H111M111 219H147M147 219H183M183 219H219&quot;/&gt;&lt;text class=&quot;label&quot; x=&quot;6&quot; y=&quot;13&quot;&gt;1&lt;/text&gt;&lt;text class=&quot;label&quot; x=&quot;78&quot; y=&quot;13&quot;&gt;2&lt;/text&gt;&lt;text class=&quot;label&quot; x=&quot;150&quot; y=&quot;13&quot;&gt;3&lt;/text&gt;&lt;text class=&quot;label&quot; x=&quot;6&quot; y=&quot;157&quot;&gt;4&lt;/text&gt;&lt;text class=&quot;label&quot; x=&quot;186&quot; y=&quot;85&quot;&gt;5&lt;/text&gt;&lt;/svg&gt; &lt;div class=&quot;message  svelte-1c99fe6&quot; aria-live=&quot;polite&quot;&gt;&lt;b&gt;Your move.&lt;/b&gt; Shade four connected cells in a region. Small, cramped regions have the fewest ways to fit a piece, so they are the best place to start.&lt;/div&gt;&lt;/div&gt; &lt;div class=&quot;side svelte-1c99fe6&quot;&gt;&lt;div class=&quot;picker svelte-113j6by&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;button svelte-113j6by&quot; aria-haspopup=&quot;listbox&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Puzzle: Puzzle 01 · 6×6 · 5 regions&quot;&gt;&lt;span class=&quot;value svelte-113j6by&quot;&gt;Puzzle 01 · 6×6 · 5 regions&lt;/span&gt; &lt;svg class=&quot;chevron svelte-113j6by&quot; viewBox=&quot;0 0 12 12&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M3 4.5 6 7.5 9 4.5&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/button&gt; &lt;/div&gt; &lt;p class=&quot;eyebrow-mono heading svelte-1c99fe6&quot;&gt;Rules check&lt;/p&gt; &lt;ul class=&quot;checks svelte-1c99fe6&quot;&gt;&lt;li class=&quot;svelte-1c99fe6&quot;&gt;&lt;span class=&quot;mark svelte-1c99fe6&quot; aria-hidden=&quot;true&quot;&gt;·&lt;/span&gt;&lt;span&gt;waiting for Python…&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p class=&quot;eyebrow-mono heading svelte-1c99fe6&quot;&gt;Board&lt;/p&gt; &lt;div class=&quot;tools svelte-1c99fe6&quot; role=&quot;group&quot; aria-label=&quot;Tool&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;svelte-1c99fe6 on&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;13&quot; height=&quot;13&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-square lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;rect width=&quot;18&quot; height=&quot;18&quot; x=&quot;3&quot; y=&quot;3&quot; rx=&quot;2&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; Shade&lt;/button&gt; &lt;button type=&quot;button&quot; class=&quot;svelte-1c99fe6&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;13&quot; height=&quot;13&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-x lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M18 6 6 18&quot;&gt;&lt;/path&gt;&lt;path d=&quot;m6 6 12 12&quot;&gt;&lt;/path&gt;&lt;/svg&gt; Mark&lt;/button&gt;&lt;/div&gt; &lt;div class=&quot;pair svelte-1c99fe6&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;button svelte-1c99fe6&quot; title=&quot;3 hints left for this puzzle&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;14&quot; height=&quot;14&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-lightbulb lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M9 18h6&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M10 22h4&quot;&gt;&lt;/path&gt;&lt;/svg&gt; Hint &lt;span class=&quot;dots svelte-1c99fe6&quot; aria-hidden=&quot;true&quot;&gt;&lt;i class=&quot;svelte-1c99fe6 on&quot;&gt;&lt;/i&gt;&lt;i class=&quot;svelte-1c99fe6 on&quot;&gt;&lt;/i&gt;&lt;i class=&quot;svelte-1c99fe6 on&quot;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; class=&quot;button quiet svelte-1c99fe6&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;14&quot; height=&quot;14&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-rotate-ccw lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M3 3v5h5&quot;&gt;&lt;/path&gt;&lt;/svg&gt; Start over&lt;/button&gt;&lt;/div&gt; &lt;p class=&quot;eyebrow-mono heading svelte-1c99fe6&quot;&gt;Solver&lt;/p&gt; &lt;div class=&quot;solver svelte-1c99fe6&quot;&gt;&lt;div class=&quot;player svelte-1c99fe6&quot;&gt;&lt;button type=&quot;button&quot; class=&quot;button svelte-1c99fe6&quot; disabled=&quot;&quot; aria-label=&quot;Back one step&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;14&quot; height=&quot;14&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-chevron-left lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;m15 18-6-6 6-6&quot;&gt;&lt;/path&gt;&lt;/svg&gt; Back&lt;/button&gt; &lt;button type=&quot;button&quot; class=&quot;button primary svelte-1c99fe6&quot;&gt;Solve&lt;/button&gt; &lt;button type=&quot;button&quot; class=&quot;button svelte-1c99fe6&quot; aria-label=&quot;Step forward&quot;&gt;Step &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;14&quot; height=&quot;14&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-chevron-right lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;m9 18 6-6-6-6&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/button&gt;&lt;/div&gt; &lt;label class=&quot;speed svelte-1c99fe6&quot;&gt;&lt;span&gt;slow&lt;/span&gt;&lt;input type=&quot;range&quot; min=&quot;0&quot; max=&quot;4&quot; value=&quot;2&quot; aria-label=&quot;Solver speed&quot; class=&quot;svelte-1c99fe6&quot;/&gt;&lt;span&gt;fast&lt;/span&gt;&lt;/label&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;dialog class=&quot;upload svelte-1c99fe6&quot; aria-labelledby=&quot;upload-title&quot;&gt;&lt;form method=&quot;dialog&quot;&gt;&lt;h3 id=&quot;upload-title&quot; class=&quot;svelte-1c99fe6&quot;&gt;Load a puzzle&lt;/h3&gt; &lt;p class=&quot;svelte-1c99fe6&quot;&gt;One row per line, cell values separated by spaces or tabs. Cells with the same number form a region. The grid must be square.&lt;/p&gt; &lt;label class=&quot;drop svelte-1c99fe6&quot;&gt;Drop a &lt;code&gt;.txt&lt;/code&gt; file here, or &lt;span class=&quot;link svelte-1c99fe6&quot;&gt;choose one&lt;/span&gt; &lt;input type=&quot;file&quot; accept=&quot;.txt,.csv,text/plain&quot; hidden=&quot;&quot;/&gt;&lt;/label&gt; &lt;textarea spellcheck=&quot;false&quot; aria-label=&quot;Puzzle grid&quot; placeholder=&quot;1 1 2 2 3 3
1 2 2 2 3 3
1 3 3 2 3 5
3 3 3 3 3 5
4 4 4 3 3 5
4 3 3 3 3 5&quot; class=&quot;svelte-1c99fe6&quot;&gt;&lt;/textarea&gt; &lt;p class=&quot;error svelte-1c99fe6&quot; role=&quot;alert&quot;&gt;&lt;/p&gt; &lt;div class=&quot;actions svelte-1c99fe6&quot;&gt;&lt;button class=&quot;button quiet svelte-1c99fe6&quot; value=&quot;cancel&quot; formnovalidate=&quot;&quot;&gt;Cancel&lt;/button&gt; &lt;button class=&quot;button primary svelte-1c99fe6&quot; type=&quot;button&quot;&gt;Load&lt;/button&gt;&lt;/div&gt;&lt;/form&gt;&lt;/dialog&gt; &lt;h2 id=&quot;how-the-solver-works&quot;&gt;How the solver works&lt;/h2&gt; &lt;p&gt;The solver generates every possible placement once, then searches depth-first, checking each move against the rules and pruning the neighbouring regions’ options as it goes. The code below is excerpted from &lt;a href=&quot;https://github.com/migpovrap/NuruominoSolver&quot;&gt;our repository on GitHub&lt;/a&gt;.&lt;/p&gt; &lt;h3 id=&quot;the-problem-formally&quot;&gt;The problem, formally&lt;/h3&gt; &lt;p&gt;As a constraint satisfaction problem, LITS is a triple &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟨&lt;/mo&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;D&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;⟩&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\langle X, D, C \rangle&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. Number the regions &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;R&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mo&gt;…&lt;/mo&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi&gt;n&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;R = \{1, \dots, n\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. A &lt;strong&gt;placement&lt;/strong&gt; &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;p&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is one of the four tetrominoes &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-l);&quot;&gt;L&lt;/span&gt;, &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-i);&quot;&gt;I&lt;/span&gt;, &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-t);&quot;&gt;T&lt;/span&gt;, &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-s);&quot;&gt;S&lt;/span&gt; in one orientation at one position on the grid: it covers a set of cells &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;C(p)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; and has a shape &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;L&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;I&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;T&lt;/mi&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;S&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;s(p) \in \{\mathrm{L}, \mathrm{I}, \mathrm{T}, \mathrm{S}\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;. Two sets of cells are adjacent, &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mo&gt;∼&lt;/mo&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;A \sim B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, when a cell of &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;A&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; shares an edge with a cell of &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;B&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;B&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Variables&lt;/strong&gt;, one per region:&lt;/p&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;∣&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;R&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;X = \{\, X_r \mid r \in R \,\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p&gt;&lt;strong&gt;Domains&lt;/strong&gt;, the placements that fit inside each region:&lt;/p&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;D&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;{&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo&gt;∣&lt;/mo&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;p&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;⊆&lt;/mo&gt;&lt;mtext&gt;cells&lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;}&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;D(X_r) = P_r = \{\, p \mid C(p) \subseteq \text{cells}(r) \,\}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p&gt;&lt;strong&gt;Constraints&lt;/strong&gt;, one per rule:&lt;/p&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;s&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mo&gt;⇒&lt;/mo&gt;&lt;mtext&gt;  &lt;/mtext&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;¬&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo fence=&quot;false&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;(&lt;/mo&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;∼&lt;/mo&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo fence=&quot;false&quot; stretchy=&quot;true&quot; minsize=&quot;1.2em&quot; maxsize=&quot;1.2em&quot;&gt;)&lt;/mo&gt;&lt;mspace width=&quot;2em&quot;&gt;&lt;/mspace&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;∀&lt;/mi&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot;&gt;≠&lt;/mo&gt;&lt;msup&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo mathvariant=&quot;normal&quot; lspace=&quot;0em&quot; rspace=&quot;0em&quot;&gt;′&lt;/mo&gt;&lt;/msup&gt;&lt;mspace width=&quot;2em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;(rule 1)&lt;/mtext&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;s(X_r) = s(X_{r&apos;}) \;\Rightarrow\; \neg\, \big( C(X_r) \sim C(X_{r&apos;}) \big) \qquad \forall\, r \neq r&apos; \qquad \text{(rule 1)}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mstyle scriptlevel=&quot;0&quot; displaystyle=&quot;false&quot;&gt;&lt;msub&gt;&lt;mo&gt;⋃&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;R&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt;  is edge-connected&lt;/mtext&gt;&lt;mspace width=&quot;2em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;(rule 2)&lt;/mtext&gt;&lt;/mstyle&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\textstyle\bigcup_{r \in R} C(X_r) \ \text{ is edge-connected} \qquad \text{(rule 2)}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mo fence=&quot;false&quot; stretchy=&quot;true&quot; minsize=&quot;1.8em&quot; maxsize=&quot;1.8em&quot;&gt;∣&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mi&gt;W&lt;/mi&gt;&lt;mo&gt;∩&lt;/mo&gt;&lt;mstyle scriptlevel=&quot;0&quot; displaystyle=&quot;false&quot;&gt;&lt;msub&gt;&lt;mo&gt;⋃&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;R&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mi&gt;C&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;X&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo fence=&quot;false&quot; stretchy=&quot;true&quot; minsize=&quot;1.8em&quot; maxsize=&quot;1.8em&quot;&gt;∣&lt;/mo&gt;&lt;mo&gt;≤&lt;/mo&gt;&lt;mn&gt;3&lt;/mn&gt;&lt;mspace width=&quot;2em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;for every &lt;/mtext&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mo&gt;×&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;mtext&gt; window &lt;/mtext&gt;&lt;mi&gt;W&lt;/mi&gt;&lt;mspace width=&quot;2em&quot;&gt;&lt;/mspace&gt;&lt;mtext&gt;(rule 3)&lt;/mtext&gt;&lt;/mstyle&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\Big|\, W \cap \textstyle\bigcup_{r \in R} C(X_r) \,\Big| \le 3 \qquad \text{for every } 2 \times 2 \text{ window } W \qquad \text{(rule 3)}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p&gt;Each variable takes exactly one value, so “one tetromino per region” needs no constraint of its own. Rules 1 and 3 are local (rule 1 relates two neighbouring regions, rule 3 at most the four regions under a window); rule 2 is a global constraint over all of them.&lt;/p&gt; &lt;h3 id=&quot;every-placement-up-front&quot;&gt;Every placement, up front&lt;/h3&gt; &lt;aside class=&quot;margin-note margin-note-left&quot; aria-label=&quot;Margin note&quot; style=&quot;--side-offset: 0px;&quot;&gt;&lt;p&gt;&lt;strong&gt;Search space.&lt;/strong&gt; The number of complete assignments is &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mo&gt;∏&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;mo&gt;∈&lt;/mo&gt;&lt;mi&gt;R&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;∣&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;P&lt;/mi&gt;&lt;mi&gt;r&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;∣&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\prod_{r \in R} \lvert P_r \rvert&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, the product of the domain sizes, which are the list lengths in &lt;code&gt;actions_&lt;wbr/&gt;graph&lt;/code&gt;. For the 12×12 puzzle 13 that is about 10&lt;sup&gt;12&lt;/sup&gt;; the search visits 141 nodes.&lt;/p&gt;&lt;/aside&gt; &lt;p&gt;An &lt;strong&gt;action&lt;/strong&gt; places one tetromino in one region. The distinct orientations of the four shapes come from &lt;code&gt;get_&lt;wbr/&gt;all_&lt;wbr/&gt;orientations&lt;/code&gt;.&lt;small&gt;(These are the 18 kept versions you saw in the rules: 8 for &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-l);&quot;&gt;L&lt;/span&gt;, 2 for &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-i);&quot;&gt;I&lt;/span&gt;, 4 for &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-t);&quot;&gt;T&lt;/span&gt; and 4 for &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-s);&quot;&gt;S&lt;/span&gt;.)&lt;/small&gt; &lt;code&gt;_generate_&lt;wbr/&gt;all_&lt;wbr/&gt;actions&lt;/code&gt; slides every orientation over every position of the grid and keeps it for a region when &lt;code&gt;Action.&lt;wbr/&gt;is_&lt;wbr/&gt;valid&lt;/code&gt; agrees: all four cells lie inside that region (&lt;code&gt;tetromino_&lt;wbr/&gt;fits_&lt;wbr/&gt;in_&lt;wbr/&gt;region&lt;/code&gt;) and the piece shares at least one edge with another region (&lt;code&gt;num_&lt;wbr/&gt;shared_&lt;wbr/&gt;edges&lt;/code&gt;). A piece touching no other region could never connect to the rest, so it is dropped before the search even starts.&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 351;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _generate_all_actions&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, adjacency_graph):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Generate all valid actions for each region.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    all_actions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; &amp;#123;&amp;#125;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; adjacency_graph.keys()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; regions:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        all_actions[region] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._orientations:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            tetromino_array &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino.get()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            shape_rows, shape_cols &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_array.shape&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.og_board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape_rows &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.og_board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape_cols &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                    cells &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [(row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row_offset, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col_offset)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                        for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row_offset, col_offset &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; zip&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;np.where(tetromino_array))]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                    action &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; Action(region, tetromino, cells)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; action.is_valid(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.og_board):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                        all_actions[region].append(action)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; all_actions&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 196;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; is_valid&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, board: Board) -&gt; &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Returns whether a action is valid or not.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.tetromino_fits_in_region(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        board.num_shared_edges(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;what-a-state-holds&quot;&gt;What a state holds&lt;/h3&gt; &lt;aside class=&quot;margin-note margin-note-right&quot; aria-label=&quot;Margin note&quot; style=&quot;--side-offset: 0px;&quot;&gt;&lt;p&gt;The state after the first move on puzzle 01 (region 1 gets an &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-l);&quot;&gt;L&lt;/span&gt;), with the real values:&lt;/p&gt; &lt;pre class=&quot;state svelte-1b6qb0t&quot;&gt;NuruominoState(
  board = Board([
    [&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;,&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;],
    [&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;],
    [&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 2 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 5 &lt;/span&gt;],
    [&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 5 &lt;/span&gt;],
    [&lt;span class=&quot;num&quot;&gt; 4 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 4 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 4 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 5 &lt;/span&gt;],
    [&lt;span class=&quot;num&quot;&gt; 4 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 3 &lt;/span&gt;,&lt;span class=&quot;num&quot;&gt; 5 &lt;/span&gt;]]),
  filled_regions = {&lt;span class=&quot;num&quot;&gt;1&lt;/span&gt;},
  adjacency_graph = {
    &lt;span class=&quot;num&quot;&gt;1&lt;/span&gt;: {&lt;span class=&quot;num&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;},
    &lt;span class=&quot;num&quot;&gt;2&lt;/span&gt;: {&lt;span class=&quot;num&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;},
    &lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;: {&lt;span class=&quot;num&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;num&quot;&gt;2&lt;/span&gt;, &lt;span class=&quot;num&quot;&gt;4&lt;/span&gt;, &lt;span class=&quot;num&quot;&gt;5&lt;/span&gt;},
    &lt;span class=&quot;num&quot;&gt;4&lt;/span&gt;: {&lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;},
    &lt;span class=&quot;num&quot;&gt;5&lt;/span&gt;: {&lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;}},
  actions_graph = {
    &lt;span class=&quot;num&quot;&gt;1&lt;/span&gt;: [],  &lt;span class=&quot;cmt&quot;&gt;# filled&lt;/span&gt;
    &lt;span class=&quot;num&quot;&gt;2&lt;/span&gt;: [Action(&lt;span class=&quot;pc pc-t&quot;&gt;&apos;T&apos;&lt;/span&gt;, …), Action(&lt;span class=&quot;pc pc-s&quot;&gt;&apos;S&apos;&lt;/span&gt;, …)],
    &lt;span class=&quot;num&quot;&gt;3&lt;/span&gt;: [Action(&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;, …), …],  &lt;span class=&quot;cmt&quot;&gt;# 37&lt;/span&gt;
    &lt;span class=&quot;num&quot;&gt;4&lt;/span&gt;: [Action(&lt;span class=&quot;pc pc-l&quot;&gt;&apos;L&apos;&lt;/span&gt;, …)],
    &lt;span class=&quot;num&quot;&gt;5&lt;/span&gt;: [Action(&lt;span class=&quot;pc pc-i&quot;&gt;&apos;I&apos;&lt;/span&gt;, …)]})&lt;/pre&gt; &lt;p&gt;Each &lt;code&gt;Action&lt;/code&gt; holds a region, a shape and four cells, for example region 2, &lt;span class=&quot;chip svelte-yrsjh2&quot; style=&quot;background: var(--piece-t);&quot;&gt;T&lt;/span&gt; at &lt;code&gt;(0,3) (1,2) (1,3) (2,3)&lt;/code&gt;. Region 2 had 7 placements before this move; forward checking left 2.&lt;/p&gt;&lt;/aside&gt; &lt;p&gt;A search &lt;strong&gt;state&lt;/strong&gt; (&lt;code&gt;NuruominoState&lt;/code&gt;) holds four things. The &lt;code&gt;board&lt;/code&gt; is the grid of region ids, with a letter written over each placed piece. &lt;code&gt;filled_&lt;wbr/&gt;regions&lt;/code&gt; is the set of regions that already have a piece. &lt;code&gt;adjacency_&lt;wbr/&gt;graph&lt;/code&gt; maps each region to the set of regions it touches. &lt;code&gt;actions_&lt;wbr/&gt;graph&lt;/code&gt; maps each region to the placements that are still legal for it, which is that region’s remaining domain. The search never edits a state: each move builds a new one, so an older state is always there to go back to.&lt;/p&gt; &lt;h3 id=&quot;checking-a-move&quot;&gt;Checking a move&lt;/h3&gt; &lt;p&gt;Before a placement can stay in a region’s list, &lt;code&gt;is_&lt;wbr/&gt;currently_&lt;wbr/&gt;valid&lt;/code&gt; tests it against the board as it is now. Each test is one rule from the top of the page: the piece must not overlap a filled cell (&lt;code&gt;tetromino_&lt;wbr/&gt;fits_&lt;wbr/&gt;in_&lt;wbr/&gt;region&lt;/code&gt;), must not touch a piece of the same shape (&lt;code&gt;_touches_&lt;wbr/&gt;same_&lt;wbr/&gt;tetromino_&lt;wbr/&gt;shape&lt;/code&gt;, rule 1), must still be able to connect when all its neighbours are already filled (&lt;code&gt;_connected_&lt;wbr/&gt;to_&lt;wbr/&gt;other_&lt;wbr/&gt;tetromino_&lt;wbr/&gt;shape&lt;/code&gt;, rule 2), and must not complete a 2×2 block (&lt;code&gt;_creates_&lt;wbr/&gt;filled_&lt;wbr/&gt;2x2_&lt;wbr/&gt;region&lt;/code&gt;, rule 3). The first failed test rejects it.&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 201;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; is_currently_valid&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, board: Board, filled_regions, adjacency_graph) -&gt; &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Check if action doesn&apos;t overlap already filled cells, doesn&apos;t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    create 2x2 filled cells and doesn&apos;t touch pieces with the same shape.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.tetromino_fits_in_region(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._touches_same_tetromino_shape(board):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._connected_to_other_tetromino_shape(board, filled_regions, adjacency_graph):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._creates_filled_2x2_region(board):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 238;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _touches_same_tetromino_shape&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, board: Board) -&gt; &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Check if tetromino touches other tetronimo pieces with the same shape.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    board_array &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    shape &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.tetromino.shape&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.position:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board_array[row&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board_array[row&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board_array[row, col&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board_array[row, col&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; shape:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 214;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _creates_filled_2x2_region&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, board: Board) -&gt; &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Check if placing this tetromino would create&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    any 2x2 filled areas, without modifying the board.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    board_array &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    tetromino_shapes &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(Tetromino.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;TETROMINO_SHAPES&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.keys())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    positions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.position)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    potencial_2x2_block &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.position:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row_offset &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col_offset &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                i, j &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row_offset, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col_offset&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; &amp;#x3C;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; j &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                    potencial_2x2_block.add((i, j))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; potencial_2x2_block:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            ((board_array[row, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; ((row, col) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; positions)) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            ((board_array[row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; ((row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; positions)) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            ((board_array[row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; ((row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; positions)) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            ((board_array[row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; ((row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; positions))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        ):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 253;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _connected_to_other_tetromino_shape&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, board: Board, filled_regions,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    adjacency_graph) -&gt; &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;When all adjacent regions are filled the tetromino placed on the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    region needs to touch a tetromino from one of the adjacent regions.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    adjacent_regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; adjacency_graph.get(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.region, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; filled_regions.issuperset(adjacent_regions):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    tetromino_shapes &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; Tetromino.&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;TETROMINO_SHAPES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.position:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board[row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board[row &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;, col] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&gt;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board[row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;&amp;#x3C;&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.size &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; board.board[row, col &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tetromino_shapes:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; False&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;placing-a-piece&quot;&gt;Placing a piece&lt;/h3&gt; &lt;aside class=&quot;margin-note margin-note-left&quot; aria-label=&quot;Margin note&quot; style=&quot;--side-offset: 0px;&quot;&gt;&lt;p&gt;&lt;strong&gt;Constraint propagation.&lt;/strong&gt; This is the simplest kind, forward checking: only the variables adjacent to the one just assigned are filtered. Arc consistency would also re-filter their neighbours, at a higher cost per node.&lt;/p&gt;&lt;/aside&gt; &lt;p&gt;&lt;code&gt;result&lt;/code&gt; copies the state (so the parent stays intact for backtracking), writes the piece onto the copied board, and then &lt;strong&gt;re-validates the candidate lists of the neighbouring regions&lt;/strong&gt; with &lt;code&gt;is_&lt;wbr/&gt;currently_&lt;wbr/&gt;valid&lt;/code&gt;. Candidates that would overlap, touch an identical shape, complete a 2×2 block or could no longer connect are dropped. If a neighbour ends up with an empty list, the new state is already doomed and the next call to &lt;code&gt;actions&lt;/code&gt; will return nothing, so the failure is noticed one step later instead of deep in the subtree.&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 286;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; result&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, state, action):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Return the state that results from executing the given action.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_state &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; NuruominoState(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;        board&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;state.board.copy(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;        actions_graph&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;state.actions_graph.copy(),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;        adjacency_graph&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&amp;#123;key: value.copy()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; key, value &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; state.adjacency_graph.items()&amp;#125;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;        filled_regions&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;state.filled_regions.copy()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    # Update baord.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_state.board.run_action(action)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    # Update filled regions.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_state.filled_regions.add(action.region)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    # Update adjacency graph.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_adjacent_regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state.board.get_adjacent_regions(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        action.position, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.og_board, new_state.filled_regions)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_state.adjacency_graph[action.region] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_adjacent_regions.copy()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; neighbour &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_adjacent_regions:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; neighbour &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state.adjacency_graph:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            new_state.adjacency_graph[neighbour].add(action.region)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region, neighbours &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state.adjacency_graph.items():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; (region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; action.region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; action.region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; neighbours&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_adjacent_regions):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            neighbours.discard(action.region)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;    # Update actions graph.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    new_state.actions_graph[action.region] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_adjacent_regions:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state.actions_graph:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            valid_actions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_actions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state.actions_graph[region]:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;                if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_actions.is_currently_valid(new_state.board,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                    new_state.filled_regions, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.adjacency_graph):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                    valid_actions.append(new_actions)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;            new_state.actions_graph[region] &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; valid_actions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; new_state&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;which-region-goes-next&quot;&gt;Which region goes next&lt;/h3&gt; &lt;p&gt;Each node expands &lt;strong&gt;one region only&lt;/strong&gt;: the unfilled region with the fewest legal placements left. This is the &lt;em&gt;minimum remaining values&lt;/em&gt; (fail-first) heuristic. It is safe because every region must receive a piece anyway, so the order cannot change which solutions exist, only how early dead ends show up. A region with zero placements makes the node a dead end immediately.&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 327;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; actions&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, state):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Return the actions available in the current state.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._adjacency_graph_connected(state.adjacency_graph):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; state.actions_graph.get(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._select_next_region(state), [])&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 369;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _select_next_region&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, state):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Selects the next region to explore and test actions.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(state.adjacency_graph.keys())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;-=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; state.filled_regions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    min_actions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; min&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(state.actions_graph.get(region, []))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; regions)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    min_regions &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; regions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(state.actions_graph.get(region, [])) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; min_actions]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(min_regions) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(min_regions) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; min_regions[&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(min_regions, &lt;/span&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;key&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=lambda&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;        len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(state.actions_graph.get(region, [])), &lt;/span&gt;&lt;span style=&quot;--shiki-light:#E36209;--shiki-dark:#FFAB70&quot;&gt;default&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;None&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;depth-first-search&quot;&gt;Depth-first search&lt;/h3&gt; &lt;p&gt;&lt;code&gt;depth_&lt;wbr/&gt;first_&lt;wbr/&gt;tree_&lt;wbr/&gt;search&lt;/code&gt; keeps a &lt;strong&gt;frontier&lt;/strong&gt;, a Python list used as a stack. It pops the newest node, tests it, and pushes all its children. Because children go on top, the search dives into the most recent choice first. There is no separate “undo”: when a branch dies, the next &lt;code&gt;pop()&lt;/code&gt; simply returns to the most recent unexplored sibling, which is backtracking. No visited set is needed: each node branches on a single region, so sibling subtrees differ in that region’s piece and never reach the same state, and the depth is bounded by the number of regions.&lt;/p&gt; &lt;figure id=&quot;figure-1&quot; class=&quot;figure svelte-1wp1csv&quot;&gt;&lt;div class=&quot;figure-body svelte-1wp1csv&quot;&gt;&lt;div class=&quot;dfs svelte-1lat54v&quot;&gt;&lt;div class=&quot;stage svelte-1lat54v&quot;&gt;&lt;svg class=&quot;tree svelte-1lat54v&quot; viewBox=&quot;0 0 440 270&quot; role=&quot;img&quot; aria-label=&quot;Search tree&quot;&gt;&lt;line class=&quot;edge svelte-1lat54v&quot; x1=&quot;220&quot; y1=&quot;30&quot; x2=&quot;120&quot; y2=&quot;105&quot;&gt;&lt;/line&gt;&lt;line class=&quot;edge svelte-1lat54v&quot; x1=&quot;220&quot; y1=&quot;30&quot; x2=&quot;320&quot; y2=&quot;105&quot;&gt;&lt;/line&gt;&lt;line class=&quot;edge svelte-1lat54v&quot; x1=&quot;320&quot; y1=&quot;105&quot; x2=&quot;250&quot; y2=&quot;180&quot;&gt;&lt;/line&gt;&lt;line class=&quot;edge svelte-1lat54v&quot; x1=&quot;320&quot; y1=&quot;105&quot; x2=&quot;390&quot; y2=&quot;180&quot;&gt;&lt;/line&gt;&lt;line class=&quot;edge svelte-1lat54v&quot; x1=&quot;250&quot; y1=&quot;180&quot; x2=&quot;250&quot; y2=&quot;245&quot;&gt;&lt;/line&gt;&lt;g class=&quot;node waiting svelte-1lat54v&quot; transform=&quot;translate(220 30)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;start&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g class=&quot;node unseen svelte-1lat54v&quot; transform=&quot;translate(120 105)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;1·L&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g class=&quot;node unseen svelte-1lat54v&quot; transform=&quot;translate(320 105)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;1·T&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g class=&quot;node unseen svelte-1lat54v&quot; transform=&quot;translate(250 180)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;2·S&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g class=&quot;node unseen svelte-1lat54v&quot; transform=&quot;translate(390 180)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;2·I&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;g class=&quot;node unseen svelte-1lat54v&quot; transform=&quot;translate(250 245)&quot;&gt;&lt;circle r=&quot;21&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;/circle&gt;&lt;text class=&quot;svelte-1lat54v&quot;&gt;3·L&lt;/text&gt;&lt;path class=&quot;cross svelte-1lat54v&quot; d=&quot;M13 -21l8 8m0 -8l-8 8&quot;&gt;&lt;/path&gt;&lt;path class=&quot;tick svelte-1lat54v&quot; d=&quot;M12 -16l3.5 3.5 6.5 -7&quot;&gt;&lt;/path&gt;&lt;/g&gt;&lt;/svg&gt; &lt;div class=&quot;side&quot;&gt;&lt;p class=&quot;heading svelte-1lat54v&quot;&gt;frontier &lt;span class=&quot;svelte-1lat54v&quot;&gt;top = next pop()&lt;/span&gt;&lt;/p&gt; &lt;ol class=&quot;stack svelte-1lat54v&quot;&gt;&lt;li class=&quot;svelte-1lat54v next pushed&quot;&gt;&lt;span&gt;start&lt;/span&gt; &lt;em class=&quot;svelte-1lat54v&quot;&gt;next&lt;/em&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class=&quot;caption svelte-1lat54v&quot;&gt;&lt;div class=&quot;controls svelte-1lat54v&quot;&gt;&lt;button type=&quot;button&quot; aria-label=&quot;Previous step&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;15&quot; height=&quot;15&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-chevron-left lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;m15 18-6-6 6-6&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; aria-label=&quot;Pause&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;13&quot; height=&quot;13&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-pause lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;rect x=&quot;14&quot; y=&quot;3&quot; width=&quot;5&quot; height=&quot;18&quot; rx=&quot;1&quot;&gt;&lt;/rect&gt;&lt;rect x=&quot;5&quot; y=&quot;3&quot; width=&quot;5&quot; height=&quot;18&quot; rx=&quot;1&quot;&gt;&lt;/rect&gt;&lt;/svg&gt;&lt;/button&gt; &lt;button type=&quot;button&quot; aria-label=&quot;Next step&quot; class=&quot;svelte-1lat54v&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;15&quot; height=&quot;15&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-chevron-right lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;m9 18 6-6-6-6&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/button&gt; &lt;span class=&quot;count svelte-1lat54v&quot;&gt;1 / 6&lt;/span&gt;&lt;/div&gt; &lt;p aria-live=&quot;polite&quot; class=&quot;svelte-1lat54v&quot;&gt;The frontier starts with a single node: the empty board.&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt; &lt;figcaption class=&quot;svelte-1wp1csv&quot;&gt;Figure 1: Depth-first search on a tiny tree, with its frontier stack. 1·T means: put a T in region 1.&lt;/figcaption&gt;&lt;/figure&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 196;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; depth_first_tree_search&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(problem):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    [Figure 3.7]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    Search the deepest nodes in the search tree first.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    Search through the successors of a problem to find a goal.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    The argument frontier should be an empty queue.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    Repeats infinitely in case of loops.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    frontier &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [Node(problem.initial)]  &lt;/span&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;# Stack&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    while&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; frontier:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        node &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; frontier.pop()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; problem.goal_test(node.state):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; node&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        frontier.extend(node.expand(problem))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; None&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;keeping-everything-connected&quot;&gt;Keeping everything connected&lt;/h3&gt; &lt;p&gt;The rule “all shaded cells are connected” involves every region at once, so no single region can check it. The code encodes it in the graph: when a piece is placed, &lt;code&gt;result&lt;/code&gt; &lt;strong&gt;rewrites that region’s edges&lt;/strong&gt; so it is adjacent only to the regions its cells actually touch, and removes the reverse edges from the others. The graph then stays connected exactly as long as every placed piece can still be linked to the rest, with unfilled regions counted optimistically. &lt;code&gt;actions&lt;/code&gt; returns no children if the graph has split, and &lt;code&gt;goal_&lt;wbr/&gt;test&lt;/code&gt; accepts a state only when every region is filled &lt;em&gt;and&lt;/em&gt; the graph is connected.&lt;small&gt;(Look at the graph in the &lt;code class=&quot;pane svelte-ox3mxj&quot;&gt;Search state&lt;/code&gt; panel on the &lt;a href=&quot;https://inesiscosta.com/projects/nuruomino/solver&quot;&gt;solver page&lt;/a&gt;: grey edges disappear the moment a piece is placed that does not touch that neighbour.)&lt;/small&gt;&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 385;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; _adjacency_graph_connected&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, adjacency_graph):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Return True if the adjacency graph is connected. False otherwise.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    visited &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;    queue &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    while&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; queue:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; queue.pop(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; region &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; visited:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            continue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;        visited.add(region)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; neighbour &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; adjacency_graph[region]:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; neighbour &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;not&lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt; in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; visited:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;                queue.append(neighbour)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(visited) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(adjacency_graph)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;counter-reset: line 322;--line-digits: 3&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;--shiki-light:#6F42C1;--shiki-dark:#B392F0&quot;&gt; goal_test&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(self, state):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#032F62;--shiki-dark:#9ECBFF&quot;&gt;    &quot;&quot;&quot;Test if the given state is a goal state.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;.regions) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;(state.filled_regions) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;and&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#005CC5;--shiki-dark:#79B8FF&quot;&gt;        self&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;._adjacency_graph_connected(state.adjacency_graph)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h2 id=&quot;see-it-run&quot;&gt;See it run&lt;/h2&gt; &lt;p&gt;To better understand how the solver works, you can explore any of these puzzles in the interactive demo in &lt;a href=&quot;https://inesiscosta.com/projects/nuruomino/solver&quot;&gt;this&lt;/a&gt; page. Step through the Python code line by line, just like in a debugger, while inspecting the variables, call stack, search state, and how the board evolves as pieces are placed, tested, and removed during backtracking.&lt;/p&gt;</content>
  </entry>
  <entry>
    <id>https://inesiscosta.com/writing/swate</id>
    <title>SWATE — A multi-camera 3D human tracking system</title>
    <link rel="alternate" type="text/html" href="https://inesiscosta.com/writing/swate"/>
    <published>2026-10-04T00:00:00.000Z</published>
    <updated>2026-10-04T00:00:00.000Z</updated>
    <summary>A real-time 3D human tracking system combining multi-camera calibration, pose estimation, triangulation, and identity tracking.</summary>
    <category term="Computer Vision"/>
    <category term="Systems"/>
    <category term="Research"/>
    <content type="html" xml:base="https://inesiscosta.com/writing/swate">&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt; &lt;p&gt;SWATE (Socially-Aware AI for Teamwork Enhancement and Training) is a multi-camera 3D human tracking system that reconstructs and tracks several people in real time as 3D skeletons from synchronised USB cameras. It combines multi-view pose estimation, geometric triangulation, and identity tracking to produce consistent 3D trajectories, and is used as the perception backend for a collaborative training platform.&lt;/p&gt; &lt;p&gt;This post covers the system’s design, the main implementation details, and the lessons learned from building and deploying it.&lt;/p&gt; &lt;h2 id=&quot;system-design&quot;&gt;System design&lt;/h2&gt; &lt;p&gt;The goal is to estimate the 3D pose of multiple people in a shared space using &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;N&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; calibrated cameras and to maintain consistent identities over time. The system is organised as a real-time pipeline with three main stages, shown in &lt;a href=&quot;https://inesiscosta.com/writing/swate#figure-1&quot;&gt;Figure 1&lt;/a&gt;.&lt;/p&gt; &lt;figure id=&quot;figure-1&quot; class=&quot;figure svelte-1wp1csv&quot;&gt;&lt;div class=&quot;figure-body svelte-1wp1csv&quot;&gt;&lt;ol class=&quot;pipeline svelte-qr8ysd&quot; aria-label=&quot;Pipeline stages&quot;&gt; &lt;li class=&quot;stage svelte-qr8ysd&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;22&quot; height=&quot;22&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.5&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-video lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5&quot;&gt;&lt;/path&gt;&lt;rect x=&quot;2&quot; y=&quot;6&quot; width=&quot;14&quot; height=&quot;12&quot; rx=&quot;2&quot;&gt;&lt;/rect&gt;&lt;/svg&gt; &lt;span class=&quot;svelte-qr8ysd&quot;&gt;&lt;strong class=&quot;svelte-qr8ysd&quot;&gt;Multi-view&lt;/strong&gt; pose estimation&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;arrow svelte-qr8ysd&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;20&quot; height=&quot;20&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.5&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-arrow-right lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt;&lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/li&gt; &lt;li class=&quot;stage svelte-qr8ysd&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;22&quot; height=&quot;22&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.5&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-box lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z&quot;&gt;&lt;/path&gt;&lt;path d=&quot;m3.3 7 8.7 5 8.7-5&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M12 22V12&quot;&gt;&lt;/path&gt;&lt;/svg&gt; &lt;span class=&quot;svelte-qr8ysd&quot;&gt;&lt;strong class=&quot;svelte-qr8ysd&quot;&gt;3D reconstruction&lt;/strong&gt; (triangulation)&lt;/span&gt;&lt;/li&gt;&lt;li class=&quot;arrow svelte-qr8ysd&quot; aria-hidden=&quot;true&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;20&quot; height=&quot;20&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.5&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-arrow-right lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M5 12h14&quot;&gt;&lt;/path&gt;&lt;path d=&quot;m12 5 7 7-7 7&quot;&gt;&lt;/path&gt;&lt;/svg&gt;&lt;/li&gt; &lt;li class=&quot;stage svelte-qr8ysd&quot;&gt;&lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;22&quot; height=&quot;22&quot; viewBox=&quot;0 0 24 24&quot; fill=&quot;none&quot; stroke=&quot;currentColor&quot; stroke-width=&quot;1.5&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; class=&quot;lucide lucide-users lucide-icon&quot; aria-hidden=&quot;true&quot;&gt;&lt;path d=&quot;M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M16 3.128a4 4 0 0 1 0 7.744&quot;&gt;&lt;/path&gt;&lt;path d=&quot;M22 21v-2a4 4 0 0 0-3-3.87&quot;&gt;&lt;/path&gt;&lt;circle cx=&quot;9&quot; cy=&quot;7&quot; r=&quot;4&quot;&gt;&lt;/circle&gt;&lt;/svg&gt; &lt;span class=&quot;svelte-qr8ysd&quot;&gt;&lt;strong class=&quot;svelte-qr8ysd&quot;&gt;Tracking&lt;/strong&gt; (identity &amp;amp; smoothing)&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt; &lt;figcaption class=&quot;svelte-1wp1csv&quot;&gt;Figure 1: High-level pipeline of the tracking system.&lt;/figcaption&gt;&lt;/figure&gt; &lt;h3 id=&quot;multi-view-setup&quot;&gt;Multi-view setup&lt;/h3&gt; &lt;p&gt;We use a set of &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;4&lt;/mn&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;N = 4&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; USB cameras placed around the scene, synchronised via a common clock. Each frame is processed independently by a 2D pose estimation model&lt;small&gt;(In practice, we use a TensorRT-accelerated version of a YOLO-Pose model, which allows us to run the entire pipeline at ~30 FPS on a single GPU.)&lt;/small&gt; to detect keypoints, which are then associated across views and triangulated to obtain 3D positions.&lt;/p&gt; &lt;div class=&quot;code-block&quot;&gt;&lt;pre class=&quot;shiki shiki-themes github-light github-dark&quot; style=&quot;--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;--line-digits: 1&quot; tabindex=&quot;0&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#6A737D;--shiki-dark:#6A737D&quot;&gt;# Per-frame pipeline (simplified)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;keypoints &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; [model.infer(frame) &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; frame &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; frames]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;tracks &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; associate_keypoints(keypoints)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;poses_3d &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; triangulate(tracks, cameras)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt;smoothed &lt;/span&gt;&lt;span style=&quot;--shiki-light:#D73A49;--shiki-dark:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;--shiki-light:#24292E;--shiki-dark:#E1E4E8&quot;&gt; tracker.update(poses_3d)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt; &lt;h3 id=&quot;pose-estimation&quot;&gt;Pose estimation&lt;/h3&gt; &lt;p&gt;Every camera produces a list of 2D skeletons per frame, each keypoint with a confidence score. Before anything can be triangulated, the detections have to be matched across views&lt;small&gt;(By “multi-view” we mean cameras with overlapping fields of view, enabling triangulation of 3D keypoints from their 2D detections.)&lt;/small&gt;: which skeleton in camera &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;i&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; is the same person as which skeleton in camera &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;j&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;? We score each candidate pair by the symmetric epipolar distance between their keypoints, using the fundamental matrix &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;F&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;F_{ij}&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; between the two cameras:&lt;/p&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mi&gt;d&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;dist&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;msub&gt;&lt;mi&gt;F&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/mrow&gt;&lt;/msub&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;mo&gt;+&lt;/mo&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;dist&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;mo stretchy=&quot;false&quot;&gt;(&lt;/mo&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mo separator=&quot;true&quot;&gt;,&lt;/mo&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;msubsup&gt;&lt;mi&gt;F&lt;/mi&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/mrow&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;⊤&lt;/mi&gt;&lt;/msubsup&gt;&lt;msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;x&lt;/mi&gt;&lt;mi&gt;j&lt;/mi&gt;&lt;/msub&gt;&lt;mo stretchy=&quot;false&quot;&gt;)&lt;/mo&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;d(\mathbf{x}_i, \mathbf{x}_j) = \operatorname{dist}(\mathbf{x}_j,\, F_{ij}\mathbf{x}_i) + \operatorname{dist}(\mathbf{x}_i,\, F_{ij}^{\top}\mathbf{x}_j)&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p&gt;A low distance means the two detections are consistent with a single point in space.&lt;/p&gt; &lt;h3 id=&quot;3d-reconstruction&quot;&gt;3D reconstruction&lt;/h3&gt; &lt;p&gt;Each matched group of detections is triangulated with a confidence-weighted DLT: every camera contributes two linear constraints per keypoint, scaled by the detector’s confidence &lt;span class=&quot;math math-inline&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;msub&gt;&lt;mi&gt;w&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;w_i&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;, and the 3D point is the least-squares solution&lt;/p&gt; &lt;div class=&quot;math math-display&quot;&gt;&lt;span class=&quot;katex-display&quot;&gt;&lt;span class=&quot;katex&quot;&gt;&lt;span class=&quot;katex-mathml&quot;&gt;&lt;math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;&gt;&lt;semantics&gt;&lt;mrow&gt;&lt;mover accent=&quot;true&quot;&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;X&lt;/mi&gt;&lt;mo&gt;^&lt;/mo&gt;&lt;/mover&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mi&gt;arg&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;munder&gt;&lt;mrow&gt;&lt;mi&gt;min&lt;/mi&gt;&lt;mo&gt;⁡&lt;/mo&gt;&lt;/mrow&gt;&lt;mrow&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;X&lt;/mi&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;/munder&gt;&lt;munderover&gt;&lt;mo&gt;∑&lt;/mo&gt;&lt;mrow&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;mo&gt;=&lt;/mo&gt;&lt;mn&gt;1&lt;/mn&gt;&lt;/mrow&gt;&lt;mi&gt;N&lt;/mi&gt;&lt;/munderover&gt;&lt;msub&gt;&lt;mi&gt;w&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mtext&gt; &lt;/mtext&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;msub&gt;&lt;mi&gt;A&lt;/mi&gt;&lt;mi&gt;i&lt;/mi&gt;&lt;/msub&gt;&lt;mi mathvariant=&quot;bold&quot;&gt;X&lt;/mi&gt;&lt;msup&gt;&lt;mo stretchy=&quot;false&quot;&gt;∥&lt;/mo&gt;&lt;mn&gt;2&lt;/mn&gt;&lt;/msup&gt;&lt;mi mathvariant=&quot;normal&quot;&gt;.&lt;/mi&gt;&lt;/mrow&gt;&lt;annotation encoding=&quot;application/x-tex&quot;&gt;\hat{\mathbf{X}} = \arg\min_{\lVert \mathbf{X} \rVert = 1} \sum_{i=1}^{N} w_i \, \lVert A_i \mathbf{X} \rVert^2 .&lt;/annotation&gt;&lt;/semantics&gt;&lt;/math&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;p&gt;Weighting by confidence lets a camera with a clear view outvote one where the person is half occluded.&lt;/p&gt; &lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt; &lt;h3 id=&quot;camera-calibration&quot;&gt;Camera calibration&lt;/h3&gt; &lt;p&gt;Triangulation is only as good as the calibration. I wrote a small calibration library that places every camera in one shared 3D space: intrinsics come from ChArUco boards, with MAD-based outlier rejection on the per-view reprojection errors, and extrinsics from pairwise stereo calibrations chained over a spanning tree of the cameras, with loop-closure checks to catch a bad pair. A RANSAC fit of the floor plane then gives the scene a sensible “up”.&lt;/p&gt; &lt;h3 id=&quot;tracking-and-identity&quot;&gt;Tracking and identity&lt;/h3&gt; &lt;p&gt;Identities have to stay stable as people move around and cross paths. Position-based tracking handles the easy cases; when two people come close, appearance re-identification breaks the tie by comparing hue–saturation histograms of each person with the Bhattacharyya distance. Joint positions are smoothed with a One Euro filter, which removes jitter when someone stands still without adding lag when they move quickly.&lt;/p&gt; &lt;h3 id=&quot;optimisation&quot;&gt;Optimisation&lt;/h3&gt; &lt;p&gt;The whole loop has to fit in a frame budget. The pose model runs through TensorRT, and the geometry (matching, triangulation, filtering) is vectorised so that its cost stays small next to inference.&lt;/p&gt; &lt;h2 id=&quot;results&quot;&gt;Results&lt;/h2&gt; &lt;p&gt;The system runs live as a desktop app (Tauri and React, with a FastAPI backend) that shows every tracked person as a 3D skeleton in a Three.js viewer, at around 30 frames per second on a single GPU.&lt;/p&gt; &lt;h2 id=&quot;takeaways&quot;&gt;Takeaways&lt;/h2&gt; &lt;ul&gt;&lt;li&gt;Calibration quality bounds everything downstream; checking it (loop closure, outlier rejection) paid off more than any later tuning.&lt;/li&gt; &lt;li&gt;Weighting by detector confidence is a cheap way to make triangulation robust to occlusion.&lt;/li&gt; &lt;li&gt;Identity tracking needs both geometry and appearance: either alone fails when people cross paths.&lt;/li&gt;&lt;/ul&gt;</content>
  </entry>
</feed>
