diff --git a/Makefile b/Makefile index 577c3c7..05e55b2 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ SRCDIR = ./src/ OBJDIR = ./obj/ SRC_FILES = main.c \ + fillit.c \ glue_figure.c \ move_up_left.c \ read_file.c \ @@ -24,6 +25,7 @@ SRC_FILES = main.c \ to_letters.c \ dancing_links.c \ get_types.c \ + get_amount.c \ test!_check.c \ test!_print_one_string.c \ test!_print_table.c \ @@ -35,7 +37,7 @@ SRC = $(addprefix $(SRCDIR), $(SRC_FILES)) OBJ = $(addprefix $(OBJDIR), $(OBJ_FILES)) -INC = -I ./inc +INC = -I ./inc -I $(LIBFOLDER) LIB = libft.a diff --git a/inc/fillit.h b/inc/fillit.h index 214d08e..81af720 100644 --- a/inc/fillit.h +++ b/inc/fillit.h @@ -78,9 +78,27 @@ void to_letters(char **ttr); // create array of ttr structures int *to_strct_array(char **ttr, t_ttrmn *templates); +t_node *init_root(void); + 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); @@ -88,4 +106,8 @@ void uncover(t_node *to_uncover); int *get_types(char **ttr); +int get_amount(char **ttr); + +unsigned int ft_sqrt_ceil(unsigned int num); + #endif diff --git a/inc/libft.h b/inc/libft.h deleted file mode 100644 index a60ff79..0000000 --- a/inc/libft.h +++ /dev/null @@ -1,97 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gtertysh +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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 -# include -# include - -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 diff --git a/libft/Makefile b/libft/Makefile index 1271e00..fbe50a5 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -76,6 +76,7 @@ SRC = ft_memset.c \ ft_lstfind.c \ ft_lst_at.c \ ft_lstadd_back.c \ + ft_lstpop.c \ \ ft_realloc.c diff --git a/libft/ft_lstpop.c b/libft/ft_lstpop.c new file mode 100644 index 0000000..dc7af32 --- /dev/null +++ b/libft/ft_lstpop.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstpop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/libft/libft.h b/libft/libft.h index a60ff79..da269ed 100644 --- a/libft/libft.h +++ b/libft/libft.h @@ -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_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_lstpop(t_list **alst); t_list *ft_lststrsplit(const char *s, char c); t_list *ft_lstfind(t_list *lst, void *data, size_t size); diff --git a/src/dancing_links.c b/src/dancing_links.c index 04eda08..2514ec6 100644 --- a/src/dancing_links.c +++ b/src/dancing_links.c @@ -13,13 +13,14 @@ #include "../inc/fillit.h" #include -t_node *init_root() +t_node *init_root(void) { t_node *new; new = (t_node*)malloc(sizeof(t_node)); new->left = new->right = new->down = new->up = NULL; new->column = NULL; + return (new); } 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); } -t_node *add_node(t_node *col +t_node *add_node(t_node *col) { t_node *new_node; @@ -122,13 +123,17 @@ void add_rows(int *types, int amount, int size, t_node **cols_arr) l = 0; 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[0] = i; add_row(col_num, cols_arr, coord); 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; } +void print_solution(t_list *sol) +{ + sol = 0; + printf("as\n"); +} + void search(t_node* root, t_list *solution, int k, int amount) { t_node *current_col; diff --git a/src/get_amount.c b/src/get_amount.c new file mode 100644 index 0000000..939b8d3 --- /dev/null +++ b/src/get_amount.c @@ -0,0 +1,11 @@ +#include "fillit.h" + +int get_amount(char **ttr) +{ + int amount; + + amount = 0; + while (ttr[amount]) + amount++; + return (amount); +} \ No newline at end of file diff --git a/src/main.c b/src/main.c index f1b9807..1640555 100644 --- a/src/main.c +++ b/src/main.c @@ -52,6 +52,7 @@ int main(int argc, char **argv) t_node **cols_arr; t_list *ans; + ans = NULL; i = 0; if (argc != 2) { @@ -85,9 +86,9 @@ int main(int argc, char **argv) size = ft_sqrt_ceil(amount * 4); r = init_root(); cols_arr = add_cols(r, (size * size + amount)); - add_rows(types, amount, cols_arr); - ans = dlx(r); - print_ans(ans); + add_rows(types, amount, size, cols_arr); + //search(r, ans, 0, amount); + //print_ans(ans); //printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y); //to_letters(ttr); //printf("to latters:\n\n"); diff --git a/src/test!_print_one_string.c b/src/test!_print_one_string.c index 9e3be5f..d215baf 100644 --- a/src/test!_print_one_string.c +++ b/src/test!_print_one_string.c @@ -25,7 +25,7 @@ void print_one_string(t_ttrmn ttr) ft_putchar('\n'); 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); ft_putstr("\n"); } \ No newline at end of file