<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>0xWick</title>
        <link>https://paragraph.com/@0xwick</link>
        <description>Geek Polymath writing about tech, writing what I learn into simple terms.
Solidity, Web3, Blockchain, AI, Math, Programming, AR/VR ...</description>
        <lastBuildDate>Sun, 03 May 2026 14:19:49 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>en</language>
        <image>
            <title>0xWick</title>
            <url>https://storage.googleapis.com/papyrus_images/2021a0b01d5da504e66ffdbf706e42fba89172b4ee536288442bd3d71279b3a7.jpg</url>
            <link>https://paragraph.com/@0xwick</link>
        </image>
        <copyright>All rights reserved</copyright>
        <item>
            <title><![CDATA[Python Sudoku Solver]]></title>
            <link>https://paragraph.com/@0xwick/python-sudoku-solver</link>
            <guid>0a3VwEsjHnlwv7cAKQFX</guid>
            <pubDate>Thu, 14 Jul 2022 16:57:33 GMT</pubDate>
            <description><![CDATA[Lazy way to Solve Sudoku with Python!Programming HumoorIntroduction: I am writing this article for record in future and also for keeping a note of my journey in Programming. I will try to write one blog every week about fun projects of Programming. My focus will be mostly about Python and Machine Learning or AI in general. I might also do some introductory ones on Blockchain and Cryptography. Let’s see how it turns out! Inspiration: I had the idea of making a Python Sudoku Solver for a while ...]]></description>
            <content:encoded><![CDATA[<h3 id="h-lazy-way-to-solve-sudoku-with-python" class="text-2xl font-header !mt-6 !mb-4 first:!mt-0 first:!mb-0">Lazy way to Solve Sudoku with Python!</h3><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/190af0d88940c822434b919f607aeb6bd80ac0ae43b572b6356dde07aec7b6b7.jpg" alt="Programming Humoor" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Programming Humoor</figcaption></figure><p><strong>Introduction:</strong></p><p>I am writing this article for record in future and also for keeping a note of my journey in Programming. I will try to write one blog every week about fun projects of Programming. My focus will be mostly about Python and Machine Learning or AI in general. I might also do some introductory ones on Blockchain and Cryptography. Let’s see how it turns out!</p><p><strong>Inspiration:</strong></p><p>I had the idea of making a Python Sudoku Solver for a while now. While I was watching Computerphile videos on YouTube I came across a video about a Python Sudoku Solver. But it was very much on-point and not so much self-explanatory.So, I decided to break each step down and explain at a beginner level.</p><p>If you are familiar with the rules of Sudoku Puzzle, you can skip the next Paragraph.</p><p><strong>Sudoku:</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/f40f460dabd34293a8fd04a5b1c9811c0fdc39fba4fb2d3eec16f4d159265351.jpg" alt="Image Credit: ”https://www.freepik.com/photos/puzzle\*&quot;" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Image Credit: ”https://www.freepik.com/photos/puzzle\*&quot;</figcaption></figure><p>It’s a <strong>9 X 9</strong> grid of boxes</p><p>Basically, its a game with 3 main rules. You have to put a number (or integer in programming terms) in all boxes. But Numbers mustn&apos;t repeat in the same</p><ol><li><p><strong>Row</strong></p></li><li><p><strong>Column</strong></p></li><li><p><strong>Box (3X3)</strong></p></li></ol><p>***Note: ***There can be more than 1 solution to a Sudoku Puzzle.</p><p>With that out of the way, let’s get technical now!</p><p><strong>Main Concepts:</strong></p><p>I have listed some main concepts that will be used in this tutorial. Although, I have tried to explain it but you can use Youtube or Google too to get a better understanding.</p><ol><li><p><strong>Arrays</strong> *(2d lists, Indexing) *</p><p><strong>or</strong></p><p><strong>Numpy</strong> *(Very Basic - Matrix only) *</p></li><li><p><strong>Recursion</strong> <em>(It’s roughly like inception movie)</em><strong>.</strong> Watch this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://(https://www.youtube.com/watch?v=Mv9NEXX1VHc&amp;ab_channel=Computerphile)">video</a></p></li><li><p><strong>BackTracking</strong> <em>(Trial &amp; Error)</em></p></li><li><p><strong>A little Math</strong> <em>(Floor division, and basic arithmetic)</em></p></li><li><p><strong>Loops</strong> (for loops, nested loops)</p></li></ol><p><em>Let’s get started:</em></p><p>First, assign the rows as lists into a single list. (You will find out why its important.)</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/b9499204f6f3595bb680ff2c2801c0ab0a846ecd9b5b84e9f459ad238e2d3c12.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>We will do it in three sections.</p><ol><li><p>Checking the number in row</p></li><li><p>Checking the number in column</p></li><li><p>Checking the number in the box</p></li></ol><p>We will define a function for checking row and then add column check to it. We will do a different function for the box (because it’s a little more complicated)</p><p><strong>-Checking the number in the row:</strong></p><p>Let’s start with checking if the number we want is in the same row or not. We can use a simple for loop that will check every number in the row we give as argument in the function.</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/c6ff9acdd30b39dd37d2edf9e9136a83e0afe9777aad0848d62f147c3eac3e7c.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>This function will return False if the number (n) is already in the row we defined.</p><p><strong>-Checking the number in the column:</strong></p><p>Now let’s add the column check into this function…</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/d6b4958d1eeca58d98107f70a74aab222956f73025f1e943549c848019907c52.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>This function return False if the number (n) is either in the same column or row.</p><p><strong>-Checking the number in the box(3X3):</strong></p><p>For checking the box you need to know a bit about a mathematical term known as <strong>Floor Division</strong> (Google or Youtube pls).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/e7b28b544da7898130c91df6f1cdda6797166afeeffa44d6114c61c869c06759.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>First two lines are the math. In simple words, it resets the grid to a specific number for a bunch of numbers. We use this to get the start of the box for any number in any box. Like, the start will be 0 if x = 0 or 1 or 2. Similarly, start is 3 if x = 3 or 4 or 5 and 6 while x = 6 or 7 or 8. See, how this resets the any number in a block to the starting point of that block.</p><p>Moving on, we use nested for loop with range 3. To check 3x3 boxes of the Box. Also, we add the i and j into x0 and j0 respectively to checking the next block and the next block so on to the last block in the box. With this we can loop (i and j) and check all 9 blocks 1-by-1 to see if number (n) is already in the box or not.</p><p><strong>First Section wind up:</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/bcaf5ac1f8182662870ef575941e6fc55c6bf0c842f507cc5b82985f287501c5.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>So far, we have made a checker to see if its possible to put a number at a specific position in the puzzle. But as Programming our laziness urge us to automate the whole process. Instead of checking every box manually.</p><p>Also, the second section isn’t only for automation but it gives another important function to our program i.e. Trial and Error. Because <strong>possible()</strong> only tell us if a number can be placed in a specific position but there can be many possibilities for a specific position. Our choice now can prove to be wrong later. That’s why we need Trial and Error (<em>Backtracking and Recursion</em>).</p><p><strong>Second Section:</strong></p><p>We loop through all numbers 0–8 in rows and columns to check the position with possible(). But first we check if the position is empty i.e. 0. Then use possible() and a loop to check which of the number we can put there <strong>currently (we might be wrong and won’t put the same number again and again hence I use</strong> able to put currently)</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/7b4a72519d916b1eb79c79dc7042cfb5d154890f458b96a137810a4a37ae47eb.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>Now we are going to use the most important and complicated method to solve this puzzle.</p><p><strong>Recursion: Try to understand recursion using this meme:</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/3e6c286d65117d934a62a10bc44cc5a5ec35339ab28136eb74fae3d4118948e7.png" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>Look how you got the answer at 5th recursion. That’s when you get out of the recursion. Use the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.youtube.com/watch?v=Mv9NEXX1VHc&amp;ab_channel=Computerphile">computerphile video</a> with above meme to understand it properly!</p><p>Simply put in this method, we keep finding the answer and putting it in the empty spot until we can’t find the answer for the next empty position. In which case, we return. But we returned from a recursed function not the main or most outer function. Re-watch the recursion video if you feel lost.</p><p><strong>Back-Tracking:</strong></p><p>Basically, Trying all possible options (and seeing if they fit together).</p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/a5b5ec834a6bf5f7ec801381185dcd18c6921e06a8c538deae1cb9689a9eeb81.jpg" alt="" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="hide-figcaption"></figcaption></figure><p>So, if we fail to find all answers with a number we simply change it to zero and try the next number. Google: Backtracking. To understand how we use Trial and Error to solve this.</p><p>This process of recursion and backtracking will keep going on until we find the answers to all empty spaces that satisfy our conditions in possible().</p><p>That’s when we return from our main function or the most outer layer of our function.</p><p><strong>Finally,</strong></p><figure float="none" data-type="figure" class="img-center" style="max-width: null;"><img src="https://storage.googleapis.com/papyrus_images/2765fdeb58c1dd26ae2cf56058ba5b3b5ec9b9621648dfa7e7dfe8f61833c34c.png" alt="Final Code" blurdataurl="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=" nextheight="600" nextwidth="800" class="image-node embed"><figcaption HTMLAttributes="[object Object]" class="">Final Code</figcaption></figure><p>If you feel lost at any point regarding Backtracking or Recursion just Google or Find <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.youtube.com/watch?v=G_UYXzGuqvM">Computerphile&apos;s tutorial</a> on YouTube about it.</p><p>Also watch this <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://www.youtube.com/watch?v=G_UYXzGuqvM&amp;ab_channel=Computerphile">video</a> for a overview of this puzzle.</p><p>Well, that was my first article and I hope to get better at writing and my Knowledge. Stay tuned for further Python Fun Projects and Computer Science (Especially ML, AI, Crypto and Tech) related Blogs.</p><p>JazakAllah for reading and your feedback means a lot for me.</p><p>This Blog is also a bookmark for my future self to compare if I am better today when I was at the time of writing this!</p><p>Here is the <a target="_blank" rel="noopener noreferrer nofollow ugc" class="dont-break-out" href="https://github.com/0xWick/Sudoku-Solver">Github repo</a> for the code, enjoy!</p><p>Process finished with exit code 0</p>]]></content:encoded>
            <author>0xwick@newsletter.paragraph.com (0xWick)</author>
            <enclosure url="https://storage.googleapis.com/papyrus_images/dc163e02a98cea7735e0138b8831eac93ac0212523646481e95ad407c5237c58.jpg" length="0" type="image/jpg"/>
        </item>
    </channel>
</rss>