-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.c
40 lines (37 loc) · 1.5 KB
/
solution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* solution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cosney <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/24 04:21:15 by cosney #+# #+# */
/* Updated: 2020/04/24 23:15:38 by cosney ### ########.fr */
/* */
/* ************************************************************************** */
int *empty_spots(char board[][9], int *pos, char var, int k);
int check_position(char board[][9], int *pos, char var, int k);
int solution(char board[][9], char x, int k)
{
int pos[2];
empty_spots(board, pos, x, k);
if (pos[0] == -1)
x = x - 1;
if (pos[0] == -1 && x == '0')
return (0);
empty_spots(board, pos, x, k);
while (pos[1] < (k + 1))
{
if (check_position(board, pos, x, k) == 0)
{
board[pos[0]][pos[1]] = x;
if (!solution(board, x, k))
return (0);
board[pos[0]][pos[1]] = '0';
pos[1] = pos[1] + 1;
}
else
pos[1] = pos[1] + 1;
}
return (1);
}