<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by AlgoRythm on Medium]]></title>
        <description><![CDATA[Stories by AlgoRythm on Medium]]></description>
        <link>https://medium.com/@my_algo_rythm?source=rss-ffdfff9cadf5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AFjattVxYI7XYiFeYyGoVA.png</url>
            <title>Stories by AlgoRythm on Medium</title>
            <link>https://medium.com/@my_algo_rythm?source=rss-ffdfff9cadf5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 01:58:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@my_algo_rythm/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Queens’ Many Hats: Mastering the Symmetries of the Board]]></title>
            <link>https://medium.com/@my_algo_rythm/n-queens-part-2-the-queens-many-hats-mastering-the-symmetries-of-the-board-982b4b4179b7?source=rss-ffdfff9cadf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/982b4b4179b7</guid>
            <category><![CDATA[symmetry]]></category>
            <category><![CDATA[chess]]></category>
            <category><![CDATA[n-queens-problem]]></category>
            <category><![CDATA[symmetry-breaking]]></category>
            <category><![CDATA[groups]]></category>
            <dc:creator><![CDATA[AlgoRythm]]></dc:creator>
            <pubDate>Wed, 25 Feb 2026 07:42:51 GMT</pubDate>
            <atom:updated>2026-02-25T07:45:20.243Z</atom:updated>
            <content:encoded><![CDATA[<h4>N-Queens Part 2</h4><p>After winning that first race with a simple backtracking solver, I realized my code was working way harder than it needed to. It was finding the same “shape” over and over again, just wearing a different hat. To truly master the Queens, I had to learn the language of symmetry.</p><p>I won’t dive deep into the weeds of Group Theory — I’m an engineer, not a mathematician, and I’m comfortable admitting that. However, you don’t need a PhD to appreciate the <strong>Dihedral Group of Order 8 (D₄)</strong>. In simple terms, these are the symmetries of a square, and they are the secret to understanding how several seemingly different board layouts can actually be the same solution in disguise.By recognizing these symmetries, we can group solutions into “families,” where one <strong>fundamental solution</strong> represents all the possible rotations and reflections of that specific pattern.</p><h4>THE SYMMETRIES OF A SQUARE</h4><p>A chessboard is essentially a square, and a square is a highly symmetrical object. In geometry, a symmetry is a transformation that leaves a shape looking exactly as it did before. If you can rotate or flip the board and the queens still land on a valid grid, you’ve found a symmetry.</p><p>The D₄ group consists of 8 distinct transformations:</p><ol><li><strong>The Rotations (Around the center): </strong>R₀, R₉₀, R₁₈₀, R₂₇₀</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JrgptM8nxssC4F9R3xUWw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E0sblUVHqp9Omiaji6ooHA.png" /><figcaption><strong><em>LEFT</em></strong>: R₀ — The Identity (0° rotation — doing nothing); <strong><em>RIGHT</em></strong>: R₉₀ — 90° counter-clockwise.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfBFAI0_AoRIfFF9bWQMCA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kSQ5uTTUrBuNqWs1r1rY8g.png" /><figcaption><strong>LEFT</strong>: R₁₈₀ — 180° counter-clockwise; <strong>RIGHT</strong>: R₂₇₀ — 270° counter-clockwise</figcaption></figure><p><strong>2. The Reflections: </strong>Horizontal (flipping the board top-to-bottom), vertical (flipping the board left-to-right), main-diagonal (flipping over the line from top-left to bottom-right), anti-diagonal (flipping over the line from top-right to bottom-left)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gP29ItGUKxOM9Cf3FmxWjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T3Oqx4YXjEPLN0XJsvqlpA.png" /><figcaption><strong>LEFT</strong>: Reflection around horizontal axis; <strong>RIGHT</strong>: Reflection around vertical axis</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5MognxEcWw2mmtejdb5hA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sfvXEuepW39_YxCF_LyUyg.png" /><figcaption><strong>LEFT</strong>: Reflection around main diagonal; <strong>RIGHT</strong>: Reflection around anti-diagonal</figcaption></figure><p>Before we apply these flips and rotations, we need a way to talk about the board that a computer understands. We represent an N-Queens solution as a <strong>tuple</strong> (or array). If we label the top-left square as (0,0), a solution is a sequence of N numbers: (c0, c1, ... CN-1). Each number represents the column position of a queen in that specific row.</p><p><strong>Example:</strong> For N=4, the solution (1, 3, 0, 2) means, queens are positioned at (0,1), (1,3), (2,0)and (3,2)</p><p>This representation is powerful because it inherently satisfies the “one queen per row/column” rule, turning a 2D problem into a 1D permutation.</p><h4>USING SYMMETRY TO FIND MORE SOLUTIONS</h4><p>If you find one solution, you’ve actually found a “family.” By applying the 8 transformations of <strong>D₄</strong> to that one tuple, you can generate up to 7 other solutions for free. However, there is a catch: <strong>Some solutions are their own twins.</strong></p><p>If a solution is already symmetrical (for example, if rotating it 180° results in the exact same queen positions), the transformation doesn’t produce a “new” solution. We call the set of solutions generated from a single one an <strong>orbit</strong>.</p><h4>The 8-Queens Breakdown:</h4><p>In the 8-Queens puzzle, there are <strong>92</strong> total solutions. But if we look at them through the lens of symmetry, we find there are only <strong>12 Fundamental Solutions</strong>.</p><ul><li><strong>11 groups of 8:</strong> 11 fundamental solutions have no internal symmetry. Applying all 8 transformations yields 8 unique board layouts. (11 x 8 = 88)</li><li><strong>1 group of 4:</strong> One very special fundamental solution is <strong>rotationally symmetric</strong>. Specifically, rotating it 180° results in the same layout. Because of this “self-similarity,” it only produces 4 unique variations instead of 8. (1 x 4 = 4)</li></ul><p><strong>Total:</strong> 88 + 4 = 92 solutions.</p><p>The “lonely” group of four exists because of <strong>Point Symmetry</strong>. For N=8, there is one specific fundamental solution — (2, 4, 1, 7, 0, 6, 3, 5)—that looks exactly the same if you spin the board 180°. Because R₁₈₀ doesn&#39;t create a new layout, the total count of unique variations for that family drops from 8 to 4.</p><p>By convention, we define the <strong>Fundamental Solution</strong> as the lexicographically smallest tuple in its group. It’s the “ancestor” of the family. Now that we know we are looking for ‘families’ of solutions, can we tell our code to stop looking for the children and only find the ancestors? In my next post, I’ll show you how <strong>Symmetry Breaking</strong> can cut your search time in half — or more.</p><p><strong>P.S.</strong> — <em>You might have noticed the diagrams in this post are a bit… “hero-sized.” Medium’s editor and I had a brief disagreement about image scaling, and the editor won. I apologize for the extra scrolling !</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=982b4b4179b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why I’ve Been Solving the Same Puzzle for Two Decades]]></title>
            <link>https://medium.com/@my_algo_rythm/why-ive-been-solving-the-same-puzzle-for-two-decades-a10e7478f026?source=rss-ffdfff9cadf5------2</link>
            <guid isPermaLink="false">https://medium.com/p/a10e7478f026</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[a-journey]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[coding-challenge]]></category>
            <dc:creator><![CDATA[AlgoRythm]]></dc:creator>
            <pubDate>Tue, 03 Feb 2026 04:21:58 GMT</pubDate>
            <atom:updated>2026-02-25T07:45:47.671Z</atom:updated>
            <content:encoded><![CDATA[<h4>N-Queens Part 1</h4><p>I won’t spend time introducing the n-queens puzzle here; if you’re unfamiliar with it, a quick trip to <a href="https://en.wikipedia.org/wiki/Eight_queens_puzzle">Wikipedia</a> will get you up to speed. Instead, I want to share my personal journey with this classic challange.</p><h4>A Competition Fueled by Sugar</h4><p>I was first introduced to the n-queens puzzle during my days as a junior software test engineer. My manager at the time and I shared a love for puzzles, and he had spent a significant portion of his PhD studying this one. Looking for a companion, or perhaps just some friendly competition, he challanged me to a race: we would both implement a backtracking solver, and the fastest code would win.</p><p>In the end, my solver took the crown. To be fair, looking back, I suspect he may have chosen MATLAB — and perhaps a less-than-optimal approach — just to give his junior engineer a shot at victory. Whether it was a technical oversight on his part or a subtle act of mentorship, the result was the same: a small late-afternoon gathering fueled by victory cake, provided by the ‘loser’ with a smile.</p><h4>Two Decades Down the Rabbit Hole</h4><p>It has been 20 years since that first race, and I still find myself returning to the N-Queens problem. Over the decades, I’ve explored its many facets: from analytical solvers and backtracking optimizations to D4-symmetric groups, the toroidal version of the board, and the search for fundamental solutions or maximal independent sets of the conflict graph.</p><p>In this article, I want to share something I’m particularly proud of creating 😃. While I plan to dive into the technical and mathematical nuances in future posts, let’s start with the visual beauty of the puzzle.</p><h4>Visualizing the Solutions</h4><p>Below is an iteration through all possible solutions for the 8-Queens puzzle (there are 92 of them):</p><figure><img alt="An animated gif iterating over all 92 solutions of the 8-quuens problem" src="https://cdn-images-1.medium.com/max/660/1*x66ypFSR9UUxqNyv1i2a7w.gif" /></figure><p>And here is a look at the “thought process” of the machine — a visualization of the backtracking algorithm in action for 5-queens:</p><figure><img alt="An animated gif that iterates over the backtracking algorithm steps for 5-queens." src="https://cdn-images-1.medium.com/max/420/1*Ufv4GX15O-79W5hEIi6-ng.gif" /></figure><h4>The Backtracking Logic</h4><p>Below is the core Python logic used to generate solutions for the general N-Queens puzzle. A word of caution: <strong>be careful when setting <em>n</em> to a large number.</strong></p><p>The complexity of the problem grows exponentially. At the time of writing, the world record for finding all solutions stands at <a href="https://github.com/preusser/q27"><em>n = 27</em></a>. That feat took approximately one year to complete using specialized hardware and massive distributed computing efforts. For a standard laptop, anything beyond <em>n = 15</em> will likely start to test your patience!</p><pre>class BacktrackSolver:<br>    <br>    @staticmethod<br>    def solve(n : int) -&gt; list[tuple[int, ...]]:<br>        rows = [-1] * n<br>        solutions = []<br>        <br>        def is_valid(r: int, c: int) -&gt; bool:<br>            s = r + c # all squares in the same anti-diagonals have this same value.<br>            d = c - r # all squares in the same diagonals have this same value.<br> <br>            for i in range(r):<br>                if rows[i] == c or d == (rows[i] - i)  or s == (i + rows[i]):<br>                    return False<br>            return True<br>    <br>        def place_queen(r: int):<br>            for c in range(n):<br>                rows[r] = c                         # place the queen<br>                if is_valid(r, c):<br>                    if r == n - 1:                  # if we placed the queen to the last row.<br>                        solutions.append(tuple(rows)) # we found a solution<br>                    else:       <br>                        place_queen(r + 1)          # continue with the next row<br>                rows[r] = -1                        # take back the queen placement<br><br>        place_queen(0)<br>        return solutions<br>    <br>    @staticmethod<br>    def steps(n : int) -&gt; list[tuple[int | str, ...]]:<br>        rows = [-1] * n<br>        steps = [tuple(rows)]<br>        num_solutions = 0<br><br>        def is_valid(r: int, c: int) -&gt; bool:<br>            s = r + c # all squares in the same anti-diagonals have this same value.<br>            d = c - r # all squares in the same diagonals have this same value.<br> <br>            for i in range(r):<br>                if rows[i] == c or d == (rows[i] - i)  or s == (i + rows[i]):<br>                    return False<br>            return True<br>    <br>        def place_queen(r: int):<br>            nonlocal num_solutions<br>            for c in range(n):<br>                rows[r] = c<br>                steps.append(tuple(rows))<br>                if is_valid(r, c):<br>                    if r == n - 1:                  <br>                        num_solutions += 1<br>                    else:       <br>                        place_queen(r + 1)<br>                rows[r] = -1<br>        <br>        place_queen(0)<br>        return steps</pre><h4>The Secret of the Diagonals</h4><p>The most computationally expensive part of the puzzle is checking for conflicts. While checking rows and columns is simple, checking diagonals can be tricky. In the code above, I used a mathematical shortcut:</p><ul><li><strong>Anti-Diagonals (<em>r + c</em>):</strong> Every square on a “slash” diagonal (bottom-left to top-right) shares the same sum.</li><li><strong>Diagonals (<em>c — r</em>):</strong> Every square on a “backslash” diagonal (top-left to bottom-right) shares the same difference.</li></ul><p>By comparing these values, the algorithm can determine if a queen is under attack using simple arithmetic rather than searching the entire board.</p><h4>What’s Next?</h4><p>If you are interested in the code used to generate the GIFs, leave a comment below! I am planning to move the full visualizer to a GitHub repository soon, but if there’s enough interest, I’ll prioritize getting it published faster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a10e7478f026" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>