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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:42:49+00:00 2026-05-26T04:42:49+00:00

I am attempting to solve Sudoku as a constraint satisfaction problem for a homework

  • 0

I am attempting to solve Sudoku as a constraint satisfaction problem for a homework assignment. I have already constructed constraints for all the elements in a particular row being distinct, as well as for columns. I am trying to construct the constraints for the elements in a sub-region being distinct, and I’m running into some trouble.

The general idea behind my current algorithm is to add all of the variables that are in a sub-region (e.g. a 3×3 box for a 9×9 grid) into a list, and then permute all the values in that list to construct NotEqualConstraints between each variable. The code below works properly for the 1st subregion of a NxN grid, but I am not sure how I should change this to iterate through the rest of the entire grid.

int incSize = (int)Math.sqrt(svars.length);

ArrayList<Variable> subBox = new ArrayList<Variable>();

for (int ind = 0; ind < incSize; ind++) {
for (int ind2 = 0; ind2 < incSize; ind2++) {
    subBox.add(svars[ind][ind2]);
    }
}

for (int i = 0; i < subBox.size(); i++) {
for (int j = i + 1; j < subBox.size(); j++) {
   NotEqualConstraint row = new NotEqualConstraint(subBox.get(i), subBox.get(j));
   constraints.add(row);
   }
}

Can anyone guide me in the right direction about how I can modify the code to hit each subregion and not just the top left one?

edit: I am also open to trying any algorithm that works, it is not necessary to add all of the values to an ArrayList for each sub-region. If you see a better way, please share insight

  • 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-26T04:42:49+00:00Added an answer on May 26, 2026 at 4:42 am

    Here is the working solution I came up with, for those interested:

    for (int ofs = 0; ofs < svars.length; ofs++) {
        int col = (ofs % incSize) * incSize;
        int row = ((int)(ofs / incSize)) * incSize;
    
        ArrayList<Variable> subBox = new ArrayList<Variable>();
        for (int ind = row; ind < row+incSize; ind++) {
            for (int ind2 = col; ind2 < col+incSize; ind2++) {
                subBox.add(svars[ind][ind2]);
            }
        }
        for (int i = 0; i < subBox.size(); i++) {
                for (int j = i + 1; j < subBox.size(); j++) {
                   NotEqualConstraint c = new NotEqualConstraint(subBox.get(i), subBox.get(j));
                   constraints.add(c);
                }
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have sort of a tricky problem I'm attempting to solve. First of all,
Here is the problem I am attempting to solve. I have 3 database tables
I'm attempting to solve the Project Euler Problem 8 with C++, and the problem
I'm attempting to solve the Code Golf: Build Me an Arc problem. My solution's
I am attempting to make an algorithm to solve Project Euler Problem 255 I
I am attempting to use tortoiseSVN to solve a small problem which I am
I'm attempting to solve what I thought would be a very simple problem. I
I'm attempting to solve the producer-consumer problem using pthreads and semaphores, but it looks
I am attempting to solve a problem from topcoder.com and it's driving me crazy.
I have a complicated solution I am attempting to solve. I have a wcf

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.