Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Ad icon
Video Content Creator
pramukag
Updated:
Today at 6:10 AM
Ad icon
QA Engineer Intern
pramukag
Updated:
Today at 6:07 AM
Ad icon
Sell your Land, House on idamata.lk for FREE
sajith.xp.pk
Updated:
Thursday at 9:03 AM
Handmade Character Soft Toys
anil1961
Updated:
Tuesday at 2:11 PM
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Jun 21, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Solve Sudoku Puzzle[C#]
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Scattered123" data-source="post: 22384186" data-attributes="member: 440759"><p>දැන් ටික කාලෙකට මගේ පරණ යාලුවෙක් ආව කැම්පස් එකේ Computer Science කරන එකෙක්. උන්ට ඇගයීමක් දීලා තිබ්බා සුදොකු පස්ල් එකක් විසදන්න. මේ මම ඒකට ලියපු කෝඩ් එකක්, C# වලින් තියෙන්නෙ. කිරියෙ කාට හරි උවමනාවක් වෙයි කියල හිතුන.</p><p></p><p>අලුතෙන් ප්රෝග්රැමින් කරන උන්ට වැදගත් වෙයි. <img src="/styles/default/xenforo/smilies/default/rolleyes.gif" class="smilie" loading="lazy" alt=":rolleyes:" title="Rolleyes :rolleyes:" data-shortname=":rolleyes:" /></p><p></p><p>[CODE]using System;</p><p>using System.Collections.Generic;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Threading.Tasks;</p><p></p><p>namespace ConsoleApplication1</p><p>{</p><p> class Program</p><p> {</p><p></p><p> static int roww = 0;</p><p> static int coll = 0;</p><p></p><p> static int[,] puzzle = new int[,]</p><p> {</p><p> {6, 0, 0, 0, 7, 8, 0, 0, 0},</p><p> {0, 0, 4, 6, 0, 0, 0, 8, 0},</p><p> {3, 0, 5, 0, 0, 9, 7, 0, 0},</p><p> </p><p> {5, 0, 3, 8, 0, 7, 0, 0, 0},</p><p> {8, 0, 9, 4, 0, 6, 3, 0, 5},</p><p> {0, 0, 0, 9, 0, 3, 8, 0, 7},</p><p></p><p> {0, 0, 8, 3, 0, 0, 6, 0, 2},</p><p> {0, 2, 0, 0, 0, 1, 4, 0, 0},</p><p> {0, 0, 0, 7, 8, 0, 0, 0, 1}</p><p> };</p><p></p><p> static void Main(string[] args)</p><p> {</p><p> Solver();</p><p> Console.Read();</p><p> }</p><p></p><p> static void Solver()</p><p> {</p><p> int count = 0;</p><p> for (int q = 0; q < 9; q++)</p><p> {</p><p> roww = q;</p><p> for (int w = 0; w < 9; w++)</p><p> {</p><p> coll = w;</p><p> if (puzzle[q, w] == 0)</p><p> {</p><p> count++;</p><p> Solve();</p><p> }</p><p> }</p><p> }</p><p> if (count != 0)</p><p> {</p><p> Solver();</p><p> }</p><p> else</p><p> {</p><p> for (int i = 0; i < 9; i++)</p><p> {</p><p> for (int w = 0; w < 9; w++)</p><p> {</p><p> Console.Write(puzzle[i, w] + " ");</p><p> }</p><p> Console.WriteLine("");</p><p> }</p><p> }</p><p> }</p><p></p><p> static void Solve()</p><p> {</p><p></p><p> List<int> ios = new List<int>();</p><p> List<int> ios2 = new List<int>();</p><p></p><p> for (int i = 0; i < 9; i++)</p><p> {</p><p> if (puzzle[roww, i] != 0)</p><p> {</p><p> ios.Add(puzzle[roww, i]);</p><p> //Console.WriteLine(puzzle[roww, i]);</p><p></p><p> }</p><p></p><p> }</p><p> //Console.WriteLine("\n");</p><p> for (int i = 0; i < 9; i++)</p><p> {</p><p> if (puzzle[i, coll] != 0)</p><p> {</p><p> ios.Add(puzzle[i, coll]);</p><p> //Console.WriteLine(puzzle[i, coll]);</p><p> }</p><p> }</p><p> //Console.WriteLine("\n");</p><p></p><p></p><p> for (int a = 1; a <= 9; a++)</p><p> {</p><p> if (!ios.Contains(a))</p><p> {</p><p> ios2.Add(a);</p><p></p><p> //Console.WriteLine(a);</p><p> }</p><p> }</p><p> //Console.WriteLine("\n");</p><p> int ia = 0;</p><p> int b = 0;</p><p> List<int> ioss = ios2;</p><p> int[] onto = ios2.ToArray();</p><p></p><p> foreach (int val in ios2)</p><p> {</p><p> if (CheckRegion(val) != 1)</p><p> {</p><p> ia++;</p><p> }</p><p> }</p><p></p><p> if (ia == 1)</p><p> {</p><p> for (int i = 0; i < ios2.Count; i++)</p><p> {</p><p> if (CheckRegion(ios2[i]) != 1)</p><p> {</p><p> b = i;</p><p> }</p><p> }</p><p> }</p><p></p><p> if (ia == 1)</p><p> {</p><p> //Console.WriteLine(roww + "-" + coll + "-" + ios2[b]);</p><p> puzzle[roww, coll] = ios2[b];</p><p> //Solve();</p><p> }</p><p> else</p><p> {</p><p> </p><p> //Solve();</p><p> }</p><p></p><p> //Console.WriteLine(ia);</p><p> }</p><p></p><p> static int CheckRegion(int value)</p><p> {</p><p> int rows = 0;</p><p> int cols = 0;</p><p></p><p> if (roww >= 0 && roww < 3)</p><p> {</p><p> rows = 3;</p><p> }</p><p> if (roww >= 3 && roww < 6)</p><p> {</p><p> rows = 6;</p><p> }</p><p> if (roww >= 6 && roww < 9)</p><p> {</p><p> rows = 9;</p><p> }</p><p></p><p> if (coll >= 0 && coll < 3)</p><p> {</p><p> cols = 3;</p><p> }</p><p> if (coll >= 3 && coll < 6)</p><p> {</p><p> cols = 6;</p><p> }</p><p> if (coll >= 6 && coll < 9)</p><p> {</p><p> cols = 9;</p><p> }</p><p></p><p></p><p> for (int i = rows - 3; i < 3 + (rows - 3); i++)</p><p> {</p><p> for (int j = cols - 3; j < 3 + (cols - 3); j++)</p><p> {</p><p> if (puzzle[i, j] == value)</p><p> {</p><p> return 1;</p><p> }</p><p> }</p><p> }</p><p> return 0;</p><p> }</p><p></p><p> static int CheckIfZero()</p><p> {</p><p> return 0;</p><p> }</p><p> }</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="Scattered123, post: 22384186, member: 440759"] දැන් ටික කාලෙකට මගේ පරණ යාලුවෙක් ආව කැම්පස් එකේ Computer Science කරන එකෙක්. උන්ට ඇගයීමක් දීලා තිබ්බා සුදොකු පස්ල් එකක් විසදන්න. මේ මම ඒකට ලියපු කෝඩ් එකක්, C# වලින් තියෙන්නෙ. කිරියෙ කාට හරි උවමනාවක් වෙයි කියල හිතුන. අලුතෙන් ප්රෝග්රැමින් කරන උන්ට වැදගත් වෙයි. :rolleyes: [CODE]using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static int roww = 0; static int coll = 0; static int[,] puzzle = new int[,] { {6, 0, 0, 0, 7, 8, 0, 0, 0}, {0, 0, 4, 6, 0, 0, 0, 8, 0}, {3, 0, 5, 0, 0, 9, 7, 0, 0}, {5, 0, 3, 8, 0, 7, 0, 0, 0}, {8, 0, 9, 4, 0, 6, 3, 0, 5}, {0, 0, 0, 9, 0, 3, 8, 0, 7}, {0, 0, 8, 3, 0, 0, 6, 0, 2}, {0, 2, 0, 0, 0, 1, 4, 0, 0}, {0, 0, 0, 7, 8, 0, 0, 0, 1} }; static void Main(string[] args) { Solver(); Console.Read(); } static void Solver() { int count = 0; for (int q = 0; q < 9; q++) { roww = q; for (int w = 0; w < 9; w++) { coll = w; if (puzzle[q, w] == 0) { count++; Solve(); } } } if (count != 0) { Solver(); } else { for (int i = 0; i < 9; i++) { for (int w = 0; w < 9; w++) { Console.Write(puzzle[i, w] + " "); } Console.WriteLine(""); } } } static void Solve() { List<int> ios = new List<int>(); List<int> ios2 = new List<int>(); for (int i = 0; i < 9; i++) { if (puzzle[roww, i] != 0) { ios.Add(puzzle[roww, i]); //Console.WriteLine(puzzle[roww, i]); } } //Console.WriteLine("\n"); for (int i = 0; i < 9; i++) { if (puzzle[i, coll] != 0) { ios.Add(puzzle[i, coll]); //Console.WriteLine(puzzle[i, coll]); } } //Console.WriteLine("\n"); for (int a = 1; a <= 9; a++) { if (!ios.Contains(a)) { ios2.Add(a); //Console.WriteLine(a); } } //Console.WriteLine("\n"); int ia = 0; int b = 0; List<int> ioss = ios2; int[] onto = ios2.ToArray(); foreach (int val in ios2) { if (CheckRegion(val) != 1) { ia++; } } if (ia == 1) { for (int i = 0; i < ios2.Count; i++) { if (CheckRegion(ios2[i]) != 1) { b = i; } } } if (ia == 1) { //Console.WriteLine(roww + "-" + coll + "-" + ios2[b]); puzzle[roww, coll] = ios2[b]; //Solve(); } else { //Solve(); } //Console.WriteLine(ia); } static int CheckRegion(int value) { int rows = 0; int cols = 0; if (roww >= 0 && roww < 3) { rows = 3; } if (roww >= 3 && roww < 6) { rows = 6; } if (roww >= 6 && roww < 9) { rows = 9; } if (coll >= 0 && coll < 3) { cols = 3; } if (coll >= 3 && coll < 6) { cols = 6; } if (coll >= 6 && coll < 9) { cols = 9; } for (int i = rows - 3; i < 3 + (rows - 3); i++) { for (int j = cols - 3; j < 3 + (cols - 3); j++) { if (puzzle[i, j] == value) { return 1; } } } return 0; } static int CheckIfZero() { return 0; } } } [/CODE] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom