A Developer Journey who codes for fun

Daily Dose Of Code

  • Home
  • Dot.Net Basics
    • .Net Basics
      • CTS
      • CLS
      • CLR
      • Strong Vs Weak Ref
      • .Net Framework
      • What is Manifest
    • Memory Management
      • Garbage Collection 1
      • Garbage Collection 2
      • Circular Reference
  • C Sharp
    • Abstract Class in C#
    • Interfaces in C#
    • Value type by Val and By Ref
    • Var keyword
    • Null Coalescing Operator
    • Buit-in code snippets
  • OOPS
    • Abstraction and Encapsulation
    • Polymorphism
    • Inheritence
    • Aggregation
  • Threading
    • Delegates
      • Calling Delegate using Invoke, BeginInvoke
      • Multicast Delegate
      • Exception Handling in Multicast Delegate
      • Action
      • Predicate
      • Func
    • Synchronization
    • Thread Pool
    • Exception Handling
    • TPL
  • Design Pattern
    • Creational Patterns
      • Singleton Pattern
      • Factory Pattern
      • Abstract Factory Pattern
      • Prototype Pattern
      • Builder Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Proxy Pattern
      • Facade Pattern
      • Decorator Pattern
      • Flyweight Pattern
    • Behavioral Patterns
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
      • Visitor Pattern
      • Chain Of Responsibility Pattern
      • Template Pattern
  • Data Structures
    • Generic List in C#
    • 2d array to 1d array
    • 3d arrayto 1d array
    • Linked List
      • Singly Linked List in C#
    • Queue
      • Dummy Data 1
    • Stack
      • Dummy Data 2
    • Tree
      • Dummy Data 3
    • Graph
      • Dummy Data 4
  • WCF
    • WCF Service using VS 2015
  • Scripts
    • Chrome Extensions
      • Create a Chrome Extension
      • Facebook autologout script
      • Gmail autologout script

Sudoku-Checker in ASP.Net using C#

 Unknown     2:49 AM     No comments   

# region directives

using System;
using System.Collections;

#endregion


namespace sudokuChecker
{

class SudokuMainExample
{
static void Main()
{
SudokuCheck objectSudokuCheck = new SudokuCheck();
int[,] Board=new int[9,9];
int countnumberofInput=0;
string menuStatus="y";
string readInput="n";

try
{
Console.WriteLine("You Are Entering In Sudoku Checker:----");
for (int indexRow = 0; indexRow < 9; indexRow++)
{
for (int indexColumn = 0; indexColumn < 9; indexColumn++)
{
Board[indexRow, indexColumn] = 0;
}

}

do
{
/*try
{
Console.WriteLine("PLease Enter The Size of Row To Start The Game:--");
int row = Int32.Parse(Console.ReadLine());
Console.WriteLine("Lease Enter The Size of Row To Start The Game:--");
int column = Int32.Parse(Console.ReadLine());
if ((row != 9) && (column != 9))
throw new Exception("error");
else
Board = new int[row, column];
for (int indexRow = 0; indexRow < row; indexRow++)
{
for (int indexColumn = 0; indexColumn < column; indexColumn++)
{
Board[indexRow, indexColumn] = 0;
}

}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Your Input Is Not Valid Please Input A Right One ");
Console.WriteLine("If You Want To Input It Again then press :-Y otherwise Press N .");
readInput = (Console.ReadLine());
}*/
while ((menuStatus == "Y") || (menuStatus == "y"))
{
Console.WriteLine("You Have Some Choices:--");
Console.WriteLine("Press:-1 To Give Input In Sudoku Game:-");
Console.WriteLine("Press:-2 To Check Status");
Console.WriteLine("Press:-3 To Put Default Right Values:-");
Console.WriteLine("Press:-4 To Put Default Wrong Values:-");
Console.WriteLine("Press:-5 To Exit From The Menu Status:-");
int readChoice = Int32.Parse(Console.ReadLine());
switch (readChoice)
{
case 1:
int choiceCheck = 0;
while (choiceCheck != 1)
{
Console.WriteLine("Please Input A Row Number Where You Want To Put The Input");
int inputRow = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please Input A Column Number Where You Want to Put The Input");
int inputColumn = Int32.Parse(Console.ReadLine());
Console.WriteLine("Please Input The Value You Want To Fill In This Particular Space");
int inputValue = Int32.Parse(Console.ReadLine());
if ((inputValue > 9) || (inputValue < 1))
{
Console.WriteLine("You Input Value Is Not Valid Please Input A Valid Value");
choiceCheck = 0;
}
else
{
choiceCheck = 1;
if (countnumberofInput != 81)
{
countnumberofInput++;
objectSudokuCheck.UserInputSudoku(inputRow, inputColumn, inputValue,Board);
}
else
{
Console.WriteLine("Board Has Already Filled");
Console.WriteLine("Now Check The status of Sudoku Game.");
}
}
}
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 2:
Console.WriteLine("We Are Going To Check the Status Of Sudoku Game");
SudokuCheck.Status obj= objectSudokuCheck.CheckSudokuStatus(Board);
Console.WriteLine(obj);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 3:
Console.WriteLine("We Are Going To Put Default Right Values");
objectSudokuCheck.InputDefaultRightValues(Board);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 4:
Console.WriteLine("We Are Going To Put Default Wrong Values");
objectSudokuCheck.InputDefaultWrongValues(Board);
Console.WriteLine("If You Again Want To Go To The Main menu Then Press Y To Continue Otherwise Press Any Button");
menuStatus = Console.ReadLine();
break;
case 5:
Console.WriteLine("We Are Exiting From The Program");
menuStatus = "N";
Console.WriteLine("If You Want To Input It Again then press :-Y otherwise Press N .");
readInput = (Console.ReadLine());
break;
default:
Console.WriteLine("Invalid Choice");
break;
}
}


} while (readInput == "y");
}
catch (Exception e)
{
Console.WriteLine("Your Input Is Not Valid:--");
Console.WriteLine("Do You Wanna Input It Again:--");
Console.ReadKey();
}
}
}
}



using System;
using System.Collections;

namespace sudokuChecker
{
class SudokuCheck
{
public enum Status
{
Success = 0,
Failure = 1,
Continue = 2
}
public void UserInputSudoku(int inputRow, int inputColumn, int inputValue,int [,]Board)
{
Board[inputRow,inputColumn] = inputValue;
}
public void InputDefaultWrongValues(int[,] Board)
{
Board[0, 0] = 9; Board[0, 1] = 6; Board[0, 2] = 1; Board[0, 3] = 1;
Board[0, 4] = 4; Board[0, 5] = 8; Board[0, 6] = 2; Board[0, 7] = 7;
Board[0, 8] = 3; Board[1, 0] = 8; Board[1, 1] = 7; Board[1, 2] = 2;
Board[1, 3] = 9; Board[1, 4] = 3; Board[1, 5] = 1; Board[1, 6] = 6;
Board[1, 7] = 4; Board[1, 8] = 5; Board[2, 0] = 6; Board[2, 1] = 5;
Board[2, 2] = 3; Board[2, 3] = 3; Board[2, 4] = 2; Board[2, 5] = 7;
Board[2, 6] = 8; Board[2, 7] = 9; Board[2, 8] = 1; Board[3, 0] = 5;
Board[3, 1] = 8; Board[3, 2] = 9; Board[3, 3] = 3; Board[3, 4] = 2;
Board[3, 5] = 2; Board[3, 6] = 1; Board[3, 7] = 6; Board[3, 8] = 7;
Board[4, 0] = 2; Board[4, 1] = 8; Board[4, 2] = 6; Board[4, 3] = 7;
Board[4, 4] = 1; Board[4, 5] = 5; Board[4, 6] = 4; Board[4, 7] = 3;
Board[4, 8] = 9; Board[5, 0] = 1; Board[5, 1] = 3; Board[5, 2] = 7;
Board[5, 3] = 4; Board[5, 4] = 9; Board[5, 5] = 6; Board[5, 6] = 5;
Board[5, 7] = 8; Board[5, 8] = 2; Board[6, 0] = 6; Board[6, 1] = 9;
Board[6, 2] = 4; Board[6, 3] = 1; Board[6, 4] = 5; Board[6, 5] = 3;
Board[6, 6] = 7; Board[6, 7] = 2; Board[6, 8] = 8; Board[7, 0] = 3;
Board[7, 1] = 2; Board[7, 2] = 5; Board[7, 3] = 8; Board[7, 4] = 7;
Board[7, 5] = 4; Board[7, 6] = 9; Board[7, 7] = 1; Board[7, 8] = 6;
Board[8, 0] = 7; Board[8, 1] = 1; Board[8, 2] = 8; Board[8, 3] = 2;
Board[8, 4] = 6; Board[8, 5] = 5; Board[8, 6] = 7; Board[8, 7] = 5;
Board[8, 8] = 4;
}
public void InputDefaultRightValues(int[,] Board)
{

Board[0,0]=9;Board[0,1]=6;Board[0,2]=1;Board[0,3]=5;
Board[0,4]=4;Board[0,5]=8;Board[0,6]=2;Board[0,7]=7;
Board[0,8]=3;Board[1,0]=8;Board[1,1]=7;Board[1,2]=2;
Board[1,3]=9;Board[1,4]=3;Board[1,5]=1;Board[1,6]=6;
Board[1,7]=4;Board[1,8]=5;Board[2,0]=4;Board[2,1]=5;
Board[2,2]=3;Board[2,3]=6;Board[2,4]=2;Board[2,5]=7;
Board[2,6]=8;Board[2,7]=9;Board[2,8]=1;Board[3,0]=5;
Board[3,1]=4;Board[3,2]=9;Board[3,3]=3;Board[3,4]=8;
Board[3,5]=2;Board[3,6]=1;Board[3,7]=6;Board[3,8]=7;
Board[4,0]=2;Board[4,1]=8;Board[4,2]=6;Board[4,3]=7;
Board[4,4]=1;Board[4,5]=5;Board[4,6]=4;Board[4,7]=3;
Board[4,8]=9;Board[5,0]=1;Board[5,1]=3;Board[5,2]=7;
Board[5,3]=4;Board[5,4]=9;Board[5,5]=6;Board[5,6]=5;
Board[5,7]=8;Board[5,8]=2;Board[6,0]=6;Board[6,1]=9;
Board[6,2]=4;Board[6,3]=1;Board[6,4]=5;Board[6,5]=3;
Board[6,6]=7;Board[6,7]=2;Board[6,8]=8;Board[7,0]=3;
Board[7,1]=2;Board[7,2]=5;Board[7,3]=8;Board[7,4]=7;
Board[7,5]=4;Board[7,6]=9;Board[7,7]=1;Board[7,8]=6;
Board[8,0]=7;Board[8,1]=1;Board[8,2]=8;Board[8,3]=2;
Board[8,4]=6;Board[8,5]=9;Board[8,6]=3;Board[8,7]=5;
Board[8,8]=4;

}

public Status CheckSudokuStatus(int[,] Board)
{
int flag = 0;
for (int rowCheck = 0; rowCheck < 9; rowCheck++)
{
flag = 0;
for (int columnCheck = 0; columnCheck < 9; columnCheck++)
{
if (Board[rowCheck, columnCheck] == 0)
continue;

if ((flag & (1 << Board[rowCheck, columnCheck])) != 0)
return Status.Failure;
flag |= (1 << Board[rowCheck, columnCheck]);
}
}
for (int columnCheck = 0; columnCheck < 9; columnCheck++)
{
flag = 0;
for (int rowCheck = 0; rowCheck < 9; rowCheck++)
{
if (Board[rowCheck, columnCheck] == 0)
continue;
if (((flag & (1 << Board[rowCheck, columnCheck])) != 0))
return Status.Failure;
flag |= (1 << Board[rowCheck, columnCheck]);
}
}
for (int rowCheck = 0; rowCheck < 3; rowCheck++)
{
for (int columnCheck = 0; columnCheck < 3; columnCheck++)
{
BoxCheck(Board, rowCheck* 3, columnCheck * 3);

}
}

return Status.Success;

}
private Status BoxCheck(int[,] Board, int Row, int Coloumn)
{
ArrayList ArrElementsCompare = new ArrayList();
ArrElementsCompare.Clear();
for (int rowIndex = Row; rowIndex < Row + 3; rowIndex++)
{
for (int columnIndex = Coloumn; columnIndex < Coloumn + 3; columnIndex++)
{
if (Board[rowIndex, columnIndex] == 0)
continue;
if (ArrElementsCompare.Contains(Board[rowIndex, columnIndex]))
return Status.Failure;
ArrElementsCompare.Add(Board[rowIndex, columnIndex]);
}
}
return Status.Success;
}

}
}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook

Related Posts:

  • An Example to create an UserControl to create a checklist box and how to set default check in ASP.Net Using C#using System;using System.Collections;using System.ComponentModel;using System.Drawing;using System.Data;using System.Text;using System.Windows.Forms;… Read More
  • C code to Check the string has valid identifier or not in.#include#include#includechar keyword[][10]={"auto","break","case","char","const","continue","default","printf", "double","… Read More
  • Code for matrix problem in C++#includeusing namespace std;#define row 10#define col 10int row1,row2,col1,col2;class matrix{ int a[row][col]; int b[row][col]; int c[row][col… Read More
  • How to Send data from a User Control to another user control on a single form using Events and Delegates:--This is an example how to create Dynamic Check Boxes and how to communicate betwwen two user controls on a sigle form using Events and Delegates.In th… Read More
  • C Aptitude Questions...C Questions Check Your Ability In CNote : All the programs are tested under Turbo C/C++ compilers. It is assumed that, Programs run under DOS envi… Read More
Newer Post Home

0 comments:

Post a Comment

About The Author

Unknown
View my complete profile

Total Pageviews

84952

Popular Posts

  • Clr - Common Language Runtime
    .Net framework provides a run time environment - CLR. Common language runtime takes the IL code from the compiler( language specific) and p...
  • Auto logout chrome extension for Gmail
    Hello Friends, In the last article we learned to create a sample chrome extension. Here we are going to create auto logout Gmail script as...
  • Predicate delegate in C#
    Hello Everyone, In the article we will talk about Predicate delegate. Predicate is also a delegate which encapsulate a method that takes...
  • .Net Framework overview
    Hello friends : Here i am writing my first article on .Net framework anyways....So the question is What is .Net Framework ? The .Net fram...
  • Calling the Delegates using Invoke(), BeginInvoke() and DynamicInvoke() ?
    Hello Guys, So in the last article we talked about What is delegate and how can we create a delegate. In this article we will discuss w...
  • What does it mean by disconnected data access architecture of ADO.Net?
    ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the databa...
  • Nagarro Placement Papers..
    Ques.1 :- Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are...
  • C code to Check the string has valid identifier or not in.
    #include #include #include char keyword[][10]={"auto","break","case","char","const","...
  • Delegates in C Sharp
    A Delegate is a type variable that holds the reference to a method. Delegates are similar to Pointer to functions in C and C++ When we...
  • Garbage Collection - Automatic memory management
    While thinking of this question few things are coming in my mind ~ How .Net reclaims objects and memory used by an application ? So the ans...

Blog Archive

  • ►  2016 (4)
    • ►  September (2)
      • ►  Sep 03 (2)
    • ►  August (1)
      • ►  Aug 28 (1)
    • ►  April (1)
      • ►  Apr 24 (1)
  • ►  2015 (12)
    • ►  September (10)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 27 (2)
      • ►  Sep 26 (3)
      • ►  Sep 20 (1)
      • ►  Sep 19 (1)
    • ►  August (1)
      • ►  Aug 16 (1)
    • ►  March (1)
      • ►  Mar 31 (1)
  • ►  2013 (10)
    • ►  June (1)
      • ►  Jun 16 (1)
    • ►  April (1)
      • ►  Apr 21 (1)
    • ►  February (8)
      • ►  Feb 18 (3)
      • ►  Feb 17 (2)
      • ►  Feb 16 (2)
      • ►  Feb 15 (1)
  • ►  2012 (1)
    • ►  May (1)
      • ►  May 27 (1)
  • ►  2010 (22)
    • ►  October (14)
      • ►  Oct 21 (1)
      • ►  Oct 06 (12)
      • ►  Oct 04 (1)
    • ►  April (2)
      • ►  Apr 22 (1)
      • ►  Apr 16 (1)
    • ►  March (1)
      • ►  Mar 30 (1)
    • ►  January (5)
      • ►  Jan 08 (3)
      • ►  Jan 01 (2)
  • ▼  2009 (110)
    • ►  December (8)
      • ►  Dec 18 (2)
      • ►  Dec 05 (1)
      • ►  Dec 04 (5)
    • ►  November (1)
      • ►  Nov 27 (1)
    • ►  October (14)
      • ►  Oct 09 (4)
      • ►  Oct 07 (1)
      • ►  Oct 06 (3)
      • ►  Oct 05 (3)
      • ►  Oct 01 (3)
    • ►  September (17)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 25 (1)
      • ►  Sep 24 (1)
      • ►  Sep 17 (2)
      • ►  Sep 15 (3)
      • ►  Sep 11 (2)
      • ►  Sep 09 (3)
      • ►  Sep 08 (2)
    • ►  August (31)
      • ►  Aug 31 (1)
      • ►  Aug 27 (3)
      • ►  Aug 26 (1)
      • ►  Aug 25 (2)
      • ►  Aug 24 (1)
      • ►  Aug 22 (2)
      • ►  Aug 21 (3)
      • ►  Aug 20 (2)
      • ►  Aug 19 (3)
      • ►  Aug 18 (1)
      • ►  Aug 16 (1)
      • ►  Aug 12 (2)
      • ►  Aug 11 (1)
      • ►  Aug 10 (3)
      • ►  Aug 07 (4)
      • ►  Aug 06 (1)
    • ►  July (24)
      • ►  Jul 25 (4)
      • ►  Jul 24 (20)
    • ▼  April (15)
      • ►  Apr 10 (3)
      • ►  Apr 07 (9)
      • ▼  Apr 06 (3)
        • How to: Read Image Metadata
        • How to store a record in xml file from a windows f...
        • Sudoku-Checker in ASP.Net using C#

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments
copyright @ TechGiant 2015. Powered by Blogger.

Disclaimer

This is my personal blog and i write articles on .Net, WPF, C#, OOPS, Threading and other .Net technologies. This is not related to any of my employer and organizations. This is the result of my personal interest.

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Followers

Copyright © 2025 A Developer Journey who codes for fun | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com