Joining multiple data types?

Feb 14, 2012 at 4:31am
Hi everyone. I'm working on a project - a "sudoku solver." I'm not very well-trained, never taken a C++ class or anything, but have been slowly picking things up on my own. Although I'm starting to learn more and more elements of C++, I'm most familiar with the basics, recursion, arrays and vectors. (Lists, heaps, piles, deques, etc confuse me, along with the whole object-oriented class system. I'll get there soon hopefully).

My approach:

Create a nine by nine array, and link each specific position to a "list" or set of the digits 1-9. Visually, I'm seeing a 2D game-board, with a "stack" of possible numbers on each space. I figured if I can set this up, some type of brute force would lead to answer.

The question:

Is there a way to link the 81 positions on the board to a list or vector sequence of digits? I know I could declare 81 variables by hand, and have them store the possible digits, and go from there... but I feel like there has to be a more sophisticated way.

Is there a way to have an array thats joined to a list? Like
"array[position][position]*[list of 9 numbers]*"?

Any help or thoughts are appreciated. Thank you.
Feb 14, 2012 at 5:12am
There certainly is. Make an array of lists or make an array of vectors or make an array of arrays..

I'm not certain this is a good approach though. One 'cell' of a Sudoku puzzle has either one number in it or none. Making use of an array of int (either 1 or 2d) you could use the value at each particular position to store whether a position currently has a number (0 = no number?) and what that number is.
Feb 14, 2012 at 12:52pm
Thank you! I did not know the array class could be co-opted like that. I've only used it for integers and strings / characters so far.

You're probably right - I'll give it a try. (First, I'll figure out how these array of lists work). I appreciate the help!
Topic archived. No new replies allowed.