-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_is_valid.c
41 lines (38 loc) · 1.51 KB
/
ft_is_valid.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
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_valid.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ssnelgro <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/21 11:04:55 by ssnelgro #+# #+# */
/* Updated: 2018/01/21 18:16:29 by frodrigu ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_sudoku.h"
int ft_is_valid(char number, char **puzzle, int row, int col)
{
int i;
int sqrrow;
int sqrcol;
i = 0;
sqrrow = 3 * (row / 3);
sqrcol = 3 * (col / 3);
while (i < 9)
{
if (puzzle[i][col] == number)
return (0);
if (puzzle[row][i] == number)
return (0);
i++;
}
if (puzzle[(row + 2) % 3 + sqrrow][(col + 2) % 3 + sqrcol] == number)
return (0);
if (puzzle[(row + 2) % 3 + sqrrow][(col + 4) % 3 + sqrcol] == number)
return (0);
if (puzzle[(row + 4) % 3 + sqrrow][(col + 2) % 3 + sqrcol] == number)
return (0);
if (puzzle[(row + 4) % 3 + sqrrow][(col + 4) % 3 + sqrcol] == number)
return (0);
return (1);
}