<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://jholjhapata.com/index.php?action=history&amp;feed=atom&amp;title=SudokuSolver</id>
	<title>SudokuSolver - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://jholjhapata.com/index.php?action=history&amp;feed=atom&amp;title=SudokuSolver"/>
	<link rel="alternate" type="text/html" href="https://jholjhapata.com/index.php?title=SudokuSolver&amp;action=history"/>
	<updated>2026-08-25T14:41:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://jholjhapata.com/index.php?title=SudokuSolver&amp;diff=151&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;Here’s a simple Sudoku Solver in C# using backtracking. It works on a standard 9x9 Sudoku grid.   SudokuSolver      using System;     using S...&quot;</title>
		<link rel="alternate" type="text/html" href="https://jholjhapata.com/index.php?title=SudokuSolver&amp;diff=151&amp;oldid=prev"/>
		<updated>2025-06-01T08:13:52Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Here’s a simple Sudoku Solver in C# using backtracking. It works on a standard 9x9 Sudoku grid.   &lt;a href=&quot;/wiki/File:SudokuSolver.png&quot; title=&quot;File:SudokuSolver.png&quot;&gt;thumb|SudokuSolver&lt;/a&gt;      using System;     using S...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Here’s a simple Sudoku Solver in C# using backtracking. It works on a standard 9x9 Sudoku grid.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:SudokuSolver.png|thumb|SudokuSolver]]&lt;br /&gt;
&lt;br /&gt;
    using System;&lt;br /&gt;
    using System.Collections.Generic;&lt;br /&gt;
    using System.Linq;&lt;br /&gt;
    using System.Text;&lt;br /&gt;
    using System.Threading;&lt;br /&gt;
    using System.Threading.Tasks;&lt;br /&gt;
    namespace sudoku_console&lt;br /&gt;
    {&lt;br /&gt;
        internal class Program&lt;br /&gt;
        {&lt;br /&gt;
            static int SIZE = 9;&lt;br /&gt;
            public static void Main()&lt;br /&gt;
            {&lt;br /&gt;
                int[,] board = {&lt;br /&gt;
                {5, 3, 0, 0, 7, 0, 0, 0, 0},&lt;br /&gt;
                {6, 0, 0, 1, 9, 5, 0, 0, 0},&lt;br /&gt;
                {0, 9, 8, 0, 0, 0, 0, 6, 0},&lt;br /&gt;
                {8, 0, 0, 0, 6, 0, 0, 0, 3},&lt;br /&gt;
                {4, 0, 0, 8, 0, 3, 0, 0, 1},&lt;br /&gt;
                {7, 0, 0, 0, 2, 0, 0, 0, 6},&lt;br /&gt;
                {0, 6, 0, 0, 0, 0, 2, 8, 0},&lt;br /&gt;
                {0, 0, 0, 4, 1, 9, 0, 0, 5},&lt;br /&gt;
                {0, 0, 0, 0, 8, 0, 0, 7, 9}&lt;br /&gt;
            };&lt;br /&gt;
                if (Solve(board))&lt;br /&gt;
                {&lt;br /&gt;
                    PrintBoard(board);&lt;br /&gt;
                    Console.ReadLine();&lt;br /&gt;
                }&lt;br /&gt;
                else&lt;br /&gt;
                {&lt;br /&gt;
                    Console.WriteLine(&amp;quot;No solution exists.&amp;quot;);&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
            static bool Solve(int[,] board, bool isTimer = false)&lt;br /&gt;
            {&lt;br /&gt;
                for (int row = 0; row &amp;lt; SIZE; row++)&lt;br /&gt;
                {&lt;br /&gt;
                    for (int col = 0; col &amp;lt; SIZE; col++)&lt;br /&gt;
                    {&lt;br /&gt;
                        if (board[row, col] == 0)&lt;br /&gt;
                        {&lt;br /&gt;
                            for (int num = 1; num &amp;lt;= 9; num++)&lt;br /&gt;
                            {&lt;br /&gt;
                                if (IsValid(board, row, col, num))&lt;br /&gt;
                                {&lt;br /&gt;
                                    board[row, col] = num;&lt;br /&gt;
                                    if (isTimer)&lt;br /&gt;
                                        Thread.Sleep(1000);&lt;br /&gt;
                                    if (Solve(board))&lt;br /&gt;
                                        return true;&lt;br /&gt;
                                    board[row, col] = 0; // backtrack&lt;br /&gt;
                                }&lt;br /&gt;
                            }&lt;br /&gt;
                            return false; // no valid number found&lt;br /&gt;
                        }&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                return true; // board is solved&lt;br /&gt;
            }&lt;br /&gt;
            static bool IsValid(int[,] board, int row, int col, int num)&lt;br /&gt;
            {&lt;br /&gt;
                for (int x = 0; x &amp;lt; SIZE; x++)&lt;br /&gt;
                {&lt;br /&gt;
                    if (board[row, x] == num || board[row, x] == num)&lt;br /&gt;
                        return false;&lt;br /&gt;
                }&lt;br /&gt;
                for (int x = 0; x &amp;lt; SIZE; x++)&lt;br /&gt;
                {&lt;br /&gt;
                    if (board[x, col] == num || board[x, col] == num)&lt;br /&gt;
                        return false;&lt;br /&gt;
                }&lt;br /&gt;
                int startRow = row / 3 * 3;&lt;br /&gt;
                int startCol = col / 3 * 3;&lt;br /&gt;
                for (int i = 0; i &amp;lt; 3; i++)&lt;br /&gt;
                {&lt;br /&gt;
                    for (int j = 0; j &amp;lt; 3; j++)&lt;br /&gt;
                    {&lt;br /&gt;
                        if (board[startRow + i, startCol + j] == num)&lt;br /&gt;
                            return false;&lt;br /&gt;
                    }&lt;br /&gt;
                }&lt;br /&gt;
                return true;&lt;br /&gt;
            }&lt;br /&gt;
            static void PrintBoard(int[,] board)&lt;br /&gt;
            {&lt;br /&gt;
                for (int i = 0; i &amp;lt; SIZE; i++)&lt;br /&gt;
                {&lt;br /&gt;
                    for (int j = 0; j &amp;lt; SIZE; j++)&lt;br /&gt;
                    {&lt;br /&gt;
                        Console.Write(board[i, j] + &amp;quot; &amp;quot;);&lt;br /&gt;
                    }&lt;br /&gt;
                    Console.WriteLine();&lt;br /&gt;
                }&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>