-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_2.c
88 lines (78 loc) · 2.12 KB
/
main_2.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
80
81
82
83
84
85
86
87
88
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pnoutere <pnoutere@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/31 12:37:29 by pietari #+# #+# */
/* Updated: 2022/02/04 17:10:35 by pnoutere ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void solve_tetrimino(unsigned short *tetriminos)
{
unsigned short count;
unsigned short min_sqr;
count = 0;
while (tetriminos[count])
count++;
min_sqr = sqroot(count);
solver_main(tetriminos, min_sqr, count);
}
unsigned short counter(char **array, int i, int j)
{
unsigned short count;
count = 0;
if (i + 1 <= 3 && array[i + 1][j] == '#')
count++;
if (i - 1 >= 0 && array[i - 1][j] == '#')
count++;
if (j + 1 <= 3 && array[i][j + 1] == '#')
count++;
if (j - 1 >= 0 && array[i][j - 1] == '#')
count++;
return (count);
}
void up_most_left_most(int i, int j, int *leftmost, int *upmost)
{
if (j < *leftmost)
*leftmost = j;
if (i < *upmost)
*upmost = i;
}
unsigned short check_around_loop(char **array, int *find,
int *leftmost, int *upmost)
{
int i;
int j;
unsigned short count;
i = 0;
j = 0;
count = 0;
while (array[i])
{
j = 0;
while (array[i][j])
{
if (array[i][j] == '#')
{
up_most_left_most(i, j, leftmost, upmost);
count += counter(array, i, j);
*find = *find + 1;
}
j++;
}
i++;
}
return (count);
}
unsigned short sqroot(unsigned short count)
{
unsigned short sqroot;
count = count * 4;
sqroot = 1;
while (sqroot * sqroot < count)
sqroot++;
return (sqroot);
}