how do I make possibilities true or false?

So, I know that number values are all true except 0, that's what keeps coming up when I try to find answers elsewhere. I'm making a sudoku program, and I'm making a function to show the possibilities of a certain square based on the others in the row, column, and box. I'm trying to make it set all values 1-9 to true first, and then if a number shows up in the row, column, or box, switch that value to false. I cannot for the life of me figure out how to do that though. I know it should be something very simple, but I just can't figure it out! I think if I could get help knowing how to set them all equal to true, I could go from there. Do I need a boolean variable? an array? I tried making a boolean array, but I guess that's not allowed...? HELP!

I suggest you, dealing with empty squares as 0 (==false). If any number is setten to your square, it would not be any more 0, so it's considered as 'true'. So if some square is still 'false', it could be considered as empty. So I suggest you, setting all the values to 0 first.
Btw, boolean arrays are allowed.
I tried making a boolean array, but I guess that's not allowed...?

Why would you guess that? Why would there be something magical about the bool type that would mean you couldn't make an array of that type?

It sounds to me like you want each cell of your Sudoko grid to have two properties:

- the number it's supposed to be
- a flag for whether or not that number is actually to be displayed

Yes?
A Sudoku puzzle is a 9 x 9 grid, 81 values in total. Each grid element can hold either a positive integer number or is blank.

Now that we have some idea of the requirements actually figuring out how to start writing code is easier.

The puzzle grid can be either a 2 dimensional container (int puzzle[9][9] { }; all the elements are set to zero using uniform initialization.)

Or a 1 dimensional array based on the 2 dimensions (int puzzle[9 * 9] { };)

Personally I would use a 2D container*.

Since part of creating the puzzle container is setting all the elements to zero, that can be used to internally represent a blank element. When displaying the puzzle grid, loop through the array's elements and any that are zero output space(s).

You've got your Sudoku grid, now you add the code to layout the numbers in the puzzle.

No need for Boolean logic. :)

I'd opt for a std::vector or std::array over a regular array. 2D or 1D simulated 2D
Okay, I guess I didn't explain this very well.
I'm not trying to write the sudoku, I'm just trying to solve one that I get from a file.
I already had to figure out how to get it from the file, and then I needed to be able to edit it so the user can solve the sudoku. I already did that, and it works fine. Now I'm trying to make it so I can enter coordinates of an individual square, and it will display what numbers are possible to be put in that square to help the user.
Ah, OK.

So, for each element of the grid, you want a container of values that can still be possible in that cell - possibly, a std::set.

In the initial state of a totally empty grid, each cell has a full set of 10 numbers in the vector. As cells are filled in, and possibilities are removed, you could remove those numbers from the set for that cell, so that the set contains fewer and fewer possible values.

Once the set is reduced to a single value, you know the answer for that cell.
okay, upon your suggestion, I revisited the idea of a boolean array... and maybe it will work, I was just doing it wrong before. I have no idea what std::set is, so I probably can't use that here.
take a chance to learn something new. set would do it, add 1-9 to a set, and remove them as they become invalid choices. Seems like overkill to me, but why not try it?

an integer is sufficient, you can set and clear the bits. that is the C way. From there you have literally hundreds of options --- any container, string/set/bitset/vector/array/list/etc can all be used here to store the flags.
Topic archived. No new replies allowed.