-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.c
79 lines (71 loc) · 2.81 KB
/
test_main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <unistd.h>
#include <stdlib.h>
void ft_putchar(char c);
void print_board(int *board, int N);
int get_cell_value(int *possible_values, int x, int y, int N);
int main(void)
{
/*int board[10][4][4] = {{{1, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 1, 0, 0}},
{{0, 2, 0, 0}, {2, 0, 0, 0}, {0, 0, 0, 2}, {0, 0, 2, 0}},
{{0, 0, 3, 0}, {0, 3, 0, 0}, {3, 0, 0, 0}, {0, 0, 0, 3}},
{{0, 0, 0, 4}, {0, 0, 4, 0}, {0, 4, 0, 0}, {4, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},
{{1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}, {1, 1, 1, 1}}};
*/
int N;
N = 4;
//int *board = (int *)malloc(N*N*10*(sizeof(int)));
int board[] = {1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0,
0, 0, 3, 0, 0, 3, 0, 0, 3, 0, 0, 0, 0, 0, 0, 3,
0, 0, 0, 4, 0, 0, 4, 0, 0, 4, 0, 0, 4, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
print_board(board, N);
return (0);
}
void print_board(int *board, int N)
{
int x;
int y;
y = 0;
while(y < N) // goes through every row
{
x = 0;
ft_putchar(get_cell_value(board, x, y, N) + '0'); //Prints the first digit of the row
x++;
while (x < N)
{
ft_putchar(' ');
ft_putchar(get_cell_value(board, x, y, N) + '0');
x++;
}
ft_putchar('\n');
y++;
}
}
int get_cell_value(int *possible_values, int x, int y, int N)
{
int i;
i = 0;
if (possible_values[N * y + x]!= 0) //because at the 0th layer z == 0
return (1);
if (possible_values[N * N * (9) + N * y + x] == 1) {
while (possible_values[N * N * i + N * y + x] == 0)
i++;
return (possible_values[N * N * (i) + N * y + x]);
}
return (0);
}
void ft_putchar(char c)
{
write(1, &c, sizeof(c));
}