Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int puzzle[9][9] = {
- 4,5,2, 0,9,1, 8,7,6, //0,0 -> 0,8
- 3,1,8, 6,0,5, 2,9,4,
- 6,7,0, 4,2,8, 3,1,5,
- 8,3,1, 0,0,0, 7,2,9,
- 2,4,5, 0,0,0, 1,6,3,
- 9,6,7, 0,0,0, 5,4,8,
- 7,9,6, 8,5,2, 4,3,1,
- 1,8,3, 7,4,9, 6,5,2,
- 5,2,4, 1,3,6, 9,8,7
- };
- int copypuzzle[9][9];
- //returns true if the number is found
- bool checksquare(int startx, int starty, int number)
- {
- for(int x = startx; x < startx + 3; x++)
- for(int y = starty; y < starty + 3; y++)
- if(puzzle[x][y] == number)
- return true;
- return false;
- }
- bool checkrow(int row, int number)
- {
- for(int x = 0; x < 9; x++)
- if(puzzle[row][x] == number)
- return true;
- return false;
- }
- bool checkcolumn(int column, int number)
- {
- for(int x = 0; x < 9; x++)
- if(puzzle[x][column] == number)
- return true;
- return false;
- }
- //returns true if the number can be placed
- int checkspot(int x, int y, int number)
- {
- if((checksquare(x-(x%3), y-(y%3), number) || checkrow(x, number) || checkcolumn(y, number)) && puzzle[x][y] != number)
- return false;
- return true;
- }
- int main()
- {
- cout << checkspot(0,3,3) << " " << true <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement