-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_print_solution.c
More file actions
83 lines (75 loc) · 2.13 KB
/
ft_print_solution.c
File metadata and controls
83 lines (75 loc) · 2.13 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_solution.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: schakor <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/24 10:06:20 by schakor #+# #+# */
/* Updated: 2018/04/08 17:50:22 by khsadira ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static void ft_map_init(char **alphabet_map, int square)
{
int i;
if (!(*alphabet_map = (char*)malloc(sizeof(**alphabet_map) * (square *
square + square))))
{
ft_putendl_fd("error", 1);
exit(1);
}
i = 0;
while (i < square * square + square)
(*alphabet_map)[i++] = '.';
i = square;
while (i < square * square + square)
{
(*alphabet_map)[i] = '\n';
i += square + 1;
}
}
static void ft_putfmap(char **map)
{
ft_putstr(*map);
free(*map);
}
static int ft_calc_pos(int ind, int pos[26], int sqr, int i)
{
return (pos[ind] / 16 + (pos[ind] % 16)
+ (pos[ind] / 16 * sqr) + ((i * sqr) + i));
}
/*
** Tab[0] = index tetra
** Tab[1] = position tetra;
** Tab[2] = decalage binaire
** Tab[3] = variable a realiser 4 fois
** Tab[4] =
*/
void ft_characterize_map(int nb_tetra, int pos[26],
t_uint16 *tetra, int sqr)
{
int place;
int ind[4];
char *alphabet_map;
ft_map_init(&alphabet_map, sqr);
ind[0] = -1;
while (ind[0]++ < nb_tetra)
{
ind[1] = 15;
ind[3] = 0;
while (ind[1] >= 0)
{
place = ft_calc_pos(ind[0], pos, sqr, ind[3]);
ind[2] = 0;
while (ind[2]++ < 4)
{
if ((tetra[ind[0]] >> ind[1]-- & 1))
alphabet_map[place] = 'A' + ind[0];
place++;
}
ind[3]++;
}
}
ft_putfmap(&alphabet_map);
}