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 4005948
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:27:21+00:00 2026-05-20T08:27:21+00:00

I decided to write a logic solving algorithm for my Sudoku application. What I

  • 0

I decided to write a logic solving algorithm for my Sudoku application. What I wrote works for a limited amount of grid values, but then the recursion stops way too soon.

What my methods do:
addToThirdDimension(): A three dimensional array stores any possible values that can be put into the grid value at logicGrid[x][y]. This method refreshes the three dimensional array. It does this by testing values 1-9 in every grid index, and if it’s valid, it adds that number to the array. If not, it sets that value to zero.

checkValues(): Checks how many possibilities are left in the three dimensional grid. It goes through the logicGrid and returns the number of non-zero values are in the grid.

checkSingleValue(int row, int col): Checks logicGrid[row][col] to see if there is one and only one value left in there (If there is one value left, it is the only possibility for the grid element at [row, col]). It returns the amount of non-zero values that are in that grid location.

getSingleValue(int row, int col): Returns the single number that’s left in logicGrid[row][col]

immutableValues: A two dimensional boolean array that stores whether or not a specific grid element is immutable or not. If it is immutable, the solve method should not touch it.

public boolean solveWithLogic(){

    addToThirdDimension();
    if(checkValues() == 0){
        return true;
    }

    for(int row = 0; row < 9; row++){
        for(int col = 0; col < 9; col++){
            if(!immutableValues[row][col]){
                if(checkSingleValue(row, col) == 1){
                    sGrid[row][col] = getSingleValue(row, col);
                    setValues[row][col] = true;
                    addToThirdDimension();
                }
            }
        }
    }

    if(checkValues() != 0){
        solveWithLogic();
    } else{
        return true;
    }

    return false;
}

I cannot see where I am going wrong. After a certain number of tries, checkValues returns 0 even though there should be more possibilities. Here is the code for addToThirdDimension() as I am sure that if something is wrong, it is here.

sGrid is the main two-dimensional integer array that stores the values for the puzzle.

public void addToThirdDimension(){

    logicGrid = new int[9][9][9];

    for(int x = 0; x < 9; x++){
        for(int y = 0; y < 9; y++){
            for(int z = 0; z < 9; z++){
                logicGrid[x][y][z] = z + 1;
            }
        }
    }

    int[][] temp1 = sGrid;

    for(int row = 0; row < 9; row++){
        for(int col = 0; col < 9; col++){
            if(setValues[row][col]){
                for(int i = 0; i < 9; i++){
                    logicGrid[row][col][i] = 0;
                }
            } else{
                for(int i = 1; i <= 9; i++){
                    temp1[row][col] = i;
                    if(!isColumnValid(col, temp1) && !isRowValid(row, temp1) &&
                            !isQuadrantValid(row, col, temp1){
                        logicGrid[row][col][i-1] = 0;
                    }
                }
            }
            temp1[row][col] = sGrid[row][col];
        }
    }
}

The code isn’t too efficient at the moment. I want to get it working before I start minimizing solve times.

  • 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-05-20T08:27:21+00:00Added an answer on May 20, 2026 at 8:27 am

    The first thing I would do is create a SudukoCell object that stores your possible values in it. Then create a SudukoBoard with a 2d array of SudukoCells. Also give it an array of SudukoAreas. One area for rows, one area for cols, and one area for blocks.

    Add your suduko cells appropriately.

    This will help you consolidate your legwork and prevent silly mistakes.

    then every time you solve a number, you can go to the cells in each of its areas and remove the number you solved from them.

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

Sidebar

Related Questions

The other day I decided to write an implementation of radix sort in Java.
I've been working through Practical Common Lisp and as an exercise decided to write
We decided to use the minimumRequiredVersion in our clickOnce application manifest, and now when
Inspired by this topic , I decided to write a simple program that does
Greetings, everyone. I'm trying to learn some Silverlight basics, and have decided to write
So at work yesterday, I had to write an application to count the pages
What criteria should I use to decide whether I write VBA code like this:
I decided to make a system for a client using Castle ActiveRecord , everything
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
I decided to install APC to speed up the site that I work for.

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.