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

  • SEARCH
  • Home
  • 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 7800385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:37:07+00:00 2026-06-02T00:37:07+00:00

I am in the process of writing a sudoku solver (still need to write

  • 0

I am in the process of writing a sudoku solver (still need to write the box check and actually complete the program) but I’m testing it as I know. The puzzle I’m testing right now is “very easy” as in there is only one empty cell in any row/column. THe puzzle starts with “empty” cells as zeros. My issues is that when I run the program and print out the puzzle after solve() is called, the zeros aren’t changing and the original puzzle is just printed out. Not sure what my issue is, would appreciate some direction!

public ArrayList<Integer> create(){

    ArrayList<Integer> possible = new ArrayList<Integer>(); 

    for(int i=1; i<10; i++){
        possible.add(i);
    }
    return possible;
}
public sudoku( int size )
{
    SIZE = size;
    N = size*size;

    Grid = new int[N][N];
    for( int i = 0; i < N; i++ ) 
        for( int j = 0; j < N; j++ ) 
            Grid[i][j] = 0;
}

public void solve()
{ 
    int a, b, c, d, i, j, k, l; 

    int count = 0;
    int value= 0;

    for(i=0; i<N;i++){
        for(j=0; j<N;j++){  
            if(Grid[i][j]==0){

                ArrayList<Integer> possible = create();

                //check row             
                for(a=0; a<N;a++){
                    for(b=0; b<N; b++){  
                        if(Grid[a][0]==possible.get(a)){
                            possible.set(a, 0);
                        }
                    }
                }
                //check column
                for(c=0; c<N;c++){
                    for(d=0; d<N;d++){  
                        if(Grid[0][d]==possible.get(d)){
                            possible.set(d,0);
                        }
                    }
                }
                for(k=0; k<9; k++){
                    if(possible.get(k)!=0){
                        count++;
                    }
                }
                if(count==1){
                    for(l=0; l<9; l++){
                        if(possible.get(l)!=0){
                            value=possible.get(l);
                        }
                    }
                }
                Grid[i][j]=value;
            }
        }
    }
}
  • 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-02T00:37:08+00:00Added an answer on June 2, 2026 at 12:37 am

    Look at your line if(Grid[a][0]==possible.get(a)) (and similar spots). What is it doing there vs what do you actually want?

    Your possible array looks something like this:
    [1,2,3,4,5,6,7,8,9]

    and your grid (just the first row, since you’re only checking Grid[a][0]) might look something like this:
    [3,7,8,1,2,9,5,0,4]

    Your loop is looking at each element stepwise individually and seeing if they’re equal, like this:

    if(1 == 3) ... it's not
    if(2 == 7) ... it's not
    if(3 == 8) ... it's not
    

    … etc

    So, as you can see, when you do your

    for(k=0; k<9; k++){
        if(possible.get(k)!=0){
            count++;
        }
    }
    

    Your possible array is still going to be full of options most of the time, unless your first row happens to be some variation on [1,2,3,4,5,6,7,8,9] with a 0 in one of the spaces… so count is definitely going to be > 1

    So, your next loop (for(l=0; l<9; l++)) next gets executed, so value is still (as you initialized it) 0.

    Try stepping through a debugger on these points and seeing how the arrays are interacting.

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

Sidebar

Related Questions

I'm currently writing a graphical sudoku solver program in Java using Swing/Awt. So I
(In the process of writing my original question, I answered it, but the information
I'm in the process of writing a program in C++ which needs to compile
I am in the process of writing a testing script that will simply run
I'm in the process of writing a program that requires a long list of
I'm in the process of writing an assembly program that takes two strings as
Let's say you had an external process writing files to some directory, and you
Im in the process of writing a python script to act as a glue
I'm in the process of writing an application to suggest circular routes over OpenStreetMap
I'm in the process of writing a small text-editor that is supposed to have

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.