Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:13:44+00:00 2026-06-15T18:13:44+00:00

I am coding a Sudoku puzzle generator but all i see is a blank

  • 0

I am coding a Sudoku puzzle generator but all i see is a blank console terminal when i compile and run the program. I have been waiting for 1 hr but its still a blank console terminal. I am wondering if its because of any logical error OR because it is still processing. Just a heads up, my entire code is super long. How do i optimize it if its a performance issue

Thanks

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cmath>

using namespace std;
bool checkrow(int row,int value,int array[][9]);

void producearray(int array[][9]);

bool checksquare(int row,int col,int value,int array[][9]);
bool checkcol(int col,int value,int array[][9]);
void populatearray(int array[][9]);

void printarray(int array[][9]);


int main()
{
int array[9][9];
populatearray( array);
producearray(array);
printarray(array);


system("PAUSE");





}

bool checkrow(int row,int value,int array[][9])// checks the entire row, returns false if any two numbers in the row are the same
{
for (int j=0;j<9;j++)
{
    if (value==array[row][j])
    {
        return false;


    }


}

return true;



}

bool checkcol(int col,int value,int array[][9]) // check if any two numbers in the same column are the same
{
for (int j=0;j<9;j++)
{
    if (value==array[j][col])
    {
        return false;


    }


}

return true;

}

bool checksquare(int row,int col,int value,int array[][9]) //checks if the number within the same square are the same
{
if  ( ( row>=0 &&  row<=2) && (col>=0 && col<=2) )
{
    for (int i=0;i<=2;i++)
    {
        for (int j=0;j<=2;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;


}

 else if  ( ( row>=0 &&  row<=2) && (col>=3 && col<=5) )
{
    for (int i=0;i<=2;i++)
    {
        for (int j=3;j<=5;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}

else if  ( ( row>=0 &&  row<=2) && (col>=6 && col<=8) )
{
    for (int i=0;i<=2;i++)
    {
        for (int j=6;j<=8;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}


 else if  ( ( row>=3 &&  row<=5) && (col>=0 && col<=2) )
{
    for (int i=3;i<=5;i++)
    {
        for (int j=0;j<=2;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}

else if  ( ( row>=3 &&  row<=5) && (col>=3 && col<=5) )
{
    for (int i=3;i<=5;i++)
    {
        for (int j=3;j<=5;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}

 else if  ( ( row>=3 &&  row<=5) && (col>=6 && col<=8) )
{
    for (int i=3;i<=5;i++)
    {
        for (int j=6;j<=8;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}

else if  ( ( row>=6 &&  row<=8) && (col>=0 && col<=2) )
{
    for (int i=6;i<=8;i++)
    {
        for (int j=0;j<=2;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;



}

 else if  ( ( row>=6 &&  row<=8) && (col>=3 && col<=5) )
{
    for (int i=6;i<=8;i++)
    {
        for (int j=3;j<=5;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;
}

 else if  ( ( row>=6 &&  row<=8) && (col>=6 && col<=8) )
{
    for (int i=6;i<=8;i++)
    {
        for (int j=6;j<=8;j++)
        {
            if (array[i][j]== value)
            {
                return false;

            }

        }


    }

    return true;
}






}

void producearray(int array[9][9]) //produces the array
{
bool isrow;
bool iscol;
bool issquare;

for (int i=0;i<9;i++)
{
    for (int j=0;j<9;j++)
    {
        do
        {
        array[i][j]=rand()%9+1;
         isrow=checkrow(i,array[i][j],array);
         iscol=checkcol(j,array[i][j],array);
         issquare=checksquare(i,j,array[i][j],array);




        }
           while(isrow==false || iscol==false || issquare==false);

    }



}

}

void populatearray(int array[][9]) // populate the arary
{
for (int i=0;i<9;i++)
{

    for (int j=0;j<9;j++)
    {
        array[i][j]=0;


    }


}




}

void printarray(int array[][9]) //prints the array
{
for (int i=0;i<9;i++)
{

    for (int j=0;j<9;j++)
    {
        cout<<array[i][j]
            <<"\t";


    }
    cout<<endl;


}



}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:13:45+00:00Added an answer on June 15, 2026 at 6:13 pm

    You are doing it wrong. Your code tries to generate a valid sudoku by randomizing every single field, one by one, checking if there is a collision. This most likely leads to the problem that when a part of the sudoku is already filled, there is no valid solution anymore. Such a deadlock happens all the time. The exising numbers do not conflict, but there is no way to fill the rest. Just take any sudoku from a newspaper and randomly fill a few fields so that they do not immediately conflict. Most likely, you won’t be able to complete the sudoku any more.

    This problem is what makes a sudoku a puzzle, and your program ignores it – so it must fail (unless the random generator is really, really, really lucky today).

    A much better way to generate a sudoku is to start with a known valid sudoku, than swap rows and columns (always within a 3 line/column block), and whole blocks of three lines / columns, and swap numbers (e.g. replace every 3 with 7 and concurrently every 7 with 3) so that every swap keeps the whole sudoku valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After coding and testing a Java application (lets say with Eclipse, but not necessarily)
Coding Platform: ASP.NET WebForms4.0 VB Installed Facebook and FacebookWeb and when I run the
Coding Language: C# Framework: .NET We have built a software, which among many other
When coding up Ajax calls in ASP.Net MVC we have a lot of options
Hi all i need to update a containers data for a sudoku game i
Coding a new 3D engine is fascinating but I there are so many out
Coding PHP on a Mac using TextEdit. It's always annoying to have to type
Coding in UNIX make , I have written: cat $ sString | grep sSubstring
I have a sudoku grid with 81 cells(asp:textboxes) which I've labeled: _c11.._c12.._c13.._c99 I'm trying
I created a table for immediate interaction (for a Sudoku solver), but the mouse

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.