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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:25:21+00:00 2026-05-17T22:25:21+00:00

What would be a smart data structure to use to represent a Sudoku puzzle?

  • 0

What would be a smart data structure to use to represent a Sudoku puzzle? I.e. a 9X9 square where each “cell” contains either a number or a blank.

Special considerations include:

  • Ability to compare across row, column, and in 3X3 “group
  • Ease of implementation (specifically in Python)
  • Efficiency (not paramount)

I suppose in a pinch, a 2D array might work but that seems to be a less than elegant solution. I just would like to know if there’s a better data structure.

  • 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-17T22:25:21+00:00Added an answer on May 17, 2026 at 10:25 pm

    Actually, I built such a beast, both a solver and a generator, and I used a 2D array. It worked fine.

    You just had to understand the indexes and where they were and that wasn’t too difficult to master.

    The relative relationships between cells in a row doesn’t change depending on the column, same goes for cells in a column, or even cells in a mini-square.

    Sometimes, a less “elegant” solution is just fine. Indeed, sometimes, it’s preferable 🙂


    For what it’s worth, you may be interested in the algorithms that I used for the solver/generator.

    First I wrote the solver part which would first set all cells as being able to be any value then apply all the rules in sequence to see if a individual cell could be solved or otherwise limited, things like:

    • if the cell was a specific value in the clues, set it to that value.
    • if there’s only one cell left in a row (or column or mini-square), you can set it to the remaining value.
    • if a cell is marked as being possibly N and N exists in its row/column/mini-square elsewhere, remove that possibility.
    • if there are two cells in the row/column/mini-square and they have the same two possibilities (and no other possibilities), all other cells in that row/column/mini-square should have that possibility removed.

    And so on, adding each rule that I use in solving the real puzzles.

    For the generator, I started with:

    123 456 789
    456 789 123
    789 123 456
    
    234 567 891
    567 891 234
    891 234 567
    
    345 678 912
    678 912 345
    912 345 678
    

    and then, in a loop of varying size (at least 500), proceeded to swap rows and columns in such a way that it would never produce an invalid puzzle. In other words, swap rows or columns with the group they’re in (for example, rows 1, 2 and 3 are a group, so are columns 4, 5 and 6).

    This shuffled up the cells well enough to produce a decent puzzle.

    Then, I started choosing random cells and setting them as unknown. Once a cell was set as unknown, I would pass the whole puzzle into the solver. If it was solvable, I would continue, otherwise I would re-instate the cell and carry on.

    This prevented me getting a puzzle that was logically unsolvable.

    Once a large number of random cell removals had been done, I would try to remove all the remaining cells in order using the same method. What was left then was the minimum amount of information required to solve the puzzle.

    And, so it wasn’t a pain to Sudoku beginners, I would allow them to specify a lower difficulty level which would put a certain number of the unnecessary cells back in.

    Not a bad scheme, there may be better ones but that one worked fine for me.

    Now, if I could only figure out this Kakuro stuff, I could die happy 🙂

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

Sidebar

Related Questions

I am looking for suggestions on what kind of data-structure to use for extremely
I thought I would be smart and create member functions that accepted output iterators.
I was wondering if using Lightbox all over the site would be a smart
a data structure to store the start and endpoint of a range. rangename start
Does anyone know of an algorithm or data structure relating to selecting items, with
Table structure - Data present for 5 min. slots - data_point | point_date 12
I have a data structure which represents a train, which can be made up
I am presented with a situation where I would like to use Html.ValidationSummary() in
In the context of design of a social network using Graphs data structure ,
I'm trying to decide which method would be best for an internal linking structure

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.