some new changes
This commit is contained in:
parent
f4bd6e02fa
commit
60119d12bb
10 changed files with 84 additions and 106 deletions
4
Makefile
4
Makefile
|
@ -17,6 +17,7 @@ SRCDIR = ./src/
|
||||||
OBJDIR = ./obj/
|
OBJDIR = ./obj/
|
||||||
|
|
||||||
SRC_FILES = main.c \
|
SRC_FILES = main.c \
|
||||||
|
fillit.c \
|
||||||
glue_figure.c \
|
glue_figure.c \
|
||||||
move_up_left.c \
|
move_up_left.c \
|
||||||
read_file.c \
|
read_file.c \
|
||||||
|
@ -24,6 +25,7 @@ SRC_FILES = main.c \
|
||||||
to_letters.c \
|
to_letters.c \
|
||||||
dancing_links.c \
|
dancing_links.c \
|
||||||
get_types.c \
|
get_types.c \
|
||||||
|
get_amount.c \
|
||||||
test!_check.c \
|
test!_check.c \
|
||||||
test!_print_one_string.c \
|
test!_print_one_string.c \
|
||||||
test!_print_table.c \
|
test!_print_table.c \
|
||||||
|
@ -35,7 +37,7 @@ SRC = $(addprefix $(SRCDIR), $(SRC_FILES))
|
||||||
|
|
||||||
OBJ = $(addprefix $(OBJDIR), $(OBJ_FILES))
|
OBJ = $(addprefix $(OBJDIR), $(OBJ_FILES))
|
||||||
|
|
||||||
INC = -I ./inc
|
INC = -I ./inc -I $(LIBFOLDER)
|
||||||
|
|
||||||
LIB = libft.a
|
LIB = libft.a
|
||||||
|
|
||||||
|
|
24
inc/fillit.h
24
inc/fillit.h
|
@ -78,9 +78,27 @@ void to_letters(char **ttr);
|
||||||
// create array of ttr structures
|
// create array of ttr structures
|
||||||
int *to_strct_array(char **ttr, t_ttrmn *templates);
|
int *to_strct_array(char **ttr, t_ttrmn *templates);
|
||||||
|
|
||||||
|
t_node *init_root(void);
|
||||||
|
|
||||||
t_node *add_column(t_node *root);
|
t_node *add_column(t_node *root);
|
||||||
|
|
||||||
t_node *add_node(t_node *col, t_coord row);
|
t_node **add_cols(t_node *root, int number);
|
||||||
|
|
||||||
|
t_node *add_node(t_node *col);
|
||||||
|
|
||||||
|
t_node *add_node_with_coords(t_node *col, t_coord row);
|
||||||
|
|
||||||
|
t_node **add_cols(t_node *root, int number);
|
||||||
|
|
||||||
|
void print_solution(t_list *sol);
|
||||||
|
|
||||||
|
void add_rows(int *types, int amount, int size, t_node **cols_arr);
|
||||||
|
|
||||||
|
void link_row(int *col_nums, t_node **cols_arr);
|
||||||
|
|
||||||
|
void add_row(int *col_numbers, t_node **cols_arr, t_coord coord);
|
||||||
|
|
||||||
|
void search(t_node* root, t_list *solution, int k, int amount);
|
||||||
|
|
||||||
void cover(t_node *to_cover);
|
void cover(t_node *to_cover);
|
||||||
|
|
||||||
|
@ -88,4 +106,8 @@ void uncover(t_node *to_uncover);
|
||||||
|
|
||||||
int *get_types(char **ttr);
|
int *get_types(char **ttr);
|
||||||
|
|
||||||
|
int get_amount(char **ttr);
|
||||||
|
|
||||||
|
unsigned int ft_sqrt_ceil(unsigned int num);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
97
inc/libft.h
97
inc/libft.h
|
@ -1,97 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
|
|
||||||
/* Updated: 2016/12/06 20:08:35 by gtertysh ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
|
|
||||||
# include <string.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <unistd.h>
|
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
size_t content_size;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
void *ft_memset(void *b, int c, size_t len);
|
|
||||||
void ft_bzero(void *s, size_t n);
|
|
||||||
void *ft_memcpy(void *dst, const void *src, size_t len);
|
|
||||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
|
||||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
|
||||||
void *ft_memchr(const void *s, int c, size_t n);
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
|
||||||
size_t ft_strlen(const char *s);
|
|
||||||
char *ft_strdup(const char *s1);
|
|
||||||
char *ft_strcpy(char *dst, const char *src);
|
|
||||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
|
||||||
char *ft_strcat(char *s1, const char *s2);
|
|
||||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
|
||||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
|
||||||
char *ft_strchr(const char *s, int c);
|
|
||||||
char *ft_strrchr(const char *s, int c);
|
|
||||||
char *ft_strstr(const char *big, const char *little);
|
|
||||||
char *ft_strnstr(const char *big, const char *little,
|
|
||||||
size_t len);
|
|
||||||
int ft_strcmp(const char *s1, const char *s2);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|
||||||
int ft_atoi(const char *str);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isdigit(int c);
|
|
||||||
int ft_isalpha(int c);
|
|
||||||
int ft_isalnum(int c);
|
|
||||||
int ft_isascii(int c);
|
|
||||||
int ft_isprint(int c);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
|
|
||||||
void *ft_memalloc(size_t size);
|
|
||||||
void ft_memdel(void **ap);
|
|
||||||
char *ft_strnew(size_t size);
|
|
||||||
void ft_strdel(char **as);
|
|
||||||
void ft_strclr(char *s);
|
|
||||||
void ft_striter(char *s, void (*f)(char *));
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
|
||||||
char *ft_strmap(char const *s, char (*f)(char));
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
|
||||||
int ft_strequ(char const *s1, char const *s2);
|
|
||||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
|
||||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *ft_strtrim(char const *s);
|
|
||||||
char **ft_strsplit(char const *s, char c);
|
|
||||||
char *ft_itoa(int c);
|
|
||||||
void ft_putchar(char c);
|
|
||||||
void ft_putstr(char const *s);
|
|
||||||
void ft_putendl(char const *s);
|
|
||||||
void ft_putnbr(int n);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putstr_fd(char const *s, int fd);
|
|
||||||
void ft_putendl_fd(char const *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
|
||||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
|
||||||
|
|
||||||
t_list *ft_lststrsplit(const char *s, char c);
|
|
||||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
|
|
||||||
t_list *ft_lst_at(t_list *l, unsigned int at);
|
|
||||||
void ft_lstadd_back(t_list **l, void *data, size_t size);
|
|
||||||
void *ft_realloc(void *old, unsigned int new_size,
|
|
||||||
unsigned int old_size);
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -76,6 +76,7 @@ SRC = ft_memset.c \
|
||||||
ft_lstfind.c \
|
ft_lstfind.c \
|
||||||
ft_lst_at.c \
|
ft_lst_at.c \
|
||||||
ft_lstadd_back.c \
|
ft_lstadd_back.c \
|
||||||
|
ft_lstpop.c \
|
||||||
\
|
\
|
||||||
ft_realloc.c
|
ft_realloc.c
|
||||||
|
|
||||||
|
|
26
libft/ft_lstpop.c
Normal file
26
libft/ft_lstpop.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstpop.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/12/04 18:30:18 by gtertysh #+# #+# */
|
||||||
|
/* Updated: 2016/12/06 19:46:45 by gtertysh ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstpop(t_list **alst)
|
||||||
|
{
|
||||||
|
t_list *first;
|
||||||
|
|
||||||
|
first = NULL;
|
||||||
|
if (alst)
|
||||||
|
{
|
||||||
|
first = *alst;
|
||||||
|
*alst = (*alst)->next;
|
||||||
|
}
|
||||||
|
return (first);
|
||||||
|
}
|
|
@ -86,6 +86,7 @@ void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||||
void ft_lstadd(t_list **alst, t_list *new);
|
void ft_lstadd(t_list **alst, t_list *new);
|
||||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||||
|
t_list *ft_lstpop(t_list **alst);
|
||||||
|
|
||||||
t_list *ft_lststrsplit(const char *s, char c);
|
t_list *ft_lststrsplit(const char *s, char c);
|
||||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
|
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
|
||||||
|
|
|
@ -13,13 +13,14 @@
|
||||||
#include "../inc/fillit.h"
|
#include "../inc/fillit.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
t_node *init_root()
|
t_node *init_root(void)
|
||||||
{
|
{
|
||||||
t_node *new;
|
t_node *new;
|
||||||
|
|
||||||
new = (t_node*)malloc(sizeof(t_node));
|
new = (t_node*)malloc(sizeof(t_node));
|
||||||
new->left = new->right = new->down = new->up = NULL;
|
new->left = new->right = new->down = new->up = NULL;
|
||||||
new->column = NULL;
|
new->column = NULL;
|
||||||
|
return (new);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_node *add_column(t_node *root)
|
t_node *add_column(t_node *root)
|
||||||
|
@ -49,7 +50,7 @@ t_node *add_node_with_coord(t_node *col, t_coord coord)
|
||||||
return (new_node);
|
return (new_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_node *add_node(t_node *col
|
t_node *add_node(t_node *col)
|
||||||
{
|
{
|
||||||
t_node *new_node;
|
t_node *new_node;
|
||||||
|
|
||||||
|
@ -122,13 +123,17 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr)
|
||||||
l = 0;
|
l = 0;
|
||||||
while (l < size - g_templates[types[i]].height)
|
while (l < size - g_templates[types[i]].height)
|
||||||
{
|
{
|
||||||
coord = {k, l};
|
coord.x = k;
|
||||||
|
coord.y = l;
|
||||||
col_num = get_coords(coord, amount, types[i], size);
|
col_num = get_coords(coord, amount, types[i], size);
|
||||||
col_num[0] = i;
|
col_num[0] = i;
|
||||||
add_row(col_num, cols_arr, coord);
|
add_row(col_num, cols_arr, coord);
|
||||||
link_row(col_num, cols_arr);
|
link_row(col_num, cols_arr);
|
||||||
|
l++;
|
||||||
}
|
}
|
||||||
|
k++;
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,6 +178,12 @@ void uncover(t_node *to_uncover)
|
||||||
to_uncover->right->left = to_uncover;
|
to_uncover->right->left = to_uncover;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_solution(t_list *sol)
|
||||||
|
{
|
||||||
|
sol = 0;
|
||||||
|
printf("as\n");
|
||||||
|
}
|
||||||
|
|
||||||
void search(t_node* root, t_list *solution, int k, int amount)
|
void search(t_node* root, t_list *solution, int k, int amount)
|
||||||
{
|
{
|
||||||
t_node *current_col;
|
t_node *current_col;
|
||||||
|
|
11
src/get_amount.c
Normal file
11
src/get_amount.c
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
int get_amount(char **ttr)
|
||||||
|
{
|
||||||
|
int amount;
|
||||||
|
|
||||||
|
amount = 0;
|
||||||
|
while (ttr[amount])
|
||||||
|
amount++;
|
||||||
|
return (amount);
|
||||||
|
}
|
|
@ -52,6 +52,7 @@ int main(int argc, char **argv)
|
||||||
t_node **cols_arr;
|
t_node **cols_arr;
|
||||||
t_list *ans;
|
t_list *ans;
|
||||||
|
|
||||||
|
ans = NULL;
|
||||||
i = 0;
|
i = 0;
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
|
@ -85,9 +86,9 @@ int main(int argc, char **argv)
|
||||||
size = ft_sqrt_ceil(amount * 4);
|
size = ft_sqrt_ceil(amount * 4);
|
||||||
r = init_root();
|
r = init_root();
|
||||||
cols_arr = add_cols(r, (size * size + amount));
|
cols_arr = add_cols(r, (size * size + amount));
|
||||||
add_rows(types, amount, cols_arr);
|
add_rows(types, amount, size, cols_arr);
|
||||||
ans = dlx(r);
|
//search(r, ans, 0, amount);
|
||||||
print_ans(ans);
|
//print_ans(ans);
|
||||||
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
//printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y);
|
||||||
//to_letters(ttr);
|
//to_letters(ttr);
|
||||||
//printf("to latters:\n\n");
|
//printf("to latters:\n\n");
|
||||||
|
|
|
@ -25,7 +25,7 @@ void print_one_string(t_ttrmn ttr)
|
||||||
ft_putchar('\n');
|
ft_putchar('\n');
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
printf("x = %d, y = %d\n", ttr.x, ttr.y);
|
printf("x = %d, y = %d\n", ttr.width, ttr.height);
|
||||||
printf("x1[%d] y1[%d]\nx2[%d] y2[%d]\nx3[%d] y3[%d]\nx4[%d] y4[%d]\n", ttr.c[0].x, ttr.c[0].y, ttr.c[1].x, ttr.c[1].y, ttr.c[2].x, ttr.c[2].y, ttr.c[3].x, ttr.c[3].y);
|
printf("x1[%d] y1[%d]\nx2[%d] y2[%d]\nx3[%d] y3[%d]\nx4[%d] y4[%d]\n", ttr.c[0].x, ttr.c[0].y, ttr.c[1].x, ttr.c[1].y, ttr.c[2].x, ttr.c[2].y, ttr.c[3].x, ttr.c[3].y);
|
||||||
ft_putstr("\n");
|
ft_putstr("\n");
|
||||||
}
|
}
|
Loading…
Reference in a new issue