From f626a8b584e1cfe3bd8ab6d1593f590b0722290a Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 20:10:01 -0400 Subject: [PATCH 01/32] Fixed split_in_two I think I might have mistaken an int and a float, which would effectively render useless the whole algo... --- libft | 2 +- src/split_in_two.c | 309 +++++++++++---------------------------------- 2 files changed, 72 insertions(+), 239 deletions(-) diff --git a/libft b/libft index a0716d3..624d3b1 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit a0716d347265a810f95aef2a043e89e12332c803 +Subproject commit 624d3b17712c0d9ee4b44d31c714882d4577b68a diff --git a/src/split_in_two.c b/src/split_in_two.c index 21fd074..efa1eb1 100644 --- a/src/split_in_two.c +++ b/src/split_in_two.c @@ -17,7 +17,8 @@ int max_elem_leaving(t_main_cont *cont, t_deque *leaving_vals) return (max_elem); } -void try_single_cutoff(t_main_cont *cont, t_deque *block_ids, float cutoff) +static void try_single_cutoff( + t_main_cont *cont, t_deque *block_ids, float cutoff) { partition_leaving_vals_cutoff( &cont->leaving_vals, @@ -35,60 +36,16 @@ void try_single_cutoff(t_main_cont *cont, t_deque *block_ids, float cutoff) return ; } -void split_in_two(t_main_cont *cont) +static void try_multiple_cutoffs_body( + t_main_cont *cont, t_deque *block_ids, float cutoff, int id_to_push) { - t_deque *block_ids; - int i; - - new_deque(&block_ids); - - try_single_cutoff(cont, block_ids, 5 / 8); - try_single_cutoff(cont, block_ids, 13 / 24); - try_single_cutoff(cont, block_ids, 11 / 24); - try_single_cutoff(cont, block_ids, 3 / 8); - try_single_cutoff(cont, block_ids, 7 / 24); - + int i; partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 3 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 2 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - insert_block_of_a_in_b(cont, block_ids, 0); - insert_b(cont, &cont->curr_moves); - rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); - if (cont->curr_moves.size < cont->best_moves.size) - { - copy_deque(&cont->curr_moves, &cont->best_moves); - } - // undo_moves(cont, &cont->curr_moves); - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); - deque_reinit_list(&cont->curr_moves); + &cont->leaving_vals, + block_ids, + (int)(max_elem_leaving(cont, &cont->leaving_vals) * cutoff)); + insert_block_of_a_in_b(cont, block_ids, id_to_push); deque_reinit_list(&cont->leaving_vals); i = 0; while (i < cont->stack_a.size) @@ -96,37 +53,29 @@ void split_in_two(t_main_cont *cont) if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) cont->leaving_vals.add_last(&cont->leaving_vals, -1); else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); + cont->leaving_vals.add_last( + &cont->leaving_vals, + cont->stack_a.elems[i]); i++; } +} +static void try_multiple_cutoffs_footer( + t_main_cont *cont, t_deque *block_ids, float cutoff, int id_to_push) +{ + int i; partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 3 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 2 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - insert_block_of_a_in_b(cont, block_ids, 0); + &cont->leaving_vals, block_ids, + (int)(max_elem_leaving(cont, &cont->leaving_vals) * cutoff)); + insert_block_of_a_in_b(cont, block_ids, id_to_push); + insert_block_of_a_in_b(cont, block_ids, (id_to_push + 1) % 2); insert_b(cont, &cont->curr_moves); rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); if (cont->curr_moves.size < cont->best_moves.size) - { copy_deque(&cont->curr_moves, &cont->best_moves); - } - // undo_moves(cont, &cont->curr_moves); - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); + copy_deque(&cont->initial_stack, &cont->stack_a); + deque_reinit_list(&cont->stack_b); deque_reinit_list(&cont->curr_moves); deque_reinit_list(&cont->leaving_vals); i = 0; @@ -135,177 +84,61 @@ void split_in_two(t_main_cont *cont) if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) cont->leaving_vals.add_last(&cont->leaving_vals, -1); else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); + cont->leaving_vals.add_last( + &cont->leaving_vals, cont->stack_a.elems[i]); i++; - } + } +} +static void split_in_two_mult_cutoffs(t_main_cont *cont, t_deque *block_ids) +{ - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 3 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 2 / 5); - insert_block_of_a_in_b(cont, block_ids, 1); - insert_block_of_a_in_b(cont, block_ids, 0); - insert_b(cont, &cont->curr_moves); - rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); - if (cont->curr_moves.size < cont->best_moves.size) - { - copy_deque(&cont->curr_moves, &cont->best_moves); - } - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); - deque_reinit_list(&cont->curr_moves); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } +} +void split_in_two(t_main_cont *cont) +{ + t_deque *block_ids; - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 0); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 0); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 0); - insert_block_of_a_in_b(cont, block_ids, 1); - insert_b(cont, &cont->curr_moves); - rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); - if (cont->curr_moves.size < cont->best_moves.size) - { - copy_deque(&cont->curr_moves, &cont->best_moves); - } - // undo_moves(cont, &cont->curr_moves); - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); - deque_reinit_list(&cont->curr_moves); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } + new_deque(&block_ids); + try_single_cutoff(cont, block_ids, 5 / 8); + try_single_cutoff(cont, block_ids, 13 / 24); + try_single_cutoff(cont, block_ids, 11 / 24); + try_single_cutoff(cont, block_ids, 3 / 8); + try_single_cutoff(cont, block_ids, 7 / 24); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); + + try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); + + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); + try_multiple_cutoffs_footer(cont, block_ids, 0.5F, 1); + + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 0); + try_multiple_cutoffs_body(cont, block_ids, 0.5F, 0); + try_multiple_cutoffs_footer(cont, block_ids, 0.5F, 0); - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } - partition_leaving_vals_cutoff( - &cont->leaving_vals, block_ids, max_elem_leaving(cont, &cont->leaving_vals) * 1 / 2); - insert_block_of_a_in_b(cont, block_ids, 1); - insert_block_of_a_in_b(cont, block_ids, 0); - insert_b(cont, &cont->curr_moves); - rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); - if (cont->curr_moves.size < cont->best_moves.size) - { - copy_deque(&cont->curr_moves, &cont->best_moves); - } - // undo_moves(cont, &cont->curr_moves); - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); - deque_reinit_list(&cont->curr_moves); - deque_reinit_list(&cont->leaving_vals); - i = 0; - while (i < cont->stack_a.size) - { - if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) - cont->leaving_vals.add_last(&cont->leaving_vals, -1); - else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); - i++; - } // Free block_ids block_ids->free_list(block_ids); From d9f6230d4be164c2a4f1462b9692024a670e4745 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:25:09 -0400 Subject: [PATCH 02/32] Fixed deques --- Makefile | 2 + include/deques.h | 19 ++- src/calc_insert_cost.c | 25 ++- src/deques.c | 217 +++--------------------- src/split_in_two.c | 35 ++-- src/unit_tests/calc_insert_costs_test.c | 48 ------ 6 files changed, 60 insertions(+), 286 deletions(-) delete mode 100644 src/unit_tests/calc_insert_costs_test.c diff --git a/Makefile b/Makefile index 134b5a1..258b789 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,9 @@ CFILES = algorithms.c \ cherrypick_utils.c \ cleanup.c \ deques.c \ + deque_modify.c \ deque_operators.c \ + deque_utils.c \ errors.c \ ignore_LIS.c \ init.c \ diff --git a/include/deques.h b/include/deques.h index a449384..77f151b 100644 --- a/include/deques.h +++ b/include/deques.h @@ -2,6 +2,7 @@ # define DEQUES_H # include +# include # include # include @@ -36,21 +37,25 @@ typedef struct s_deque void (*set_elem)(t_deque *, int, int); } t_deque; -// Deques +// deques.c void init_deque(t_deque *deque); -bool deque_add_front(t_deque *deque, int new_elem); -bool deque_add_last(t_deque *deque, int new_elem); +bool deque_reinit_list(t_deque *deque); + +// deque_utils.c +bool deque_resize_end(t_deque *deque, int new_size); +bool deque_resize_front(t_deque *deque, int new_size); void deque_free_list(t_deque *deque); int deque_get_elem_max(t_deque *deque); int deque_get_elem_min(t_deque *deque); -bool deque_reinit_list(t_deque *deque); + +// deque_modify.c +bool deque_add_front(t_deque *deque, int new_elem); +bool deque_add_last(t_deque *deque, int new_elem); void deque_remove_front(t_deque *deque); void deque_remove_last(t_deque *deque); -bool deque_resize_end(t_deque *deque, int new_size); -bool deque_resize_front(t_deque *deque, int new_size); void deque_set_elem(t_deque *deque, int pos, int new_value); -// Operators +// deque_operators.c void new_deque(t_deque **deque); t_deque *clone_deque(t_deque *src); void copy_deque(t_deque *src, t_deque *dest); diff --git a/src/calc_insert_cost.c b/src/calc_insert_cost.c index 3b98d38..0e26b3d 100644 --- a/src/calc_insert_cost.c +++ b/src/calc_insert_cost.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* calc_insert_cost.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- dist0 = a_info->pos; if (ft_abs(a_info->revpos) < a_info->pos) a_info->dist0 = a_info->revpos; - b_info->dist0 = b_info->pos; if (ft_abs(b_info->revpos) < b_info->pos) b_info->dist0 = b_info->revpos; - - //If equal in both directions, pick the one in the same direction as the other - if (ft_abs(a_info->revpos) == a_info->pos && b_info->dist0 < 0) a_info->dist0 = a_info->revpos; if (ft_abs(b_info->revpos) == b_info->pos && a_info->dist0 < 0) @@ -32,7 +40,7 @@ static int get_best_absolute_cost( ft_max(a_info->pos, b_info->pos), ft_max(-a_info->revpos, -b_info->revpos)); curr_cost = ft_min( - curr_cost, + curr_cost, ft_abs(a_info->dist0) + ft_abs(b_info->dist0)); return (curr_cost); } @@ -44,7 +52,7 @@ static int get_best_absolute_cost( // int calc_insert_cost(t_insert_info *info) { - int curr_cost; + int curr_cost; set_best_individual_costs(&info->a_info, &info->b_info); curr_cost = get_best_absolute_cost(&info->a_info, &info->b_info); @@ -68,8 +76,8 @@ static bool is_new_best_moves(t_insert_info *info) void update_insert_info(t_main_cont *cont, t_insert_info *info) { - t_stack_insert_info *a_info; - t_stack_insert_info *b_info; + t_stack_insert_info *a_info; + t_stack_insert_info *b_info; a_info = &info->a_info; b_info = &info->b_info; @@ -93,5 +101,4 @@ void update_insert_info(t_main_cont *cont, t_insert_info *info) info->min_cost = info->curr_cost; info->min_delta_insert = info->curr_delta_insert; } - return ; } diff --git a/src/deques.c b/src/deques.c index a6c5720..798035d 100644 --- a/src/deques.c +++ b/src/deques.c @@ -1,121 +1,32 @@ #include "deques.h" -#include void init_deque(t_deque *deque) { - //Add the atrocious list of helper functions(probs too much) - deque->add_front = &deque_add_front; - deque->add_last = &deque_add_last; - deque->free_list = &deque_free_list; - deque->get_elem_max = &deque_get_elem_max; - deque->get_elem_min = &deque_get_elem_min; - deque->reinit_list = &deque_reinit_list; - deque->remove_front = &deque_remove_front; - deque->remove_last = &deque_remove_last; - deque->resize_end = &deque_resize_end; - deque->resize_front = &deque_resize_front; - deque->set_elem = &deque_set_elem; - - - //Malloc a block of memory designed to leave space on each side of the - //deque_head, so that values can be added on both ends with the same - //calculation cost, while still sharing a single memory space. - deque->size = 0; - deque->min_elem = deque->get_elem_min(deque); - deque->max_elem = deque->get_elem_max(deque); - deque->capacity_end = VECTOR_INIT_SIZE; - deque->capacity_front = VECTOR_INIT_SIZE; - deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); + deque->add_front = &deque_add_front; + deque->add_last = &deque_add_last; + deque->free_list = &deque_free_list; + deque->get_elem_max = &deque_get_elem_max; + deque->get_elem_min = &deque_get_elem_min; + deque->reinit_list = &deque_reinit_list; + deque->remove_front = &deque_remove_front; + deque->remove_last = &deque_remove_last; + deque->resize_end = &deque_resize_end; + deque->resize_front = &deque_resize_front; + deque->set_elem = &deque_set_elem; + deque->size = 0; + deque->min_elem = deque->get_elem_min(deque); + deque->max_elem = deque->get_elem_max(deque); + deque->capacity_end = VECTOR_INIT_SIZE; + deque->capacity_front = VECTOR_INIT_SIZE; + deque->capacity_total = 2 * VECTOR_INIT_SIZE; + deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); if (!deque->malloced_space) exit_on_err("init_deque error\n"); ft_bzero(deque->malloced_space, 2 * VECTOR_INIT_SIZE); - deque->elems = &(deque->malloced_space[VECTOR_INIT_SIZE]); - return ; -} - -bool deque_add_front(t_deque *deque, int new_elem) -{ - bool status; - - if (deque->capacity_front == 0) - { - status = deque_resize_front(deque, deque->capacity_total); - if (status == FAILURE) - return (status); - } - deque->elems -= 1; - deque->elems[0] = new_elem; - deque->size += 1; - deque->capacity_front -= 1; - deque->capacity_end += 1; - if (new_elem > deque->max_elem) - deque->max_elem = new_elem; - if (new_elem < deque->min_elem) - deque->min_elem = new_elem; - status = SUCCESS; - return (status); -} - -bool deque_add_last(t_deque *deque, int new_elem) -{ - bool status; - - if (deque->size == deque->capacity_end) - { - status = deque_resize_end(deque, deque->capacity_total * 2); - if (status == FAILURE) - return (status); - } - deque->elems[deque->size] = new_elem; - deque->size += 1; - if (new_elem > deque->max_elem) - deque->max_elem = new_elem; - if (new_elem < deque->min_elem) - deque->min_elem = new_elem; - status = SUCCESS; - return (status); -} - -void deque_free_list(t_deque *deque) -{ - free (deque->malloced_space); - deque->malloced_space = NULL; + deque->elems = &(deque->malloced_space[VECTOR_INIT_SIZE]); return ; } -int deque_get_elem_max(t_deque *deque) -{ - int pos_in_stack; - int biggest_value; - - biggest_value = INT_MIN; - pos_in_stack = 0; - while (pos_in_stack < deque->size) - { - if (deque->elems[pos_in_stack] > biggest_value) - biggest_value = deque->elems[pos_in_stack]; - pos_in_stack++; - } - return (biggest_value); -} - -int deque_get_elem_min(t_deque *deque) -{ - int pos_in_stack; - int smallest_value; - - smallest_value = INT_MAX; - pos_in_stack = 0; - while (pos_in_stack < deque->size) - { - if (deque->elems[pos_in_stack] < smallest_value) - smallest_value = deque->elems[pos_in_stack]; - pos_in_stack++; - } - return (smallest_value); -} - bool deque_reinit_list(t_deque *deque) { free(deque->malloced_space); @@ -129,96 +40,6 @@ bool deque_reinit_list(t_deque *deque) if (!deque->malloced_space) return (FAILURE); ft_bzero(deque->malloced_space, 2 * VECTOR_INIT_SIZE); - //MADE A CHANGE HERE BY REMOVING THE ADDRESS ASSIGNATION deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; return (SUCCESS); } - -//Need to add resize smaller when under a certain size -void deque_remove_front(t_deque *deque) -{ - int elem_to_be_removed; - - elem_to_be_removed = deque->elems[0]; - deque->elems[0] = 0; - deque->elems += 1; - deque->capacity_front += 1; - deque->capacity_end -= 1; - deque->size -= 1; - if (elem_to_be_removed == deque->min_elem) - deque->min_elem = deque->get_elem_min(deque); - if (elem_to_be_removed == deque->max_elem) - deque->max_elem = deque->get_elem_max(deque); - return ; -} - -//Need to add resize smaller when under a certain size -void deque_remove_last(t_deque *deque) -{ - int elem_to_be_removed; - - elem_to_be_removed = deque->elems[deque->size - 1]; - deque->elems[deque->size - 1] = 0; - deque->size -= 1; - if (elem_to_be_removed == deque->min_elem) - deque->min_elem = deque->get_elem_min(deque); - if (elem_to_be_removed == deque->max_elem) - deque->max_elem = deque->get_elem_max(deque); - return ; -} - -bool deque_resize_front(t_deque *deque, int new_size) -{ - int *temp; - int total_new_size; - int pos_in_deque; - - total_new_size = new_size + deque->capacity_end; - temp = malloc(total_new_size * sizeof(int)); - if (!temp) - return (FAILURE); - temp += new_size; - pos_in_deque = 0; - while (pos_in_deque < deque->size) - { - temp[pos_in_deque] = deque->elems[pos_in_deque]; - pos_in_deque++; - } - free(deque->malloced_space); - deque->malloced_space = temp - new_size; - deque->elems = temp; - deque->capacity_front = new_size; - deque->capacity_total = total_new_size; - return (SUCCESS); -} - -bool deque_resize_end(t_deque *deque, int new_size) -{ - int *temp; - int total_new_size; - int pos_in_deque; - - total_new_size = new_size + deque->capacity_front; - temp = malloc(total_new_size * sizeof(int)); - if (!temp) - return (FAILURE); - temp += deque->capacity_front; - pos_in_deque = 0; - while (pos_in_deque < deque->size) - { - temp[pos_in_deque] = deque->elems[pos_in_deque]; - pos_in_deque++; - } - free(deque->malloced_space); - deque->malloced_space = temp - deque->capacity_front; - deque->elems = temp; - deque->capacity_end = new_size; - deque->capacity_total = total_new_size; - return (SUCCESS); -} - -void deque_set_elem(t_deque *deque, int pos, int new_value) -{ - deque->elems[pos] = new_value; - return ; -} diff --git a/src/split_in_two.c b/src/split_in_two.c index efa1eb1..8c27fc3 100644 --- a/src/split_in_two.c +++ b/src/split_in_two.c @@ -92,57 +92,44 @@ static void try_multiple_cutoffs_footer( static void split_in_two_mult_cutoffs(t_main_cont *cont, t_deque *block_ids) { - -} - -void split_in_two(t_main_cont *cont) -{ - t_deque *block_ids; - - new_deque(&block_ids); - - try_single_cutoff(cont, block_ids, 5 / 8); - try_single_cutoff(cont, block_ids, 13 / 24); - try_single_cutoff(cont, block_ids, 11 / 24); - try_single_cutoff(cont, block_ids, 3 / 8); - try_single_cutoff(cont, block_ids, 7 / 24); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 1); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); - try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.4F, 0); - try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); try_multiple_cutoffs_footer(cont, block_ids, 0.5F, 1); - try_multiple_cutoffs_body(cont, block_ids, 0.5F, 0); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 0); try_multiple_cutoffs_footer(cont, block_ids, 0.5F, 0); +} +void split_in_two(t_main_cont *cont) +{ + t_deque *block_ids; - // Free block_ids + new_deque(&block_ids); + try_single_cutoff(cont, block_ids, 5 / 8); + try_single_cutoff(cont, block_ids, 13 / 24); + try_single_cutoff(cont, block_ids, 11 / 24); + try_single_cutoff(cont, block_ids, 3 / 8); + try_single_cutoff(cont, block_ids, 7 / 24); + split_in_two_mult_cutoffs(cont, block_ids); block_ids->free_list(block_ids); free(block_ids); - return ; } \ No newline at end of file diff --git a/src/unit_tests/calc_insert_costs_test.c b/src/unit_tests/calc_insert_costs_test.c deleted file mode 100644 index 6585af4..0000000 --- a/src/unit_tests/calc_insert_costs_test.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "../../include/push_swap.h" - -typedef struct s_test_insert_info -{ - t_stack_insert_info a_info; - t_stack_insert_info b_info; - int min_cost; - int curr_cost; - int min_delta_insert; - int curr_delta_insert; -} t_test_insert_info; - -int test_test_calc_insert_cost(void) -{ - int size_a, size_b, pos_a, pos_b; - - size_a = 5; - size_b = 5; - pos_a = 1; - pos_b = 4; - printf("size A\t: %d\nsize B\t: %d\npos_a\t: %d\npos_b\t: %d\n", size_a, size_b, pos_a, pos_b); - printf("dist_min==> %d\n", test_calc_insert_cost(pos_a, size_a, pos_b, size_b)); - size_a = 88; - size_b = 33; - pos_a = 35; - pos_b = 32; - printf("size A\t: %d\nsize B\t: %d\npos_a\t: %d\npos_b\t: %d\n", size_a, size_b, pos_a, pos_b); - printf("dist_min==> %d\n", test_calc_insert_cost(pos_a, size_a, pos_b, size_b)); - size_a = 67; - size_b = 33; - pos_a = 33; - pos_b = 31; - printf("size A\t: %d\nsize B\t: %d\npos_a\t: %d\npos_b\t: %d\n", size_a, size_b, pos_a, pos_b); - printf("dist_min==> %d\n", test_calc_insert_cost(pos_a, size_a, pos_b, size_b)); - size_a = 67; - size_b = 33; - pos_a = 63; - pos_b = 15; - printf("size A\t: %d\nsize B\t: %d\npos_a\t: %d\npos_b\t: %d\n", size_a, size_b, pos_a, pos_b); - printf("dist_min==> %d\n", test_calc_insert_cost(pos_a, size_a, pos_b, size_b)); - size_a = 67; - size_b = 33; - pos_a = 2; - pos_b = 32; - printf("size A\t: %d\nsize B\t: %d\npos_a\t: %d\npos_b\t: %d\n", size_a, size_b, pos_a, pos_b); - printf("dist_min==> %d\n", test_calc_insert_cost(pos_a, size_a, pos_b, size_b)); - return (0); -} From 7708f987bbbb858ad4e634e75ae453ace80f4cd6 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:37:54 -0400 Subject: [PATCH 03/32] Fixed undo_moves --- include/push_swap.h | 1 - src/algorithms.c | 9 --------- src/deques.c | 30 +++++++++++++++++++++--------- src/errors.c | 12 ++++++++++++ src/push_swap.c | 22 +++++++++++++--------- src/px.c | 28 ++++++++++++++++++++-------- src/sort.c | 12 +++++++++--- src/sort_big.c | 34 ---------------------------------- src/undo_moves.c | 33 +++++++++++---------------------- 9 files changed, 86 insertions(+), 95 deletions(-) diff --git a/include/push_swap.h b/include/push_swap.h index 708e903..c4fb5d2 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -180,7 +180,6 @@ bool is_in_stack(t_deque *stack, int val); // SORT BIG void rotate_block_split(t_main_cont *cont, t_deque *block_ids, int curr_block_id, int max_val, int min_val, int median_val); void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id); -void blind_push(t_main_cont *cont, t_deque *moves_list); void insert_last_block(t_main_cont *cont, t_deque *moves_list); bool block_id_is_in_stack(t_deque *block_ids, int id); void sort_big(t_main_cont *cont); diff --git a/src/algorithms.c b/src/algorithms.c index 4eb88e5..9e3b415 100644 --- a/src/algorithms.c +++ b/src/algorithms.c @@ -1,10 +1 @@ #include "push_swap.h" - -void run_algorithms(t_main_cont *cont) -{ - split_in_blocks(cont); - split_in_two(cont); - ignore_lis(cont); - - return ; -} diff --git a/src/deques.c b/src/deques.c index 798035d..25a4277 100644 --- a/src/deques.c +++ b/src/deques.c @@ -1,6 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deques.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- add_front = &deque_add_front; deque->add_last = &deque_add_last; @@ -30,16 +42,16 @@ void init_deque(t_deque *deque) bool deque_reinit_list(t_deque *deque) { free(deque->malloced_space); - deque->size = 0; - deque->min_elem = INT_MAX - 100; - deque->max_elem = INT_MIN + 100; - deque->capacity_end = VECTOR_INIT_SIZE; - deque->capacity_front = VECTOR_INIT_SIZE; - deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); + deque->size = 0; + deque->min_elem = INT_MAX - 100; + deque->max_elem = INT_MIN + 100; + deque->capacity_end = VECTOR_INIT_SIZE; + deque->capacity_front = VECTOR_INIT_SIZE; + deque->capacity_total = 2 * VECTOR_INIT_SIZE; + deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); if (!deque->malloced_space) return (FAILURE); ft_bzero(deque->malloced_space, 2 * VECTOR_INIT_SIZE); - deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; + deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; return (SUCCESS); } diff --git a/src/errors.c b/src/errors.c index 6763bac..93dca65 100644 --- a/src/errors.c +++ b/src/errors.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* errors.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a.size <= 7) - sort(cont); - - assign_longest_increasing_subsequence(cont); - - run_algorithms(cont); - + sort(cont); print_all_moves(&cont->best_moves); cleanup(cont); - return (EXIT_SUCCESS); } diff --git a/src/px.c b/src/px.c index 0e1753b..e83ac71 100644 --- a/src/px.c +++ b/src/px.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* px.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- head_a, get_pos_smallest_val(&cont->stack_a), cont->stack_a.size, 0); - set_iterator(&cont->head_b, get_pos_smallest_val(&cont->stack_b), cont->stack_b.size, 1); + set_iterator( + &cont->head_a, + get_pos_smallest_val(&cont->stack_a), cont->stack_a.size, 0); + set_iterator( + &cont->head_b, + get_pos_smallest_val(&cont->stack_b), cont->stack_b.size, 1); return ; } -void do_pa(t_main_cont *cont, t_deque *curr_moves) +void do_pa(t_main_cont *cont, t_deque *curr_moves) { push(&cont->stack_b, &cont->stack_a); if (curr_moves) curr_moves->add_last(curr_moves, PA); - push_update_iterators(cont); - return ; } -void do_pb(t_main_cont *cont, t_deque *curr_moves) +void do_pb(t_main_cont *cont, t_deque *curr_moves) { push(&cont->stack_a, &cont->stack_b); if (curr_moves) curr_moves->add_last(curr_moves, PB); - push_update_iterators(cont); - return ; } diff --git a/src/sort.c b/src/sort.c index 64a146a..6f7c8e5 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1,5 +1,14 @@ #include "push_swap.h" +void sort_big(t_main_cont *cont) +{ + assign_longest_increasing_subsequence(cont); + split_in_blocks(cont); + split_in_two(cont); + ignore_lis(cont); + return ; +} + void sort_small(t_main_cont *cont) { if (cont->stack_a.size == 2 && !is_sorted(&cont->stack_a, 0)) @@ -15,9 +24,6 @@ void sort(t_main_cont *cont) sort_small(cont); else sort_big(cont); - print_all_moves(&cont->best_moves); - cleanup(cont); - exit(EXIT_SUCCESS); return ; } diff --git a/src/sort_big.c b/src/sort_big.c index e688b4d..5a59442 100644 --- a/src/sort_big.c +++ b/src/sort_big.c @@ -105,28 +105,6 @@ void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_bloc return ; } -void sort_big(t_main_cont *cont) -{ - // int elem_0; - int initial_size; - // int elem_1; - // int elem_last; - - initial_size = cont->stack_a.size; - - // if (stack->size == 100) - // blind_push(cont, &cont->curr_moves); - // else () - - // assign_divisions - - // insert_a needs to be ONLY called after segmentation - - - insert_b(cont, &cont->best_moves); - rotate_to_0_in_a(cont, &cont->best_moves, cont->head_a.index); -} - void insert_last_block(t_main_cont *cont, t_deque *moves_list) { int median_val; @@ -147,15 +125,3 @@ void insert_last_block(t_main_cont *cont, t_deque *moves_list) return ; } - - -void blind_push(t_main_cont *cont, t_deque *moves_list) -{ - while (!is_sorted(&cont->stack_a, cont->head_a.index) && cont->stack_a.size > 3) - { - do_pb(cont, moves_list); - } - if (!is_sorted(&cont->stack_a, cont->head_a.index)) - do_sa(cont, moves_list); - return ; -} \ No newline at end of file diff --git a/src/undo_moves.c b/src/undo_moves.c index 13cc7bd..a73fc51 100644 --- a/src/undo_moves.c +++ b/src/undo_moves.c @@ -1,36 +1,25 @@ #include "push_swap.h" /* - * REV_SA = 0 | (a => 0) + 3 * (s => 0) == 0 + 3*0 == 0 | rev_fcts[0] ==> &do_sa - * REV_SB = 1 | (b => 1) + 3 * (s => 0) == 1 + 3*0 == 1 | rev_fcts[1] ==> &do_sb - * REV_SS = 2 | (r/s => 2) + 3 * (s => 0) == 2 + 3*0 == 2 | rev_fcts[5] ==> &do_ss - * REV_RA = 3 | {...} - * REV_RB = 4 | - * REV_RR = 5 | (r/s => 2) + 3 * (r => 1) == 2 + 3*1 == 5 | rev_fcts[5] ==> &do_rrr - * REV_RRA = 6 | {...} - * REV_RRB = 7 | (b => 1) + 3 * (rr => q => 2) == 1 + 3*2 == 7| rev_fcts[7] ==> &do_rb - * REV_RRR = 8 | {...} - * REV_PA = 9 | - * REV_PB = 10 | (b => 1) + 3 * (p => 3) == 1 + 3*3 == 10 | rev_fcts[10] ==> &do_pa + * REV_SA = 0 | (a=>0) + 3 * (s=>0) = 0 + 3*0 = 0 | rev_fcts[0] => &do_sa + * REV_SB = 1 | (b=>1) + 3 * (s=>0) = 1 + 3*0 = 1 | rev_fcts[1] => &do_sb + * REV_SS = 2 | (r/s=>2) + 3 * (s=>0) = 2 + 3*0 = 2 | rev_fcts[5] => &do_ss + * REV_RA = 3 | {...} + * REV_RB = 4 | + * REV_RR = 5 | (r/s=>2) + 3 * (r=>1) = 2+ 3*1 = 5 | rev_fcts[5] => &do_rrr + * REV_RRA = 6 | {...} + * REV_RRB = 7 | (b=>1) + 3 * (rr=>q=>2) = 1 + 3*2 = 7| rev_fcts[7] => &do_rb + * REV_RRR = 8 | {...} + * REV_PA = 9 | + * REV_PB = 10 | (b=>1) + 3 * (p=>3) = 1 + 3*3 = 10 | rev_fcts[10] ==> &do_pa */ - -//Could just be: -// return ((((move & 0xFF)) / 10 - 88) + (-3 * ((move >> 8) & 0xFF) - 73)); int convert_move_to_index(int move) { int move_to_index; - - //transform {'a', 'b', 's' || 'r'} => {0, 1, 2}; move_to_index = ((move & 0xFF) - 'a' + 9) / 10; - - //if move starts with 'rr', convert it to 'q' instead if (move >> 16 == 'r') move = (move & 0xFF) | (('r' - 1) << 8); - //transform {'p', 'q', 'r', 's'} => {3, 2, 1, 0}; - //p is the only family of fcts with less than 3 members, needs to be last. - //get the position and multiply by 3 to get the offset. move_to_index += (((move >> 8) & 0xFF) - 'p' - 3) * (-1) * 3; - return (move_to_index); } From ea7050b19e0157b47ea51405d513f76140f774c1 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 21:40:19 -0400 Subject: [PATCH 04/32] fixed parse.c --- src/algorithms.c | 1 - src/parse.c | 17 +++++++++++++---- src/undo_moves.c | 13 +++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) delete mode 100644 src/algorithms.c diff --git a/src/algorithms.c b/src/algorithms.c deleted file mode 100644 index 9e3b415..0000000 --- a/src/algorithms.c +++ /dev/null @@ -1 +0,0 @@ -#include "push_swap.h" diff --git a/src/parse.c b/src/parse.c index 654657d..fd2f1b9 100644 --- a/src/parse.c +++ b/src/parse.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- > 16 == 'r') move = (move & 0xFF) | (('r' - 1) << 8); From 0ca41cca9e0c580eb0014be74411bef3d696e332 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:01:13 -0400 Subject: [PATCH 05/32] Created block_utils rotate_block_split(t_main_cont *cont, t_deque *block_ids, t_block_info *info); block_id_is_in_stack(t_deque *block_ids, int id); has_smaller_than_median(t_deque *stack, t_block_info *info); has_bigger_than_median(t_deque *stack, int median_val, int max_val); assign_block_median(t_deque *stack, t_deque *block_ids, t_block_info *info); --- Makefile | 2 +- include/push_swap.h | 10 ++-- src/cherrypick.c | 49 ++++++++-------- src/cherrypick_utils.c | 19 ++++++ src/insert_blocks.c | 85 ++------------------------- src/insert_utils.c | 50 ++++++++++++++++ src/sort_big.c | 127 ----------------------------------------- 7 files changed, 104 insertions(+), 238 deletions(-) delete mode 100644 src/sort_big.c diff --git a/Makefile b/Makefile index 258b789..0c4cd54 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ ON_RED = \033[41m RESET_COL = \033[0m CFILES = algorithms.c \ + block_utils.c \ calc_insert_cost.c \ cherrypick.c \ cherrypick_utils.c \ @@ -37,7 +38,6 @@ CFILES = algorithms.c \ rrx.c \ rx.c \ sort.c \ - sort_big.c \ sort_utils.c \ split_in_blocks.c \ split_in_two.c \ diff --git a/include/push_swap.h b/include/push_swap.h index c4fb5d2..4c1e293 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -159,6 +159,8 @@ void insert_elem_b(t_main_cont *cont, t_deque *moves_buff, t_insert_info *info); int get_cost_either_direction(t_insert_info *info); int get_cost_indep_directions(t_insert_info *info); int get_insert_val(t_deque *haystack, int curr_val); +void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id); +void insert_last_block(t_main_cont *cont, t_deque *moves_list); // calc_insert_cost.c void init_insert_info(t_main_cont *cont, t_insert_info *info); @@ -178,14 +180,12 @@ void rotate_to_0_in_a(t_main_cont *cont, t_deque *curr_moves, int pos); bool is_in_stack(t_deque *stack, int val); // SORT BIG -void rotate_block_split(t_main_cont *cont, t_deque *block_ids, int curr_block_id, int max_val, int min_val, int median_val); -void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id); -void insert_last_block(t_main_cont *cont, t_deque *moves_list); +void rotate_block_split(t_main_cont *cont, t_deque *block_ids, t_block_info *info); bool block_id_is_in_stack(t_deque *block_ids, int id); void sort_big(t_main_cont *cont); -bool has_smaller_than_median(t_deque *stack, int median_val, int min_val); +bool has_smaller_than_median(t_deque *stack, t_block_info *info); bool has_bigger_than_median(t_deque *stack, int median_val, int max_val); -int calc_block_median(t_deque *stack, t_deque *block_ids, int curr_block_id, int *max_val, int *min_val); +void assign_block_median(t_deque *stack, t_deque *block_ids, t_block_info *info); //UTILS void *ft_safealloc(size_t size); diff --git a/src/cherrypick.c b/src/cherrypick.c index 6794dd2..8f61d2f 100644 --- a/src/cherrypick.c +++ b/src/cherrypick.c @@ -1,23 +1,16 @@ -#include "push_swap.h" +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cherrypick.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size - pos) - { - while (pos-- > 0) - { - rotate(stack); - } - } - else - { - while (pos++ < stack->size) - { - rev_rotate(stack); - } - } - return ; -} +#include "push_swap.h" int longest_increasing_subsequence(t_deque **list, t_deque *stack) { @@ -63,7 +56,7 @@ t_deque *get_ordered_vals(t_deque *stack) return (staying_vals); } -void normalize_staying_vals(t_main_cont *cont) +static void normalize_staying_vals(t_main_cont *cont) { int i; @@ -71,15 +64,19 @@ void normalize_staying_vals(t_main_cont *cont) while (i < cont->staying_vals.size) { if (cont->staying_vals.elems[0] > cont->stack_a.max_elem) - cont->staying_vals.add_last(&cont->staying_vals, cont->staying_vals.elems[0] - cont->stack_a.size - 1); + cont->staying_vals.add_last( + &cont->staying_vals, + cont->staying_vals.elems[0] - cont->stack_a.size - 1); else - cont->staying_vals.add_last(&cont->staying_vals, cont->staying_vals.elems[0]); + cont->staying_vals.add_last( + &cont->staying_vals, + cont->staying_vals.elems[0]); cont->staying_vals.remove_front(&cont->staying_vals); i++; } } -void assign_leaving_vals(t_main_cont *cont) +static void assign_leaving_vals(t_main_cont *cont) { int i; @@ -89,7 +86,9 @@ void assign_leaving_vals(t_main_cont *cont) if (is_in_stack(&cont->staying_vals, cont->stack_a.elems[i])) cont->leaving_vals.add_last(&cont->leaving_vals, -1); else - cont->leaving_vals.add_last(&cont->leaving_vals, cont->stack_a.elems[i]); + cont->leaving_vals.add_last( + &cont->leaving_vals, + cont->stack_a.elems[i]); i++; } } @@ -100,7 +99,6 @@ void assign_longest_increasing_subsequence(t_main_cont *cont) t_deque *staying_stack; int i; - // check nb_sorted for every val. staying_stack = clone_deque(&cont->stack_a); i = 0; while (i < cont->stack_a.size) @@ -116,7 +114,6 @@ void assign_longest_increasing_subsequence(t_main_cont *cont) i++; } normalize_staying_vals(cont); - //Free staying_stack staying_stack->free_list(staying_stack); free(staying_stack); assign_leaving_vals(cont); diff --git a/src/cherrypick_utils.c b/src/cherrypick_utils.c index c423cf0..20685d8 100644 --- a/src/cherrypick_utils.c +++ b/src/cherrypick_utils.c @@ -27,3 +27,22 @@ void free_deque_list(t_deque **list, int size) free (list); return ; } + +void rotate_stack_to_0(t_deque *stack, int pos) +{ + if (pos < stack->size - pos) + { + while (pos-- > 0) + { + rotate(stack); + } + } + else + { + while (pos++ < stack->size) + { + rev_rotate(stack); + } + } + return ; +} diff --git a/src/insert_blocks.c b/src/insert_blocks.c index 19a7f07..afdb354 100644 --- a/src/insert_blocks.c +++ b/src/insert_blocks.c @@ -120,29 +120,6 @@ void insert_block_elem_b( return ; a_info = &info->a_info; b_info = &info->b_info; - if (cont->stack_b.size > 0) - { - //TO REMOVE - // if (info.min_cost < 0) - if (DEBUG && (info->min_cost < 0 || \ - (cont->stack_a.elems[0] > cont->stack_a.elems[1] && \ - cont->stack_a.elems[1] != cont->stack_a.min_elem))) - { - printf("wtf happened after\n"); - print_stacks(cont); - printf(YELLOW"info.a_info.val_best = %d \n"RESET_COL, info->a_info.val_best); - printf(YELLOW"info.a_info.pos_best = %d \n"RESET_COL, info->a_info.pos_best); - printf(YELLOW"info.a_info.revpos_best = %d \n"RESET_COL, info->a_info.revpos_best); - printf(YELLOW"info.b_info.val_best = %d \n"RESET_COL, info->b_info.val_best); - printf(YELLOW"info.b_info.pos_best = %d \n"RESET_COL, info->b_info.pos_best); - printf(YELLOW"info.b_info.revpos_best = %d \n"RESET_COL, info->b_info.revpos_best); - printf(YELLOW"info.a_info.dist0_best = %d \n"RESET_COL, info->a_info.dist0_best); - printf(YELLOW"info.b_info.dist0_best = %d \n"RESET_COL, info->b_info.dist0_best); - printf(YELLOW"info.min_cost = %d \n"RESET_COL, info->min_cost); - printf(YELLOW"info.min_delta_insert = %d \n"RESET_COL, info->min_delta_insert); - } - //EOREMOVE - } // case for they both need to go in the same sense if (ft_same_sign(info->a_info.dist0_best, info->b_info.dist0_best)) insert_same_sign(cont, block_ids_b, info); @@ -161,74 +138,24 @@ void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_i { t_insert_info *info; - // print_stacks(cont); - // print_single_stack(block_ids_b); - - if (!block_id_is_in_stack(block_ids_b, block_id)) return ; - info = malloc(sizeof(t_insert_info)); - if (!info) - exit_on_err("insert_b: insert_info error\n"); - + info = ft_safealloc(sizeof(t_insert_info)); info->min_cost = INT_MAX; info->min_delta_insert = INT_MAX; info->b_info.pos = 0; - while (info->b_info.pos < block_ids_b->size) { if (block_ids_b->elems[info->b_info.pos] == block_id) update_insert_info(cont, info); info->b_info.pos++; } - - - - - // if (DEBUG) - // { - // printf(YELLOW"insert_b found best elem to be stack_b[%d] == %d\n"RESET_COL, info->b_info.pos_best, cont->stack_b.elems[info->b_info.pos_best]); - // printf(YELLOW"corresponding insert value was stack_a[%d] == %d\n"RESET_COL, info->a_info.pos_best, cont->stack_a.elems[info->a_info.pos_best]); - // printf(YELLOW"info.a_info.val_best = %d \n"RESET_COL, info->a_info.val_best); - // printf(YELLOW"info.a_info.pos_best = %d \n"RESET_COL, info->a_info.pos_best); - // printf(YELLOW"info.a_info.revpos_best = %d \n"RESET_COL, info->a_info.revpos_best); - // printf(YELLOW"info.b_info.val_best = %d \n"RESET_COL, info->b_info.val_best); - // printf(YELLOW"info.b_info.pos_best = %d \n"RESET_COL, info->b_info.pos_best); - // printf(YELLOW"info.b_info.revpos_best = %d \n"RESET_COL, info->b_info.revpos_best); - // printf(YELLOW"info.a_info.dist0_best = %d \n"RESET_COL, info->a_info.dist0_best); - // printf(YELLOW"info.b_info.dist0_best = %d \n"RESET_COL, info->b_info.dist0_best); - // printf(YELLOW"info.min_cost = %d \n"RESET_COL, info->min_cost); - // printf(YELLOW"info.min_delta_insert = %d \n"RESET_COL, info->min_delta_insert); - // } - - if (cont->stack_b.size > 0) { - //Needs to update block_ids_b... insert_block_elem_b(cont, block_ids_b, info); - - // if (DEBUG) - // { - // printf(BLUE"last 5 moves: \n"RESET_COL); - // for (int i = 5; i && moves_b`uff->size > 5 - i; i--) - // print_move(cont->curr_moves.elems[cont->curr_moves.size - i]); - // } - // print_stacks(cont); - // print_single_stack(block_ids_b); - - if (DEBUG && !is_sorted(&cont->stack_a, cont->head_a.index)) - { - printf("fucked up right here\n"); - printf(BLUE"last 35 moves: \n"RESET_COL); - for (int i = 35; i && cont->curr_moves.size > 35 - i; i--) - print_move(cont->curr_moves.elems[cont->curr_moves.size - i]); - exit(1); - } insert_block_of_b_in_a(cont, block_ids_b, block_id); } - - //NEW free(info); info = NULL; return ; @@ -240,9 +167,8 @@ void insert_curr_block_id( t_deque *block_ids_b, t_block_info *info) { - // if the first elem of stack_a is a candidate for push while (cont->stack_a.elems[0] <= info->median_val && - has_smaller_than_median(&cont->stack_b, info->median_val, info->min_val) && + has_smaller_than_median(&cont->stack_b, info) && cont->stack_b.elems[0] > info->median_val && cont->stack_b.elems[0] <= info->max_val) { @@ -269,9 +195,10 @@ void rotate_to_block_id( pos_a = 0; while (block_ids_a->elems[pos_a] != info->curr_block_id) pos_a++; - if (has_smaller_than_median(&cont->stack_b, info->median_val, info->min_val)) + if (has_smaller_than_median(&cont->stack_b, info)) { - while (pos_a && cont->stack_b.elems[0] > info->median_val && cont->stack_b.elems[0] <= info->max_val) + while (pos_a && cont->stack_b.elems[0] > info->median_val + && cont->stack_b.elems[0] <= info->max_val) { do_rr(cont, &cont->curr_moves); @@ -319,7 +246,7 @@ void insert_block_set_ids( info.curr_block_id = curr_block_id_a; info.max_val = 0; info.min_val = cont->stack_a.max_elem; - info.median_val = calc_block_median(&cont->stack_a, block_ids_a, curr_block_id_a, &info.max_val, &info.min_val); + assign_block_median(&cont->stack_a, block_ids_a, &info); i = 0; while (i < block_ids_b->size) { diff --git a/src/insert_utils.c b/src/insert_utils.c index e6a2afd..03dd7d2 100644 --- a/src/insert_utils.c +++ b/src/insert_utils.c @@ -30,3 +30,53 @@ int get_insert_val(t_deque *stack, int curr_val) } return (get_insert_val(stack, curr_val + 1)); } + +void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id) +{ + t_block_info info; + + info.curr_block_id = curr_block_id; + info.max_val = 0; + info.min_val = cont->stack_a.max_elem; + assign_block_median(&cont->stack_a, block_ids, &info); + while (block_id_is_in_stack(block_ids, curr_block_id)) + { + if (block_ids->elems[0] == curr_block_id) + { + while (has_smaller_than_median(&cont->stack_b, &info) + && cont->stack_a.elems[0] <= info.median_val + && cont->stack_b.elems[0] > info.median_val + && cont->stack_b.elems[0] <= info.max_val) + do_rb(cont, &cont->curr_moves); + do_pb(cont, &cont->curr_moves); + block_ids->remove_front(block_ids); + } + else + rotate_block_split(cont, block_ids, &info); + } + while (cont->stack_b.elems[0] > info.median_val + && cont->stack_b.elems[0] <= info.max_val) + do_rb(cont, &cont->curr_moves); + return ; +} + +void insert_last_block(t_main_cont *cont, t_deque *moves_list) +{ + t_block_info info; + + info.max_val = cont->stack_a.max_elem; + info.min_val = cont->stack_a.min_elem; + info.median_val = (info.max_val - info.min_val) / 2; + while (cont->stack_a.size > 3) + { + do_pb(cont, &cont->curr_moves); + if (has_smaller_than_median(&cont->stack_b, &info) + && cont->stack_b.elems[0] > info.median_val + && cont->stack_b.elems[0] <= info.max_val) + do_rb(cont, moves_list); + } + if (!is_sorted(&cont->stack_a, cont->head_a.index)) + do_sa(cont, moves_list); + return ; + +} diff --git a/src/sort_big.c b/src/sort_big.c deleted file mode 100644 index 5a59442..0000000 --- a/src/sort_big.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "push_swap.h" - -bool block_id_is_in_stack(t_deque *block_ids, int id) -{ - int i; - - i = 0; - while (i < block_ids->size) - { - if(block_ids->elems[i] == id) - return (true); - i++; - } - return (false); -} - -int calc_block_median(t_deque *stack, t_deque *block_ids, int curr_block_id, int *max_val, int *min_val) -{ - int median_val; - int curr_pos; - - median_val = 0; - curr_pos = 0; - while (curr_pos < stack->size) - { - if (block_ids->elems[curr_pos] == curr_block_id) - { - if (stack->elems[curr_pos] < *min_val) - *min_val = stack->elems[curr_pos]; - else if (stack->elems[curr_pos] > *max_val) - *max_val = stack->elems[curr_pos]; - } - curr_pos++; - } - median_val = (*max_val - *min_val) / 2 + *min_val; - return (median_val); -} - -bool has_smaller_than_median(t_deque *stack, int median_val, int min_val) -{ - int curr_pos; - - curr_pos = 0; - while (curr_pos < stack->size) - { - if (stack->elems[curr_pos] >= min_val && stack->elems[curr_pos] <= median_val) - return (true); - curr_pos++; - } - return (false); -} - -void rotate_block_split(t_main_cont *cont, t_deque *block_ids, int curr_block_id, int max_val, int min_val, int median_val) -{ - int pos_a; - - pos_a = 0; - while (block_ids->elems[pos_a] != curr_block_id) - pos_a++; - if (has_smaller_than_median(&cont->stack_b, median_val, min_val)) - { - while (pos_a && cont->stack_b.elems[0] > median_val && cont->stack_b.elems[0] <= max_val) - { - do_rr(cont, &cont->curr_moves); - block_ids->add_last(block_ids, block_ids->elems[0]); - block_ids->remove_front(block_ids); - pos_a--; - } - } - while (pos_a) - { - do_ra(cont, &cont->curr_moves); - block_ids->add_last(block_ids, block_ids->elems[0]); - block_ids->remove_front(block_ids); - pos_a--; - } - return ; -} - -void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id) -{ - int median_val; - int max_val; - int min_val; - - max_val = 0; - min_val = cont->stack_a.max_elem; - median_val = calc_block_median(&cont->stack_a, block_ids, curr_block_id, &max_val, &min_val); - while (block_id_is_in_stack(block_ids, curr_block_id)) - { - if (block_ids->elems[0] == curr_block_id) - { - while (has_smaller_than_median(&cont->stack_b, median_val, min_val) && - cont->stack_a.elems[0] <= median_val && - cont->stack_b.elems[0] > median_val && cont->stack_b.elems[0] <= max_val) - do_rb(cont, &cont->curr_moves); - do_pb(cont, &cont->curr_moves); - block_ids->remove_front(block_ids); - } - else - rotate_block_split(cont, block_ids, curr_block_id, max_val, min_val, median_val); - } - while (cont->stack_b.elems[0] > median_val && cont->stack_b.elems[0] <= max_val) - do_rb(cont, &cont->curr_moves); - return ; -} - -void insert_last_block(t_main_cont *cont, t_deque *moves_list) -{ - int median_val; - int max_val; - int min_val; - - max_val = cont->stack_a.max_elem; - min_val = cont->stack_a.min_elem; - median_val = (max_val - min_val) / 2; - while (cont->stack_a.size > 3) - { - do_pb(cont, &cont->curr_moves); - if (has_smaller_than_median(&cont->stack_b, median_val, min_val) && cont->stack_b.elems[0] > median_val && cont->stack_b.elems[0] <= max_val) - do_rb(cont, moves_list); - } - if (!is_sorted(&cont->stack_a, cont->head_a.index)) - do_sa(cont, moves_list); - return ; - -} From 8fa41a82d1a8d765fa22e0ee93b79a3477a6275e Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:04:32 -0400 Subject: [PATCH 06/32] split_in_blocks.c, deque_operators.c --- include/push_swap.h | 4 ++-- src/deque_operators.c | 18 +++++++++++++++--- src/split_in_blocks.c | 21 +++++++++++++-------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/include/push_swap.h b/include/push_swap.h index 4c1e293..9ca87e5 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -121,6 +121,8 @@ void ignore_lis(t_main_cont *cont); // sort.c void sort(t_main_cont *cont); +void sort_small(t_main_cont *cont); +void sort_big(t_main_cont *cont); // cherrypick.c t_deque *get_ordered_vals(t_deque *stack); @@ -143,7 +145,6 @@ t_deque *get_leaving_vals_trimmed(t_deque *leaving_vals); // sort_small.c -void sort_small(t_main_cont *cont); void try_sort_small(t_main_cont *cont); bool try_swap(t_main_cont *cont); bool try_invert_4(t_main_cont *cont); @@ -182,7 +183,6 @@ bool is_in_stack(t_deque *stack, int val); // SORT BIG void rotate_block_split(t_main_cont *cont, t_deque *block_ids, t_block_info *info); bool block_id_is_in_stack(t_deque *block_ids, int id); -void sort_big(t_main_cont *cont); bool has_smaller_than_median(t_deque *stack, t_block_info *info); bool has_bigger_than_median(t_deque *stack, int median_val, int max_val); void assign_block_median(t_deque *stack, t_deque *block_ids, t_block_info *info); diff --git a/src/deque_operators.c b/src/deque_operators.c index e6e84d0..0edc0b4 100644 --- a/src/deque_operators.c +++ b/src/deque_operators.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deque_operators.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- reinit_list(dest); i = 0; while (i < src->size) @@ -46,7 +58,7 @@ void cat_deque(t_deque *src, t_deque *dest) int i; if (!src || !dest) - return ; + return ; i = 0; while (i < src->size) { @@ -61,7 +73,7 @@ void cat_deque_front(t_deque *src, t_deque *dest) int i; if (!src || !dest) - return ; + return ; i = src->size - 1; while (i >= 0) { diff --git a/src/split_in_blocks.c b/src/split_in_blocks.c index e71b33b..cb18dbd 100644 --- a/src/split_in_blocks.c +++ b/src/split_in_blocks.c @@ -1,7 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* split_in_blocks.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- curr_moves); rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); if (cont->curr_moves.size < cont->best_moves.size) @@ -37,21 +48,15 @@ void split_in_blocks(t_main_cont *cont) new_deque(&block_ids_a); new_deque(&block_ids_b); - nb_blocks = 2; while (nb_blocks <= 6) { split_in_n_blocks(cont, block_ids_a, block_ids_b, nb_blocks); nb_blocks++; } - - // Free block_ids_a block_ids_a->free_list(block_ids_a); free(block_ids_a); - - // Free block_ids_b block_ids_b->free_list(block_ids_b); free(block_ids_b); - return ; } From 3f6f8bd4a3a415b771184c0f9e7c55e35ca62950 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:05:47 -0400 Subject: [PATCH 07/32] Normed insert_utils.c --- src/insert_utils.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/insert_utils.c b/src/insert_utils.c index 03dd7d2..483bc77 100644 --- a/src/insert_utils.c +++ b/src/insert_utils.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* insert_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a, cont->head_a.index)) do_sa(cont, moves_list); return ; - } From c0cb894644491cfe72d22cfeb06ac250ac947bf3 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:07:01 -0400 Subject: [PATCH 08/32] sort_utils.c: OK! --- src/sort_utils.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sort_utils.c b/src/sort_utils.c index e8b73c2..cfcd353 100644 --- a/src/sort_utils.c +++ b/src/sort_utils.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a.size; - printf(YELLOW"rotate_to_pos0=======> pos = %d, revpos = %d\n", pos, revpos); - if (pos < cont->stack_a.size - pos) - printf("Choosing ra; %d < %d\n"RESET_COL, pos, -revpos); - else - printf("Choosing rra; %d >= %d\n"RESET_COL, pos, -revpos); - } if (pos < cont->stack_a.size - pos) while (pos-- > 0) do_ra(cont, curr_moves); From c1f8259a6aabbadaa9c4305ef6f7497b09dd599e Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:07:32 -0400 Subject: [PATCH 09/32] cleanup.c: OK! --- src/cleanup.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cleanup.c b/src/cleanup.c index d778f24..95682a6 100644 --- a/src/cleanup.c +++ b/src/cleanup.c @@ -1,10 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cleanup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a.free_list(&cont->stack_a); cont->stack_b.free_list(&cont->stack_b); - // cont->final_moves.free_list(&cont->final_moves); cont->curr_moves.free_list(&cont->curr_moves); cont->best_moves.free_list(&cont->best_moves); cont->best_moves.free_list(&cont->initial_stack); From 1e3c95d685997fa546c0122841643d2a62ef8c87 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:07:58 -0400 Subject: [PATCH 10/32] utils.c: OK! --- src/utils.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/utils.c b/src/utils.c index 4a31793..afe9e04 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- Date: Wed, 20 Apr 2022 22:08:35 -0400 Subject: [PATCH 11/32] rrx.c: OK! --- src/rrx.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rrx.c b/src/rrx.c index a5d91f8..cf26641 100644 --- a/src/rrx.c +++ b/src/rrx.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rrx.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a); if (curr_moves) @@ -22,7 +34,7 @@ void do_rra(t_main_cont *cont, t_deque *curr_moves) return ; } -void do_rrb(t_main_cont *cont, t_deque *curr_moves) +void do_rrb(t_main_cont *cont, t_deque *curr_moves) { rev_rotate(&cont->stack_b); if (curr_moves) From 8ed81f3b83e33e6c6878ddc63402fd46bbaba79a Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:30:46 -0400 Subject: [PATCH 12/32] Normed insert_blocks.c, insert_blocks_utils.c --- include/push_swap.h | 7 +- src/insert.c | 39 ++++--- src/insert_blocks.c | 260 ++++++++++++-------------------------------- 3 files changed, 95 insertions(+), 211 deletions(-) diff --git a/include/push_swap.h b/include/push_swap.h index 9ca87e5..975c056 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -169,9 +169,14 @@ void update_insert_info(t_main_cont *cont, t_insert_info *info); // insert_blocks.c void insert_block_set_ids(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, int curr_block_id_a); -void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_id); void insert_block_elem_b(t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info); +// insert_blocks_utils.c +void insert_curr_block_id(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, t_block_info *info) +void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_id); +void rotate_to_block_id(t_main_cont *cont,t_deque *block_ids_a,t_deque *block_ids_b,t_block_info *info); +void check_if_top_stack_b_is_smaller_than_median(t_main_cont *cont, t_deque *block_ids, t_block_info *info); + // sort_utils.c bool is_sorted(t_deque *stack, int pos_smallest); int get_pos_of_val(t_deque *stack, int val); diff --git a/src/insert.c b/src/insert.c index 83b4faf..352a88e 100644 --- a/src/insert.c +++ b/src/insert.c @@ -47,16 +47,18 @@ static void insert_same_sign( do_rr(cont, moves_buff); } } - while (info->min_cost-- > 0) + else { - if (++info->a_info.dist0_best > 0) - do_rrb(cont, moves_buff); - else if (++info->b_info.dist0_best > 0) - do_rra(cont, moves_buff); - else - do_rrr(cont, moves_buff); + while (info->min_cost-- > 0) + { + if (++info->a_info.dist0_best > 0) + do_rrb(cont, moves_buff); + else if (++info->b_info.dist0_best > 0) + do_rra(cont, moves_buff); + else + do_rrr(cont, moves_buff); + } } - do_pa(cont, moves_buff); } static void insert_same_direction( @@ -75,16 +77,18 @@ static void insert_same_direction( do_rr(cont, moves_buff); } } - while (info->min_cost-- > 0) + else { - if (++info->a_info.revpos_best > 0) - do_rrb(cont, moves_buff); - else if (++info->b_info.revpos_best > 0) - do_rra(cont, moves_buff); - else - do_rrr(cont, moves_buff); + while (info->min_cost-- > 0) + { + if (++info->a_info.revpos_best > 0) + do_rrb(cont, moves_buff); + else if (++info->b_info.revpos_best > 0) + do_rra(cont, moves_buff); + else + do_rrr(cont, moves_buff); + } } - do_pa(cont, moves_buff); } static void insert_indep_directions( @@ -102,8 +106,6 @@ static void insert_indep_directions( else while (info->b_info.dist0_best++ < 0) do_rrb(cont, moves_buff); - do_pa(cont, moves_buff); - } void insert_elem_b( @@ -122,6 +124,7 @@ void insert_elem_b( insert_same_direction(cont, moves_buff, info); else insert_indep_directions(cont, moves_buff, info); + do_pa(cont, moves_buff); return ; } diff --git a/src/insert_blocks.c b/src/insert_blocks.c index afdb354..a161583 100644 --- a/src/insert_blocks.c +++ b/src/insert_blocks.c @@ -1,65 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* insert_blocks.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- a_info.dist0_best > 0 || info->b_info.dist0_best > 0) + t_block_info info; + int i; + + info.curr_block_id = curr_block_id_a; + info.max_val = 0; + info.min_val = cont->stack_a.max_elem; + assign_block_median(&cont->stack_a, block_ids_a, &info); + i = 0; + while (i < block_ids_b->size) { - while (info->min_cost-- > 0) - { - if (--info->b_info.dist0_best < 0) - do_ra(cont, &cont->curr_moves); - else - { - if (--info->a_info.dist0_best < 0) - do_rb(cont, &cont->curr_moves); - else - do_rr(cont, &cont->curr_moves); - block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); - block_ids_b->remove_front(block_ids_b); - } - } + block_ids_b->elems[i] += 2; + i++; } - while (info->min_cost-- > 0) + while (block_id_is_in_stack(block_ids_a, curr_block_id_a)) { - if (++info->b_info.dist0_best > 0) - do_rra(cont, &cont->curr_moves); + if (block_ids_a->elems[0] == curr_block_id_a) + insert_curr_block_id(cont, block_ids_a, block_ids_b, &info); else - { - if (++info->a_info.dist0_best > 0) - do_rrb(cont, &cont->curr_moves); - else - do_rrr(cont, &cont->curr_moves); - block_ids_b->add_front(block_ids_b, block_ids_b->elems[block_ids_b->size - 1]); - block_ids_b->remove_last(block_ids_b); - } + rotate_to_block_id(cont, block_ids_a, block_ids_b, &info); } - do_pa(cont, &cont->curr_moves); - block_ids_b->remove_front(block_ids_b); + check_if_top_stack_b_is_smaller_than_median(cont, block_ids_b, &info); + return ; } - -void insert_same_direction( +void insert_block_rot( t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info) { - if (info->min_cost == info->a_info.pos_best || - info->min_cost == info->b_info.pos_best) + while (info->min_cost-- > 0) { - while (info->min_cost-- > 0) + if (--info->b_info.pos_best < 0) + do_ra(cont, &cont->curr_moves); + else { - if (--info->b_info.pos_best < 0) - do_ra(cont, &cont->curr_moves); + if (--info->a_info.pos_best < 0) + do_rb(cont, &cont->curr_moves); else - { - if (--info->a_info.pos_best < 0) - do_rb(cont, &cont->curr_moves); - else - do_rr(cont, &cont->curr_moves); - block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); - block_ids_b->remove_front(block_ids_b); - } + do_rr(cont, &cont->curr_moves); + block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); + block_ids_b->remove_front(block_ids_b); } } + return ; +} + +void insert_block_rev_rot( + t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info) +{ while (info->min_cost-- > 0) { if (++info->b_info.revpos_best > 0) @@ -70,15 +75,14 @@ void insert_same_direction( do_rrb(cont, &cont->curr_moves); else do_rrr(cont, &cont->curr_moves); - block_ids_b->add_front(block_ids_b, block_ids_b->elems[block_ids_b->size - 1]); + block_ids_b->add_front(block_ids_b, + block_ids_b->elems[block_ids_b->size - 1]); block_ids_b->remove_last(block_ids_b); } } - do_pa(cont, &cont->curr_moves); - block_ids_b->remove_front(block_ids_b); + return ; } - void insert_indep_directions( t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info) { @@ -102,164 +106,36 @@ void insert_indep_directions( while (info->b_info.dist0_best++ < 0) { do_rrb(cont, &cont->curr_moves); - block_ids_b->add_front(block_ids_b, block_ids_b->elems[block_ids_b->size - 1]); + block_ids_b->add_front(block_ids_b, + block_ids_b->elems[block_ids_b->size - 1]); block_ids_b->remove_last(block_ids_b); } } - do_pa(cont, &cont->curr_moves); - block_ids_b->remove_front(block_ids_b); } void insert_block_elem_b( t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info) { - t_stack_insert_info *a_info; - t_stack_insert_info *b_info; - if (cont->stack_b.size <= 0) return ; - a_info = &info->a_info; - b_info = &info->b_info; - // case for they both need to go in the same sense if (ft_same_sign(info->a_info.dist0_best, info->b_info.dist0_best)) - insert_same_sign(cont, block_ids_b, info); - // case where their respective best rotations are in opposite directions, - // but it's still better to move them in same direction - else if (get_cost_either_direction(info) < get_cost_indep_directions(info)) - insert_same_direction(cont, block_ids_b, info); - // case where they each do their own thing. that's okay too. - else - insert_indep_directions(cont, block_ids_b, info); - return ; -} - - -void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_id) -{ - t_insert_info *info; - - if (!block_id_is_in_stack(block_ids_b, block_id)) - return ; - - info = ft_safealloc(sizeof(t_insert_info)); - info->min_cost = INT_MAX; - info->min_delta_insert = INT_MAX; - info->b_info.pos = 0; - while (info->b_info.pos < block_ids_b->size) - { - if (block_ids_b->elems[info->b_info.pos] == block_id) - update_insert_info(cont, info); - info->b_info.pos++; - } - if (cont->stack_b.size > 0) { - insert_block_elem_b(cont, block_ids_b, info); - insert_block_of_b_in_a(cont, block_ids_b, block_id); - } - free(info); - info = NULL; - return ; -} - -void insert_curr_block_id( - t_main_cont *cont, - t_deque *block_ids_a, - t_deque *block_ids_b, - t_block_info *info) -{ - while (cont->stack_a.elems[0] <= info->median_val && - has_smaller_than_median(&cont->stack_b, info) && - cont->stack_b.elems[0] > info->median_val && - cont->stack_b.elems[0] <= info->max_val) - { - do_rb(cont, &cont->curr_moves); - block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); - block_ids_b->remove_front(block_ids_b); - } - do_pb(cont, &cont->curr_moves); - if (cont->stack_b.elems[0] >= info->median_val) - block_ids_b->add_front(block_ids_b, 1); - else - block_ids_b->add_front(block_ids_b, 0); - block_ids_a->remove_front(block_ids_a); -} - -void rotate_to_block_id( - t_main_cont *cont, - t_deque *block_ids_a, - t_deque *block_ids_b, - t_block_info *info) -{ - int pos_a; - - pos_a = 0; - while (block_ids_a->elems[pos_a] != info->curr_block_id) - pos_a++; - if (has_smaller_than_median(&cont->stack_b, info)) - { - while (pos_a && cont->stack_b.elems[0] > info->median_val - && cont->stack_b.elems[0] <= info->max_val) - { - do_rr(cont, &cont->curr_moves); - - block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); - block_ids_b->remove_front(block_ids_b); - - block_ids_a->add_last(block_ids_a, block_ids_a->elems[0]); - block_ids_a->remove_front(block_ids_a); - pos_a--; - } - } - while (pos_a) - { - do_ra(cont, &cont->curr_moves); - - block_ids_a->add_last(block_ids_a, block_ids_a->elems[0]); - block_ids_a->remove_front(block_ids_a); - pos_a--; - } - return ; -} - -void check_if_top_stack_b_is_smaller_than_median( - t_main_cont *cont, t_deque *block_ids, t_block_info *info) -{ - while (cont->stack_b.elems[0] > info->median_val - && cont->stack_b.elems[0] <= info->max_val) - { - do_rb(cont, &cont->curr_moves); - block_ids->add_last(block_ids, block_ids->elems[0]); - block_ids->remove_front(block_ids); - } - return ; -} - -void insert_block_set_ids( - t_main_cont *cont, - t_deque *block_ids_a, - t_deque *block_ids_b, - int curr_block_id_a) -{ - t_block_info info; - int i; - - info.curr_block_id = curr_block_id_a; - info.max_val = 0; - info.min_val = cont->stack_a.max_elem; - assign_block_median(&cont->stack_a, block_ids_a, &info); - i = 0; - while (i < block_ids_b->size) - { - block_ids_b->elems[i] += 2; - i++; + if (info->a_info.dist0_best > 0 || info->b_info.dist0_best > 0) + insert_block_rot(cont, block_ids_b, info); + else + insert_block_rev_rot(cont, block_ids_b, info); } - while (block_id_is_in_stack(block_ids_a, curr_block_id_a)) + else if (get_cost_either_direction(info) < get_cost_indep_directions(info)) { - if (block_ids_a->elems[0] == curr_block_id_a) - insert_curr_block_id(cont, block_ids_a, block_ids_b, &info); + if (info->min_cost == info->a_info.pos_best + || info->min_cost == info->b_info.pos_best) + insert_block_rot(cont, block_ids_b, info); else - rotate_to_block_id(cont, block_ids_a, block_ids_b, &info); + insert_block_rev_rot(cont, block_ids_b, info); } - check_if_top_stack_b_is_smaller_than_median(cont, block_ids_b, &info); + else + insert_indep_directions(cont, block_ids_b, info); + do_pa(cont, &cont->curr_moves); + block_ids_b->remove_front(block_ids_b); return ; } From cad7b2e2c058da739b24c493fb52bd65470ae96f Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:32:42 -0400 Subject: [PATCH 13/32] Normed deque_utils.c --- Makefile | 1 + include/push_swap.h | 2 +- src/partition_stack.c | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0c4cd54..3871396 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,7 @@ CFILES = algorithms.c \ init.c \ insert.c \ insert_blocks.c \ + insert_blocks_utils.c \ insert_utils.c \ iterators.c \ parse.c \ diff --git a/include/push_swap.h b/include/push_swap.h index 975c056..51073ce 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -172,7 +172,7 @@ void insert_block_set_ids(t_main_cont *cont, t_deque *block_ids_a, t_deque *bloc void insert_block_elem_b(t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info); // insert_blocks_utils.c -void insert_curr_block_id(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, t_block_info *info) +void insert_curr_block_id(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, t_block_info *info); void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_id); void rotate_to_block_id(t_main_cont *cont,t_deque *block_ids_a,t_deque *block_ids_b,t_block_info *info); void check_if_top_stack_b_is_smaller_than_median(t_main_cont *cont, t_deque *block_ids, t_block_info *info); diff --git a/src/partition_stack.c b/src/partition_stack.c index 5800887..cabe852 100644 --- a/src/partition_stack.c +++ b/src/partition_stack.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* partition_stack.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- Date: Wed, 20 Apr 2022 22:33:42 -0400 Subject: [PATCH 14/32] Added new files --- src/block_utils.c | 93 ++++++++++++++++++++++++++++++++ src/deque_modify.c | 83 +++++++++++++++++++++++++++++ src/deque_utils.c | 102 +++++++++++++++++++++++++++++++++++ src/insert_blocks_utils.c | 109 ++++++++++++++++++++++++++++++++++++++ src/iterators.c | 16 ++++-- 5 files changed, 399 insertions(+), 4 deletions(-) create mode 100644 src/block_utils.c create mode 100644 src/deque_modify.c create mode 100644 src/deque_utils.c create mode 100644 src/insert_blocks_utils.c diff --git a/src/block_utils.c b/src/block_utils.c new file mode 100644 index 0000000..43315b7 --- /dev/null +++ b/src/block_utils.c @@ -0,0 +1,93 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* block_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) + { + if (block_ids->elems[i] == id) + return (true); + i++; + } + return (false); +} + +void assign_block_median( + t_deque *stack, t_deque *block_ids, t_block_info *info) +{ + int curr_pos; + + info->median_val = 0; + curr_pos = 0; + while (curr_pos < stack->size) + { + if (block_ids->elems[curr_pos] == info->curr_block_id) + { + if (stack->elems[curr_pos] < info->min_val) + info->min_val = stack->elems[curr_pos]; + else if (stack->elems[curr_pos] > info->max_val) + info->max_val = stack->elems[curr_pos]; + } + curr_pos++; + } + info->median_val = (info->max_val - info->min_val) / 2 + info->min_val; + return ; +} + +bool has_smaller_than_median(t_deque *stack, t_block_info *info) +{ + int curr_pos; + + curr_pos = 0; + while (curr_pos < stack->size) + { + if (stack->elems[curr_pos] >= info->min_val + && stack->elems[curr_pos] <= info->median_val) + return (true); + curr_pos++; + } + return (false); +} + +void rotate_block_split( + t_main_cont *cont, t_deque *block_ids, t_block_info *info) +{ + int pos_a; + + pos_a = 0; + while (block_ids->elems[pos_a] != info->curr_block_id) + pos_a++; + if (has_smaller_than_median(&cont->stack_b, info)) + { + while (pos_a && cont->stack_b.elems[0] > info->median_val + && cont->stack_b.elems[0] <= info->max_val) + { + do_rr(cont, &cont->curr_moves); + block_ids->add_last(block_ids, block_ids->elems[0]); + block_ids->remove_front(block_ids); + pos_a--; + } + } + while (pos_a) + { + do_ra(cont, &cont->curr_moves); + block_ids->add_last(block_ids, block_ids->elems[0]); + block_ids->remove_front(block_ids); + pos_a--; + } + return ; +} diff --git a/src/deque_modify.c b/src/deque_modify.c new file mode 100644 index 0000000..242d247 --- /dev/null +++ b/src/deque_modify.c @@ -0,0 +1,83 @@ +#include "deques.h" + +bool deque_add_front(t_deque *deque, int new_elem) +{ + bool status; + + if (deque->capacity_front == 0) + { + status = deque_resize_front(deque, deque->capacity_total); + if (status == FAILURE) + return (status); + } + deque->elems -= 1; + deque->elems[0] = new_elem; + deque->size += 1; + deque->capacity_front -= 1; + deque->capacity_end += 1; + if (new_elem > deque->max_elem) + deque->max_elem = new_elem; + if (new_elem < deque->min_elem) + deque->min_elem = new_elem; + status = SUCCESS; + return (status); +} + +bool deque_add_last(t_deque *deque, int new_elem) +{ + bool status; + + if (deque->size == deque->capacity_end) + { + status = deque_resize_end(deque, deque->capacity_total * 2); + if (status == FAILURE) + return (status); + } + deque->elems[deque->size] = new_elem; + deque->size += 1; + if (new_elem > deque->max_elem) + deque->max_elem = new_elem; + if (new_elem < deque->min_elem) + deque->min_elem = new_elem; + status = SUCCESS; + return (status); +} + +//Need to add resize smaller when under a certain size +void deque_remove_front(t_deque *deque) +{ + int elem_to_be_removed; + + elem_to_be_removed = deque->elems[0]; + deque->elems[0] = 0; + deque->elems += 1; + deque->capacity_front += 1; + deque->capacity_end -= 1; + deque->size -= 1; + if (elem_to_be_removed == deque->min_elem) + deque->min_elem = deque->get_elem_min(deque); + if (elem_to_be_removed == deque->max_elem) + deque->max_elem = deque->get_elem_max(deque); + return ; +} + +//Need to add resize smaller when under a certain size +void deque_remove_last(t_deque *deque) +{ + int elem_to_be_removed; + + elem_to_be_removed = deque->elems[deque->size - 1]; + deque->elems[deque->size - 1] = 0; + deque->size -= 1; + if (elem_to_be_removed == deque->min_elem) + deque->min_elem = deque->get_elem_min(deque); + if (elem_to_be_removed == deque->max_elem) + deque->max_elem = deque->get_elem_max(deque); + return ; +} + +void deque_set_elem(t_deque *deque, int pos, int new_value) +{ + deque->elems[pos] = new_value; + return ; +} diff --git a/src/deque_utils.c b/src/deque_utils.c new file mode 100644 index 0000000..30e0534 --- /dev/null +++ b/src/deque_utils.c @@ -0,0 +1,102 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deque_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- malloced_space); + deque->malloced_space = NULL; + return ; +} + +bool deque_resize_front(t_deque *deque, int new_size) +{ + int *temp; + int total_new_size; + int pos_in_deque; + + total_new_size = new_size + deque->capacity_end; + temp = malloc(total_new_size * sizeof(int)); + if (!temp) + return (FAILURE); + temp += new_size; + pos_in_deque = 0; + while (pos_in_deque < deque->size) + { + temp[pos_in_deque] = deque->elems[pos_in_deque]; + pos_in_deque++; + } + free(deque->malloced_space); + deque->malloced_space = temp - new_size; + deque->elems = temp; + deque->capacity_front = new_size; + deque->capacity_total = total_new_size; + return (SUCCESS); +} + +bool deque_resize_end(t_deque *deque, int new_size) +{ + int *temp; + int total_new_size; + int pos_in_deque; + + total_new_size = new_size + deque->capacity_front; + temp = malloc(total_new_size * sizeof(int)); + if (!temp) + return (FAILURE); + temp += deque->capacity_front; + pos_in_deque = 0; + while (pos_in_deque < deque->size) + { + temp[pos_in_deque] = deque->elems[pos_in_deque]; + pos_in_deque++; + } + free(deque->malloced_space); + deque->malloced_space = temp - deque->capacity_front; + deque->elems = temp; + deque->capacity_end = new_size; + deque->capacity_total = total_new_size; + return (SUCCESS); +} + +int deque_get_elem_max(t_deque *deque) +{ + int pos_in_stack; + int biggest_value; + + biggest_value = INT_MIN; + pos_in_stack = 0; + while (pos_in_stack < deque->size) + { + if (deque->elems[pos_in_stack] > biggest_value) + biggest_value = deque->elems[pos_in_stack]; + pos_in_stack++; + } + return (biggest_value); +} + +int deque_get_elem_min(t_deque *deque) +{ + int pos_in_stack; + int smallest_value; + + smallest_value = INT_MAX; + pos_in_stack = 0; + while (pos_in_stack < deque->size) + { + if (deque->elems[pos_in_stack] < smallest_value) + smallest_value = deque->elems[pos_in_stack]; + pos_in_stack++; + } + return (smallest_value); +} diff --git a/src/insert_blocks_utils.c b/src/insert_blocks_utils.c new file mode 100644 index 0000000..e891017 --- /dev/null +++ b/src/insert_blocks_utils.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* insert_blocks_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- elems[pos_a] != info->curr_block_id) + pos_a++; + if (has_smaller_than_median(&cont->stack_b, info)) + { + while (pos_a && cont->stack_b.elems[0] > info->median_val + && cont->stack_b.elems[0] <= info->max_val) + { + do_rr(cont, &cont->curr_moves); + block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); + block_ids_b->remove_front(block_ids_b); + block_ids_a->add_last(block_ids_a, block_ids_a->elems[0]); + block_ids_a->remove_front(block_ids_a); + pos_a--; + } + } + while (pos_a) + { + do_ra(cont, &cont->curr_moves); + block_ids_a->add_last(block_ids_a, block_ids_a->elems[0]); + block_ids_a->remove_front(block_ids_a); + pos_a--; + } +} + +void check_if_top_stack_b_is_smaller_than_median( + t_main_cont *cont, t_deque *block_ids, t_block_info *info) +{ + while (cont->stack_b.elems[0] > info->median_val + && cont->stack_b.elems[0] <= info->max_val) + { + do_rb(cont, &cont->curr_moves); + block_ids->add_last(block_ids, block_ids->elems[0]); + block_ids->remove_front(block_ids); + } + return ; +} + +void insert_block_of_b_in_a( + t_main_cont *cont, t_deque *block_ids_b, int block_id) +{ + t_insert_info *info; + + if (!block_id_is_in_stack(block_ids_b, block_id)) + return ; + info = ft_safealloc(sizeof(t_insert_info)); + info->min_cost = INT_MAX; + info->min_delta_insert = INT_MAX; + info->b_info.pos = 0; + while (info->b_info.pos < block_ids_b->size) + { + if (block_ids_b->elems[info->b_info.pos] == block_id) + update_insert_info(cont, info); + info->b_info.pos++; + } + if (cont->stack_b.size > 0) + { + insert_block_elem_b(cont, block_ids_b, info); + insert_block_of_b_in_a(cont, block_ids_b, block_id); + } + free(info); + info = NULL; + return ; +} + +void insert_curr_block_id( + t_main_cont *cont, + t_deque *block_ids_a, + t_deque *block_ids_b, + t_block_info *info) +{ + while (cont->stack_a.elems[0] <= info->median_val + && has_smaller_than_median(&cont->stack_b, info) + && cont->stack_b.elems[0] > info->median_val + && cont->stack_b.elems[0] <= info->max_val) + { + do_rb(cont, &cont->curr_moves); + block_ids_b->add_last(block_ids_b, block_ids_b->elems[0]); + block_ids_b->remove_front(block_ids_b); + } + do_pb(cont, &cont->curr_moves); + if (cont->stack_b.elems[0] >= info->median_val) + block_ids_b->add_front(block_ids_b, 1); + else + block_ids_b->add_front(block_ids_b, 0); + block_ids_a->remove_front(block_ids_a); +} diff --git a/src/iterators.c b/src/iterators.c index 800dbac..023141a 100644 --- a/src/iterators.c +++ b/src/iterators.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* iterators.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- head = head; iterator->max_size = size; iterator->is_reverse = is_reverse; - //Will be incremented in the first loop to set at 0 once iterate starts iterator->nb_loops = -1; iterator->prev_index = -1; return ; @@ -24,7 +35,6 @@ void iterate(t_iterator *iterator) int incrementer; iterator->prev_index = iterator->index; - //-1 if direction == 1, +1 if direction == 0 incrementer = iterator->is_reverse * -1 + !iterator->is_reverse * 1; iterator->index += incrementer; if (incrementer == 1 && iterator->index > iterator->max_size - 1) @@ -45,12 +55,10 @@ void iterate_once(t_iterator *iterator, bool is_reverse) bool iterate_n_loops(t_iterator *iterator, int n) { int incrementer; - // static bool did_one_loop; if (iterator->index == iterator->head) iterator->nb_loops += 1; iterator->prev_index = iterator->index; - //-1 if direction == 1, +1 if direction == 0 incrementer = iterator->is_reverse * -1 + !iterator->is_reverse * 1; iterator->index += incrementer; if (incrementer == 1 && iterator->index > iterator->max_size - 1) From 07ebaffe6e00d1fcca2631e6996ad752de98cf9a Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Wed, 20 Apr 2022 22:58:35 -0400 Subject: [PATCH 15/32] Normed init.c: OK! partition_leaving_vals.c: OK! sort.c: OK! --- Makefile | 3 +- include/push_swap.h | 9 +++ src/init.c | 17 +++-- src/partition_leaving_vals.c | 124 ++++++++++++++++++++++------------- src/sort.c | 16 +++-- 5 files changed, 114 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index 3871396..9d0b3d4 100644 --- a/Makefile +++ b/Makefile @@ -12,8 +12,7 @@ RED = \033[0;31m ON_RED = \033[41m RESET_COL = \033[0m -CFILES = algorithms.c \ - block_utils.c \ +CFILES = block_utils.c \ calc_insert_cost.c \ cherrypick.c \ cherrypick_utils.c \ diff --git a/include/push_swap.h b/include/push_swap.h index 51073ce..0e9957d 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -46,6 +46,15 @@ //END OF REMOVE //TYPEDEFS +typedef struct s_partition_info +{ + int block_len; + int curr_block_id; + int curr_block_min; + int offset; + int nb_blocks; +} t_partition_info; + typedef struct s_block_info { int curr_block_id; diff --git a/src/init.c b/src/init.c index 289e5a7..f628ee1 100644 --- a/src/init.c +++ b/src/init.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a.add_last(&cont->stack_a, ft_atoi(args[i]))) exit_on_err("deque_add_last done fucked up\n"); - normalize_stack_values(&cont->stack_a); copy_deque(&cont->stack_a, &cont->initial_stack); - set_iterator(&cont->head_a, get_pos_smallest_val(&cont->stack_a), - cont->stack_a.size, 0); + cont->stack_a.size, 0); set_iterator(&cont->head_b, 0, 0, 1); init_reverse_moves_array(cont->reverse_fcts); cont->min_nb_moves = INT_MAX; @@ -72,5 +82,4 @@ void normalize_stack_values(t_deque *stack) i++; } free(normalized_stack); - return ; } diff --git a/src/partition_leaving_vals.c b/src/partition_leaving_vals.c index a9e5de3..a756c04 100644 --- a/src/partition_leaving_vals.c +++ b/src/partition_leaving_vals.c @@ -1,5 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* partition_leaving_vals.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) + { + if (staying_vals->elems[i] == -1) + block_ids->add_last(block_ids, -1); + else if (staying_vals->elems[i] > cutoff) + block_ids->add_last(block_ids, 1); + else + block_ids->add_last(block_ids, 0); + i++; + } + return ; +} + t_deque *get_leaving_vals_trimmed(t_deque *leaving_vals) { t_deque *trimmed_vals; @@ -27,67 +59,69 @@ t_deque *get_leaving_vals_trimmed(t_deque *leaving_vals) return (trimmed_vals); } -void partition_leaving_vals_n_blocks(t_deque *leaving_vals, t_deque *block_ids, int nb_blocks) +void assign_first_partition( + t_deque *leaving_vals, + t_deque *block_ids, + t_deque *trimmed_vals, + t_partition_info *info) { - t_deque *trimmed_vals; - int block_len; - int curr_block_id; - int curr_block_min; - int offset; - int i; - - trimmed_vals = get_leaving_vals_trimmed(leaving_vals); - offset = trimmed_vals->size % nb_blocks; - deque_reinit_list(block_ids); - block_len = trimmed_vals->size / nb_blocks + ((offset-- > 0) * 1); - curr_block_id = 0; - curr_block_min = 0; + int i; + i = 0; while (i < leaving_vals->size) { if (leaving_vals->elems[i] >= trimmed_vals->elems[0] && \ - leaving_vals->elems[i] <= trimmed_vals->elems[block_len - 1]) - block_ids->add_last(block_ids, curr_block_id); + leaving_vals->elems[i] <= trimmed_vals->elems[info->block_len - 1]) + block_ids->add_last(block_ids, info->curr_block_id); else block_ids->add_last(block_ids, leaving_vals->elems[i]); i++; } - while (++curr_block_id < nb_blocks) - { - curr_block_min += block_len; - block_len = trimmed_vals->size / nb_blocks + ((offset-- > 0) * 1); - i = 0; - while (i < leaving_vals->size) - { - if (leaving_vals->elems[i] >= trimmed_vals->elems[curr_block_min] && \ - leaving_vals->elems[i] <= trimmed_vals->elems[curr_block_min + block_len - 1]) - block_ids->add_last(block_ids, curr_block_id); - else - block_ids->add_last(block_ids, block_ids->elems[0]); - block_ids->remove_front(block_ids); - i++; - } - } - trimmed_vals->free_list(trimmed_vals); - free (trimmed_vals); - return ; } -void partition_leaving_vals_cutoff(t_deque *staying_vals, t_deque *block_ids, int cutoff) +void assign_partitions( + t_deque *leaving_vals, + t_deque *block_ids, + t_deque *trimmed_vals, + t_partition_info *info) { - int i; + int i; - deque_reinit_list(block_ids); i = 0; - while (i < staying_vals->size) + info->curr_block_min += info->block_len; + info->block_len = trimmed_vals->size / info->nb_blocks; + info->block_len += ((info->offset-- > 0) * 1); + while (i < leaving_vals->size) { - if (staying_vals->elems[i] == -1) - block_ids->add_last(block_ids, -1); - else if (staying_vals->elems[i] > cutoff) - block_ids->add_last(block_ids, 1); - else - block_ids->add_last(block_ids, 0); + if (leaving_vals->elems[i] >= trimmed_vals->elems[info->curr_block_min] + && leaving_vals->elems[i] + <= trimmed_vals->elems[info->curr_block_min + info->block_len - 1]) + block_ids->add_last(block_ids, info->curr_block_id); + else + block_ids->add_last(block_ids, block_ids->elems[0]); + block_ids->remove_front(block_ids); i++; } +} + +void partition_leaving_vals_n_blocks( + t_deque *leaving_vals, t_deque *block_ids, int nb_blocks) +{ + t_deque *trimmed_vals; + t_partition_info info; + + trimmed_vals = get_leaving_vals_trimmed(leaving_vals); + info.offset = trimmed_vals->size % nb_blocks; + deque_reinit_list(block_ids); + info.block_len = trimmed_vals->size / nb_blocks; + info.block_len += ((info.offset-- > 0) * 1); + info.curr_block_id = 0; + info.curr_block_min = 0; + info.nb_blocks = nb_blocks; + assign_first_partition(leaving_vals, block_ids, trimmed_vals, &info); + while (++info.curr_block_id < nb_blocks) + assign_partitions(leaving_vals, block_ids, trimmed_vals, &info); + trimmed_vals->free_list(trimmed_vals); + free (trimmed_vals); return ; } diff --git a/src/sort.c b/src/sort.c index 6f7c8e5..41866a3 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- should do invert_4 \ No newline at end of file From ef2974aa860d8e9ceb9634c997496817ff923656 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Thu, 21 Apr 2022 01:30:34 -0400 Subject: [PATCH 16/32] Started working on bonus --- Makefile | 49 ++++++++++--- include/moves.h | 28 +++----- include/push_swap.h | 66 +++++++++--------- include/push_swap_bonus.h | 49 +++++++++++++ src/cherrypick_utils.c | 13 ++++ src/delta_insert.c | 55 +++++++++++++++ src/deque_modify.c | 14 +++- src/ignore_LIS.c | 126 ++++++++++++---------------------- src/ignore_lis_utils.c | 88 ++++++++++++++++++++++++ src/init.c | 24 +++---- src/insert.c | 74 +++++--------------- src/parse.c | 4 +- src/parse_bonus.c | 100 +++++++++++++++++++++++++++ src/print_utils.c | 125 ++++++++------------------------- src/push_swap.c | 6 +- src/px.c | 2 +- src/px_bonus.c | 25 +++++++ src/rrx.c | 2 +- src/rrx_bonus.c | 32 +++++++++ src/rx.c | 8 +-- src/rx_bonus.c | 32 +++++++++ src/sort.c | 2 +- src/{try_x.c => sort_small.c} | 15 +++- src/split_in_two.c | 33 ++++----- src/split_in_two_utils.c | 30 ++++++++ src/sx.c | 26 ++++--- src/sx_bonus.c | 32 +++++++++ src/undo_moves.c | 24 +++---- src/utils.c | 4 +- 29 files changed, 723 insertions(+), 365 deletions(-) create mode 100644 include/push_swap_bonus.h create mode 100644 src/delta_insert.c create mode 100644 src/ignore_lis_utils.c create mode 100644 src/parse_bonus.c create mode 100644 src/px_bonus.c create mode 100644 src/rrx_bonus.c create mode 100644 src/rx_bonus.c rename src/{try_x.c => sort_small.c} (71%) create mode 100644 src/split_in_two_utils.c create mode 100644 src/sx_bonus.c diff --git a/Makefile b/Makefile index 9d0b3d4..1251e9f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ NAME = push_swap +NAME_BONUS = checker_bonus + # FOR TESTING PURPOSES RUN_ARGS = 37 15 27 4 6 33 12 19 31 3 2 13 49 42 22 16 39 10 24 8 41 5 1 28 7 40 29 47 21 35 50 48 38 45 34 36 44 20 32 17 9 23 25 11 26 14 46 43 30 18 @@ -17,12 +19,14 @@ CFILES = block_utils.c \ cherrypick.c \ cherrypick_utils.c \ cleanup.c \ + delta_insert.c \ deques.c \ deque_modify.c \ deque_operators.c \ deque_utils.c \ errors.c \ - ignore_LIS.c \ + ignore_lis.c \ + ignore_lis_utils.c \ init.c \ insert.c \ insert_blocks.c \ @@ -39,13 +43,32 @@ CFILES = block_utils.c \ rx.c \ sort.c \ sort_utils.c \ + sort_small.c \ split_in_blocks.c \ split_in_two.c \ + split_in_two_utils.c \ sx.c \ - try_x.c \ undo_moves.c \ utils.c +CFILES_BONUS = checker_bonus.c \ + deques.c \ + deque_modify.c \ + deque_operators.c \ + errors.c \ + init.c \ + px.c \ + px_bonus.c \ + parse_bonus.c \ + rx.c \ + rrx.c \ + sx.c \ + rx_bonus.c \ + rrx_bonus.c \ + sx_bonus.c \ + undo_moves.c \ + utils.c + HFILES = push_swap.h \ deques.h @@ -53,8 +76,9 @@ SRC_DIR = src SRCS = $(addprefix $(SRC_DIR)/, $(CFILES)) -OBJ_DIR = obj -OBJS = $(addprefix $(OBJ_DIR)/, $(CFILES:.c=.o)) +OBJ_DIR = obj +OBJS = $(addprefix $(OBJ_DIR)/, $(CFILES:.c=.o)) +OBJS_BONUS = $(addprefix $(OBJ_DIR)/, $(CFILES_BONUS:.c=.o)) INCL = include INCLFLAGS = -I$(INCL) @@ -89,6 +113,12 @@ COMPILE_EXE_OUT = $$($(COMPILE_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\0 COMPILE_C = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< COMPILE_C_OUT = $$($(COMPILE_C) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') +COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(OBJS) -o $(NAME_BONUS) +COMPILE_EXE_BONUS_OUT = $$($(COMPILE_EXE_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') + +COMPILE_C_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< +COMPILE_C_BONUS_OUT = $$($(COMPILE_C_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') + $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR) @printf "$(CYAN)%-30s-->%30s $(RESET_COL)$(COMPILE_C_OUT)\n" $^ $@ @@ -119,6 +149,9 @@ all: $(NAME) $(NAME): libft pretty_print $(OBJS) @echo -e "\n$(CYAN)>>>>>>>> Compiling $(NAME) ...$(RESET_COL)$(COMPILE_EXE_OUT)" +$(NAME_BONUS): libft $(OBJS_BONUS) + @echo -e "\n$(CYAN)>>>>>>>> Compiling $(NAME_BONUS) ...$(RESET_COL)$(COMPILE_EXE_BONUS_OUT)" + silent_libft: @echo -e "---------------------- libft.a ----------------------\n" @echo -e "$(CYAN)>>>>>>>> Archiving libft.a ...$(RESET_COL)" @@ -154,10 +187,10 @@ fclean: clean clean_libft clean_debug re: fclean all -test5: all - gcc -g push_swap_tester.c libft/libft.a && ./a.out 5; +pretty_print_bonus: + @echo -e "$(RED)\n------------------- $(NAME_BONUS) -------------------$(RESET_COL)\n" -bonus: all +bonus: $(NAME_BONUS) run: all ./$(NAME) $(RUN_ARGS) @@ -172,4 +205,4 @@ debug: all pretty_print_debug $(DBG_OBJS) @echo -e "\n$(ON_RED)>>>>>>>> Compiling $(DBG_EXE) ...$(RESET_COL)$(COMPILE_DBG_EXE_OUT)" ./$(DBG_EXE) $(RUN_ARGS) -.PHONY: all clean clean_libft fclean re bonus libft silent_libft pretty_print pretty_print_debug run debug test5 +.PHONY: all clean clean_libft fclean re bonus libft silent_libft pretty_print pretty_print_debug pretty_print_bonus run debug diff --git a/include/moves.h b/include/moves.h index d3b6698..23c3371 100644 --- a/include/moves.h +++ b/include/moves.h @@ -25,17 +25,17 @@ typedef enum e_moves typedef enum e_moves_to_indices { - REV_SA = 0, - REV_SB = 1, - REV_SS = 2, - REV_RA = 3, - REV_RB = 4, - REV_RR = 5, - REV_RRA = 6, - REV_RRB = 7, - REV_RRR = 8, - REV_PA = 9, - REV_PB = 10 + SA_INDEX = 0, + SB_INDEX = 1, + SS_INDEX = 2, + RA_INDEX = 3, + RB_INDEX = 4, + RR_INDEX = 5, + RRA_INDEX = 6, + RRB_INDEX = 7, + RRR_INDEX = 8, + PA_INDEX = 9, + PB_INDEX = 10 } t_moves_to_indices; //MOVES @@ -55,12 +55,6 @@ void push(t_deque *stack_src, t_deque *stack_dest); void do_pa(t_main_cont *cont, t_deque *curr_moves); void do_pb(t_main_cont *cont, t_deque *curr_moves); -// stacks info tracking -static inline void rotate_update_iterators(t_iterator *iterator); -static inline void rev_rotate_update_iterators(t_iterator *iterator); -static inline void swap_update_iterator(t_iterator *iterator); -static inline void push_update_iterators(t_main_cont *cont); - // Moves helper functions int convert_move_to_index(int move); void undo_moves(t_main_cont *cont, t_deque *curr_moves); diff --git a/include/push_swap.h b/include/push_swap.h index 0e9957d..9535f4c 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -104,7 +104,7 @@ typedef struct s_main_cont //PARSING // parse.c -void parse(int argc, char *argv[], t_main_cont *cont); +void parse(t_main_cont *cont, int argc, char *argv[]); // init.c void init(t_main_cont *cont, char **args); @@ -112,26 +112,33 @@ void normalize_stack_values(t_deque *stack); void init_reverse_moves_array(void (**array)(t_main_cont *, t_deque *)); //SORTING -// algorithms -void run_algorithms(t_main_cont *cont); +// sort.c +void sort(t_main_cont *cont); +void sort_small(t_main_cont *cont); +void sort_big(t_main_cont *cont); -// split_in_blocks +// split_in_blocks.c void split_in_blocks(t_main_cont *cont); +void split_in_n_blocks(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, int n); // split_in_two.c -int max_elem_leaving(t_main_cont *cont, t_deque *leaving_vals); void split_in_two(t_main_cont *cont); +// split_in_two_utils.c +int max_elem_leaving(t_main_cont *cont, t_deque *leaving_vals); +void split_in_two_mult_cutoffs(t_main_cont *cont, t_deque *block_ids); + // ignore_LIS.c void try_cutoff_n(t_main_cont *cont, t_deque *block_ids, int n, int cutoff); void try_n_divisions(t_main_cont *cont, t_deque *block_ids, int n); void try_n_divisions_closest(t_main_cont *cont, t_deque *block_ids, int n); void ignore_lis(t_main_cont *cont); -// sort.c -void sort(t_main_cont *cont); -void sort_small(t_main_cont *cont); -void sort_big(t_main_cont *cont); +// ignore_lis_utils.c +void try_cutoff_n(t_main_cont *cont, t_deque *block_ids, int n, int cutoff); +void try_n_divisions(t_main_cont *cont, t_deque *block_ids, int n); +void try_n_divisions_closest(t_main_cont *cont, t_deque *block_ids, int n); +void try_n_divisions_smallest(t_main_cont *cont, t_deque *block_ids, int n); // cherrypick.c t_deque *get_ordered_vals(t_deque *stack); @@ -152,7 +159,6 @@ void partition_leaving_vals_cutoff(t_deque *staying_vals, t_deque *block_ids, in void partition_leaving_vals_n_blocks(t_deque *leaving_vals, t_deque *block_ids, int nb_blocks); t_deque *get_leaving_vals_trimmed(t_deque *leaving_vals); - // sort_small.c void try_sort_small(t_main_cont *cont); bool try_swap(t_main_cont *cont); @@ -162,9 +168,11 @@ bool check_if_best_moves(t_main_cont *cont, t_deque *moves_buff); // insert.c void insert_b(t_main_cont *cont, t_deque *moves_buff); -int calc_delta_insert(t_main_cont *cont, t_insert_info *info); void insert_elem_b(t_main_cont *cont, t_deque *moves_buff, t_insert_info *info); +// delta_insert.c +int calc_delta_insert(t_main_cont *cont, t_insert_info *info); + // insert_utils.c int get_cost_either_direction(t_insert_info *info); int get_cost_indep_directions(t_insert_info *info); @@ -172,50 +180,42 @@ int get_insert_val(t_deque *haystack, int curr_val); void insert_block_of_a_in_b(t_main_cont *cont, t_deque *block_ids, int curr_block_id); void insert_last_block(t_main_cont *cont, t_deque *moves_list); -// calc_insert_cost.c +// calc_insert_cost.c void init_insert_info(t_main_cont *cont, t_insert_info *info); void update_insert_info(t_main_cont *cont, t_insert_info *info); -// insert_blocks.c +// insert_blocks.c void insert_block_set_ids(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, int curr_block_id_a); void insert_block_elem_b(t_main_cont *cont, t_deque *block_ids_b, t_insert_info *info); -// insert_blocks_utils.c +// insert_blocks_utils.c void insert_curr_block_id(t_main_cont *cont, t_deque *block_ids_a, t_deque *block_ids_b, t_block_info *info); void insert_block_of_b_in_a(t_main_cont *cont, t_deque *block_ids_b, int block_id); void rotate_to_block_id(t_main_cont *cont,t_deque *block_ids_a,t_deque *block_ids_b,t_block_info *info); void check_if_top_stack_b_is_smaller_than_median(t_main_cont *cont, t_deque *block_ids, t_block_info *info); -// sort_utils.c -bool is_sorted(t_deque *stack, int pos_smallest); -int get_pos_of_val(t_deque *stack, int val); -int get_pos_smallest_val(t_deque *stack); -int get_pos_biggest_val(t_deque *stack); -void rotate_to_0_in_a(t_main_cont *cont, t_deque *curr_moves, int pos); -bool is_in_stack(t_deque *stack, int val); - -// SORT BIG +// block_utils.c void rotate_block_split(t_main_cont *cont, t_deque *block_ids, t_block_info *info); bool block_id_is_in_stack(t_deque *block_ids, int id); bool has_smaller_than_median(t_deque *stack, t_block_info *info); bool has_bigger_than_median(t_deque *stack, int median_val, int max_val); void assign_block_median(t_deque *stack, t_deque *block_ids, t_block_info *info); -//UTILS -void *ft_safealloc(size_t size); - // sort_utils.c +bool is_sorted(t_deque *stack, int pos_smallest); +int get_pos_of_val(t_deque *stack, int val); +int get_pos_smallest_val(t_deque *stack); +int get_pos_biggest_val(t_deque *stack); +void rotate_to_0_in_a(t_main_cont *cont, t_deque *curr_moves, int pos); + +// utils.c +void *ft_safealloc(size_t size); -// PRINT UTILS -void print_stacks(t_main_cont *cont); -void print_single_stack(t_deque *stack); +// print_utils.c void print_move(int move); void print_all_moves(t_deque *curr_moves); -void print_stacks_info(t_main_cont *cont); -void print_stack_with_block_ids(int *stack, int *block_ids, int size); -void print_staying_vals(t_main_cont *cont, t_deque *staying_vals); -//ERROR HANDLING +// errors.c void exit_on_err(char *err_message); //CLEANUP diff --git a/include/push_swap_bonus.h b/include/push_swap_bonus.h new file mode 100644 index 0000000..21650ee --- /dev/null +++ b/include/push_swap_bonus.h @@ -0,0 +1,49 @@ +#ifndef PUSH_SWAP_BONUH_H +# define PUSH_SWAP_BONUH_H + +#include "../libft/libft.h" +#include "deques.h" +#include "moves.h" + +typedef struct s_checker t_checker; +typedef struct s_checker +{ + t_deque stack_a; + t_deque stack_b; + void (**moves_fcts)(t_checker *); +} t_checker; + +// checker_bonus.c +void set_moves_pointers(void (**array)(t_checker *)); +void init_bonus(t_checker *checker, char **args); +void do_moves(t_checker *checker); +void free_checker(t_checker *checker); + +// parse_bonus.c +void parse_bonus(t_checker *checker, int argc, char *argv[]); + + +// moves +void checker_ra(t_checker *checker); +void checker_rb(t_checker *checker); +void checker_rr(t_checker *checker); +void checker_sa(t_checker *checker); +void checker_sb(t_checker *checker); +void checker_ss(t_checker *checker); +void checker_pa(t_checker *checker); +void checker_pb(t_checker *checker); +void checker_rra(t_checker *checker); +void checker_rrb(t_checker *checker); +void checker_rrr(t_checker *checker); + + +// utils.c +void *ft_safealloc(size_t size); + +// undo_moves.c +int convert_move_to_index(int move); + +// errors.c +void exit_on_err(char *err_message); + +#endif diff --git a/src/cherrypick_utils.c b/src/cherrypick_utils.c index 20685d8..5998039 100644 --- a/src/cherrypick_utils.c +++ b/src/cherrypick_utils.c @@ -1,8 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cherrypick_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) { diff --git a/src/delta_insert.c b/src/delta_insert.c new file mode 100644 index 0000000..dba1412 --- /dev/null +++ b/src/delta_insert.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* delta_insert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a.max_elem; + min_a = cont->stack_a.min_elem; + max_b = cont->stack_b.max_elem; + min_b = cont->stack_b.min_elem; + delta_insert = ft_abs(val_a - val_b); + if (delta_insert <= (ft_max(max_a, max_b) + 1) / 2) + return (delta_insert); + delta_insert = (max_a - val_a) + (val_b - min_b) + 1; + if (val_b > val_a) + delta_insert = (max_b - val_b) + (val_a - min_a) + 1; + return (delta_insert); +} + +//Need to add absolute distance from previous one +int calc_delta_insert(t_main_cont *cont, t_insert_info *info) +{ + t_iterator *iter; + int delta_insert; + + iter = malloc(sizeof(t_iterator)); + if (!iter) + exit_on_err("calc_delta_insert: iter error\n"); + set_iterator(iter, info->a_info.pos, cont->stack_a.size, 1); + iterate_once(iter, 1); + delta_insert = calc_delta_two_values( + cont, + cont->stack_a.elems[iter->index], + cont->stack_b.elems[iter->index]); + delta_insert = ft_min(delta_insert, \ + calc_delta_two_values(cont, info->a_info.val, info->b_info.val)); + free(iter); + return (delta_insert); +} diff --git a/src/deque_modify.c b/src/deque_modify.c index 242d247..aa5b48e 100644 --- a/src/deque_modify.c +++ b/src/deque_modify.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deque_modify.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- curr_moves); - insert_b(cont, &cont->curr_moves); - rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); - if (cont->curr_moves.size < cont->best_moves.size) - { - copy_deque(&cont->curr_moves, &cont->best_moves); - } - copy_deque(&cont->initial_stack, &cont->stack_a); - deque_reinit_list(&cont->stack_b); - deque_reinit_list(&cont->curr_moves); - return ; -} - - -void try_cutoff_n(t_main_cont *cont, t_deque *block_ids, int n, int cutoff) -{ - int i; - - i = 0; - while (i < n) - { - partition_stack_cutoff(&cont->stack_a, block_ids, cutoff); - insert_block_of_a_in_b(cont, block_ids, 1); - i++; - } - complete_ignore_lis_algo(cont); - return ; -} - -void try_n_divisions(t_main_cont *cont, t_deque *block_ids, int n) -{ - int i; - - i = 0; - while (i < n) - { - partition_stack_in_two(&cont->stack_a, block_ids); - insert_block_of_a_in_b(cont, block_ids, 1); - i++; - } - complete_ignore_lis_algo(cont); - return ; -} - -void try_n_divisions_smallest(t_main_cont *cont, t_deque *block_ids, int n) -{ - int i; +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ignore_LIS.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a, block_ids); - insert_block_of_a_in_b(cont, block_ids, 0); - i++; - } - complete_ignore_lis_algo(cont); - return ; -} +#include "push_swap.h" -void try_n_divisions_closest(t_main_cont *cont, t_deque *block_ids, int n) +static void ignore_lis2(t_main_cont *cont, t_deque *block_ids) { int i; - i = 0; - while (i < n) - { - partition_stack_in_two(&cont->stack_a, block_ids); - insert_block_of_a_in_b(cont, block_ids, block_ids->elems[0]); - i++; - } - complete_ignore_lis_algo(cont); - return ; + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 10 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 11 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 13 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 14 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 15 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 16 / 24); + i = -1; + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 17 / 24); } void ignore_lis(t_main_cont *cont) { t_deque *block_ids; - int div_depth = 7; int i; new_deque(&block_ids); i = -1; - while (++i < div_depth) + while (++i < 7) try_n_divisions_smallest(cont, block_ids, i); i = -1; - while (++i < div_depth) + while (++i < 7) try_n_divisions_closest(cont, block_ids, i); i = -1; - while (++i < div_depth) + while (++i < 7) try_n_divisions(cont, block_ids, i); i = -1; - while (++i < div_depth) - try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 11 / 24); + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 7 / 24); i = -1; - while (++i < div_depth) - try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 10 / 24); + while (++i < 7) + try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 8 / 24); i = -1; - while (++i < div_depth) + while (++i < 7) try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 9 / 24); - i = -1; - while (++i < div_depth) - try_cutoff_n(cont, block_ids, i, cont->stack_a.max_elem * 7 / 24); + ignore_lis2(cont, block_ids); block_ids->free_list(block_ids); free(block_ids); } diff --git a/src/ignore_lis_utils.c b/src/ignore_lis_utils.c new file mode 100644 index 0000000..7cd2871 --- /dev/null +++ b/src/ignore_lis_utils.c @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ignore_lis_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- curr_moves); + insert_b(cont, &cont->curr_moves); + rotate_to_0_in_a(cont, &cont->curr_moves, cont->head_a.index); + if (cont->curr_moves.size < cont->best_moves.size) + { + copy_deque(&cont->curr_moves, &cont->best_moves); + } + copy_deque(&cont->initial_stack, &cont->stack_a); + deque_reinit_list(&cont->stack_b); + deque_reinit_list(&cont->curr_moves); + return ; +} + +void try_cutoff_n(t_main_cont *cont, t_deque *block_ids, int n, int cutoff) +{ + int i; + + i = 0; + while (i < n) + { + partition_stack_cutoff(&cont->stack_a, block_ids, cutoff); + insert_block_of_a_in_b(cont, block_ids, 1); + i++; + } + complete_algo(cont); + return ; +} + +void try_n_divisions(t_main_cont *cont, t_deque *block_ids, int n) +{ + int i; + + i = 0; + while (i < n) + { + partition_stack_in_two(&cont->stack_a, block_ids); + insert_block_of_a_in_b(cont, block_ids, 1); + i++; + } + complete_algo(cont); + return ; +} + +void try_n_divisions_smallest(t_main_cont *cont, t_deque *block_ids, int n) +{ + int i; + + i = 0; + while (i < n) + { + partition_stack_in_two(&cont->stack_a, block_ids); + insert_block_of_a_in_b(cont, block_ids, 0); + i++; + } + complete_algo(cont); + return ; +} + +void try_n_divisions_closest(t_main_cont *cont, t_deque *block_ids, int n) +{ + int i; + + i = 0; + while (i < n) + { + partition_stack_in_two(&cont->stack_a, block_ids); + insert_block_of_a_in_b(cont, block_ids, block_ids->elems[0]); + i++; + } + complete_algo(cont); + return ; +} diff --git a/src/init.c b/src/init.c index f628ee1..30e5d9f 100644 --- a/src/init.c +++ b/src/init.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_b.size <= 0) return ; info = ft_safealloc(sizeof(t_insert_info)); - // if b is not empty, init will also call update_insert_info() - // init_insert_info(cont, info); info->b_info.pos = 0; info->min_cost = 1000; info->min_delta_insert = 1000; - while (info->b_info.pos < cont->stack_b.size) { update_insert_info(cont, info); - // Attempt to not try EVERY value, but only those that can result in fewer moves - // if stack_b pos is further than min_moves, set pos to stack_b.size - min_cost - if (info->b_info.pos > info->min_cost && - info->b_info.pos <= cont->stack_b.size - info->min_cost && - cont->stack_a.size + cont->stack_b.size >= 500) + if (info->b_info.pos > info->min_cost + && info->b_info.pos <= cont->stack_b.size - info->min_cost + && cont->stack_a.size + cont->stack_b.size >= 500) info->b_info.pos = cont->stack_b.size - info->min_cost; info->b_info.pos++; } - insert_elem_b(cont, moves_buff, info); - free(info); insert_b(cont, moves_buff); return ; @@ -64,8 +69,8 @@ static void insert_same_sign( static void insert_same_direction( t_main_cont *cont, t_deque *moves_buff, t_insert_info *info) { - if (info->min_cost == info->a_info.pos_best || - info->min_cost == info->b_info.pos_best) + if (info->min_cost == info->a_info.pos_best + || info->min_cost == info->b_info.pos_best) { while (info->min_cost-- > 0) { @@ -125,48 +130,5 @@ void insert_elem_b( else insert_indep_directions(cont, moves_buff, info); do_pa(cont, moves_buff); - return ; -} - -int calc_delta_two_values(t_main_cont *cont, int val_a, int val_b) -{ - int delta_insert; - int max_a; - int min_a; - int max_b; - int min_b; - - max_a = cont->stack_a.max_elem; - min_a = cont->stack_a.min_elem; - max_b = cont->stack_b.max_elem; - min_b = cont->stack_b.min_elem; - delta_insert = ft_abs(val_a - val_b); // is now equal to the diff between the two - //if bigger than half the absolute diff - if (delta_insert <= (ft_max(max_a, max_b) + 1) / 2) - return (delta_insert); - delta_insert = (max_a - val_a) + (val_b - min_b) + 1; - if (val_b > val_a) - delta_insert = (max_b - val_b) + (val_a - min_a) + 1; - return (delta_insert); -} - -//Need to add absolute distance from previous one -int calc_delta_insert(t_main_cont *cont, t_insert_info *info) -{ - t_iterator *iter; - int delta_insert; - - iter = malloc(sizeof(t_iterator)); - if (!iter) - exit_on_err("calc_delta_insert: iter error\n"); - set_iterator(iter, info->a_info.pos, cont->stack_a.size, 1); - iterate_once(iter, 1); - delta_insert = calc_delta_two_values( - cont, - cont->stack_a.elems[iter->index], - cont->stack_b.elems[iter->index]); - delta_insert = ft_min(delta_insert, \ - calc_delta_two_values(cont, info->a_info.val, info->b_info.val)); - free(iter); - return (delta_insert); + return ; } diff --git a/src/parse.c b/src/parse.c index fd2f1b9..9b75c16 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,7 +6,7 @@ /* By: iyahoui- 0 && int_to_long > INT_MAX) + || (sign < 0 && int_to_long * sign < INT_MIN)) + return (false); + } + return (true); +} + +static char **split_args(int argc, char *argv[]) +{ + int i; + char **args_split; + + if (argc == 2) + return (ft_split(argv[1], ' ')); + else + args_split = malloc((argc) * sizeof(char *)); + if (!args_split) + exit_on_err("Error\n"); + i = 0; + while (i < argc - 1) + { + args_split[i] = ft_strdup(argv[i + 1]); + if (!args_split[i]) + exit_on_err("Error\n"); + i++; + } + args_split[i] = NULL; + return (args_split); +} + +void parse_bonus(t_checker *checker, int argc, char *argv[]) +{ + char **args_split; + int i; + + args_split = split_args(argc, argv); + i = 0; + while (args_split[i] && is_an_int(args_split[i]) == true) + i++; + if (args_split[i] != NULL) + { + free(checker); + ft_free_split(args_split); + exit_on_err("Error\n"); + } + init_bonus(checker, args_split); + if (has_duplicates(checker->stack_a.elems, checker->stack_a.size)) + { + free_checker(checker); + ft_free_split(args_split); + exit_on_err("Error\n"); + } + ft_free_split(args_split); + return ; +} diff --git a/src/print_utils.c b/src/print_utils.c index 5f26f7b..f05c3a6 100644 --- a/src/print_utils.c +++ b/src/print_utils.c @@ -1,114 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) + if ((move >> 16) & 0xFF) { - printf("|%-3d|", i); - if (i < stack->size) - printf("\033[38;5;5m %-3d \033[0;0;0m|\n", stack->elems[i]); - else - printf("\t\033[0m|\n"); - i++; + c = (char)((move >> 16) & 0xFF); + write(1, &c, 1); } - printf("+---+-----+\n"); + c = (char)((move >> 8) & 0xFF); + write(1, &c, 1); + c = (char)(move & 0xFF); + write(1, &c, 1); + write(1, "\n", 1); + return ; } -void print_stacks(t_main_cont *cont) +void print_all_moves(t_deque *curr_moves) { - int *stack_a; - int *stack_b; - int size_a; - int size_b; int i; - printf(" |\033[38;5;5m [A] \033[0m|\033[38;5;6m [B] \033[0;0;0m|\n"); - printf("+---+-----+-----+\n"); i = 0; - stack_a = cont->stack_a.elems; - stack_b = cont->stack_b.elems; - size_a = cont->stack_a.size; - size_b = cont->stack_b.size; - while (i < size_a || i < size_b) - { - printf("|%-3d|", i); - if (i < size_a) - printf("\033[38;5;5m %-3d \033[0;0;0m", stack_a[i]); - else - printf(" \033[0m"); - if (i < size_b) - printf("|\033[38;5;6m %-3d \033[0m|\n", stack_b[i]); - else - printf("| |\n\033[0m"); - i++; - } - printf("+---+-----+-----+\n"); -} - -void print_stacks_info(t_main_cont *cont) -{ - print_stacks(cont); - - printf(YELLOW"**stack_a**\n"); - printf("\tmax elem in a = %d\n", cont->stack_a.max_elem); - printf("\tmin elem in a = %d\n", cont->stack_a.min_elem); - printf("\tpos: %d\n", cont->head_a.index); - printf("\tsize of stack_a = %d\n", cont->stack_a.size); - - printf(YELLOW"**stack_b**\n"); - printf("\tmax elem in b = %d\n", cont->stack_b.max_elem); - printf("\tmin elem in b = %d\n", cont->stack_b.min_elem); - printf("\tpos: %d\n", cont->head_b.index); - printf("\tsize of stack_b = %d\n"RESET_COL, cont->stack_b.size); - - printf(CYAN"\t==> CURR TOTAL: %d \n"RESET_COL, cont->curr_moves.size); - print_all_moves(&cont->curr_moves); - printf(BLUE"\t==> BEST TOTAL: %d \n"RESET_COL, cont->best_moves.size); - print_all_moves(&cont->best_moves); - - return ; -} - -void print_move(int move) -{ - char c; - - if (move >> 16 & 0xFF) - { - c = (char)(move >> 16 & 0xFF); - write(1, &c, 1); - } - c = (char)(move >> 8 & 0xFF); - write(1, &c, 1); - c = (char)(move & 0xFF); - write(1, &c, 1); - write(1, "\n", 1); - return; -} - -void print_all_moves(t_deque *curr_moves) -{ - int pos_of_the_move_thing_in_the_list_thing; - - pos_of_the_move_thing_in_the_list_thing = 0; if (curr_moves->size == INT_MAX) return ; - while (pos_of_the_move_thing_in_the_list_thing < curr_moves->size) - { - print_move(curr_moves->elems[pos_of_the_move_thing_in_the_list_thing]); - pos_of_the_move_thing_in_the_list_thing++; - } - if (DEBUG) + while (i < curr_moves->size) { - if (!pos_of_the_move_thing_in_the_list_thing) - printf(RESET_COL"\t====== No move stored ======\n"); - else - printf(GREEN"\t====== Total nb_moves == %d ======\n"RESET_COL, pos_of_the_move_thing_in_the_list_thing); + print_move(curr_moves->elems[i]); + i++; } - return ; + return ; } diff --git a/src/push_swap.c b/src/push_swap.c index d573a6f..509912b 100644 --- a/src/push_swap.c +++ b/src/push_swap.c @@ -6,7 +6,7 @@ /* By: iyahoui- best_moves); cleanup(cont); diff --git a/src/px.c b/src/px.c index e83ac71..e43fcd2 100644 --- a/src/px.c +++ b/src/px.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_b, &checker->stack_a); + return ; +} + +void checker_pb(t_checker *checker) +{ + push(&checker->stack_a, &checker->stack_b); + return ; +} diff --git a/src/rrx.c b/src/rrx.c index cf26641..9478d8e 100644 --- a/src/rrx.c +++ b/src/rrx.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_a); + return ; +} + +void checker_rrb(t_checker *checker) +{ + rev_rotate(&checker->stack_b); + return ; +} + +void checker_rrr(t_checker *checker) +{ + rev_rotate(&checker->stack_a); + rev_rotate(&checker->stack_b); + return ; +} diff --git a/src/rx.c b/src/rx.c index 5e07db1..4d86cb5 100644 --- a/src/rx.c +++ b/src/rx.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_a); if (curr_moves) curr_moves->add_last(curr_moves, RA); - rotate_update_iterators(&cont->head_a); return ; } -void do_rb(t_main_cont *cont, t_deque *curr_moves) +void do_rb(t_main_cont *cont, t_deque *curr_moves) { rotate(&cont->stack_b); if (curr_moves) @@ -50,7 +49,6 @@ void do_rr(t_main_cont *cont, t_deque *curr_moves) rotate(&cont->stack_b); if (curr_moves) curr_moves->add_last(curr_moves, RR); - rotate_update_iterators(&cont->head_a); rotate_update_iterators(&cont->head_b); return ; diff --git a/src/rx_bonus.c b/src/rx_bonus.c new file mode 100644 index 0000000..88f28d9 --- /dev/null +++ b/src/rx_bonus.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rx_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a); + return ; +} + +void checker_rb(t_checker *checker) +{ + rotate(&checker->stack_b); + return ; +} + +void checker_rr(t_checker *checker) +{ + rotate(&checker->stack_a); + rotate(&checker->stack_b); + return ; +} diff --git a/src/sort.c b/src/sort.c index 41866a3..5dd3f2e 100644 --- a/src/sort.c +++ b/src/sort.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_a, cont->head_a.index)) { return (false); @@ -95,7 +107,6 @@ bool try_invert_4(t_main_cont *cont) do_ra(cont, moves_buff); do_ra(cont, moves_buff); do_sa(cont, moves_buff); - if (try_solution(cont, moves_buff)) { return (true); diff --git a/src/split_in_two.c b/src/split_in_two.c index 8c27fc3..e38f3af 100644 --- a/src/split_in_two.c +++ b/src/split_in_two.c @@ -1,21 +1,16 @@ -#include "push_swap.h" - -int max_elem_leaving(t_main_cont *cont, t_deque *leaving_vals) -{ - int i; - int max_elem; +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* split_in_two.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) - { - if (leaving_vals->elems[i] > max_elem - && !is_in_stack(&cont->stack_b, leaving_vals->elems[i])) - max_elem = leaving_vals->elems[i]; - i++; - } - return (max_elem); -} +#include "push_swap.h" static void try_single_cutoff( t_main_cont *cont, t_deque *block_ids, float cutoff) @@ -90,7 +85,7 @@ static void try_multiple_cutoffs_footer( } } -static void split_in_two_mult_cutoffs(t_main_cont *cont, t_deque *block_ids) +void split_in_two_mult_cutoffs(t_main_cont *cont, t_deque *block_ids) { try_multiple_cutoffs_body(cont, block_ids, 0.6F, 1); try_multiple_cutoffs_body(cont, block_ids, 0.5F, 1); @@ -132,4 +127,4 @@ void split_in_two(t_main_cont *cont) block_ids->free_list(block_ids); free(block_ids); return ; -} \ No newline at end of file +} diff --git a/src/split_in_two_utils.c b/src/split_in_two_utils.c new file mode 100644 index 0000000..c793b52 --- /dev/null +++ b/src/split_in_two_utils.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* split_in_two_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- size) + { + if (leaving_vals->elems[i] > max_elem + && !is_in_stack(&cont->stack_b, leaving_vals->elems[i])) + max_elem = leaving_vals->elems[i]; + i++; + } + return (max_elem); +} diff --git a/src/sx.c b/src/sx.c index 2ff7cf5..0eab0a9 100644 --- a/src/sx.c +++ b/src/sx.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sx.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a); if (curr_moves) curr_moves->add_last(curr_moves, SA); - swap_update_iterator(&cont->head_a); - return ; } -void do_sb(t_main_cont *cont, t_deque *curr_moves) +void do_sb(t_main_cont *cont, t_deque *curr_moves) { swap(&cont->stack_b); if (curr_moves) curr_moves->add_last(curr_moves, SB); - swap_update_iterator(&cont->head_b); - return ; } -void do_ss(t_main_cont *cont, t_deque *curr_moves) +void do_ss(t_main_cont *cont, t_deque *curr_moves) { swap(&cont->stack_a); swap(&cont->stack_b); if (curr_moves) curr_moves->add_last(curr_moves, SS); - swap_update_iterator(&cont->head_a); swap_update_iterator(&cont->head_b); - return ; -} \ No newline at end of file +} diff --git a/src/sx_bonus.c b/src/sx_bonus.c new file mode 100644 index 0000000..77a9e10 --- /dev/null +++ b/src/sx_bonus.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* sx_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a); + return ; +} + +void checker_sb(t_checker *checker) +{ + swap(&checker->stack_b); + return ; +} + +void checker_ss(t_checker *checker) +{ + swap(&checker->stack_a); + swap(&checker->stack_b); + return ; +} diff --git a/src/undo_moves.c b/src/undo_moves.c index 9d434d0..5e1ae48 100644 --- a/src/undo_moves.c +++ b/src/undo_moves.c @@ -6,24 +6,24 @@ /* By: iyahoui- 0) + 3 * (s=>0) = 0 + 3*0 = 0 | rev_fcts[0] => &do_sa - * REV_SB = 1 | (b=>1) + 3 * (s=>0) = 1 + 3*0 = 1 | rev_fcts[1] => &do_sb - * REV_SS = 2 | (r/s=>2) + 3 * (s=>0) = 2 + 3*0 = 2 | rev_fcts[5] => &do_ss - * REV_RA = 3 | {...} - * REV_RB = 4 | - * REV_RR = 5 | (r/s=>2) + 3 * (r=>1) = 2+ 3*1 = 5 | rev_fcts[5] => &do_rrr - * REV_RRA = 6 | {...} - * REV_RRB = 7 | (b=>1) + 3 * (rr=>q=>2) = 1 + 3*2 = 7| rev_fcts[7] => &do_rb - * REV_RRR = 8 | {...} - * REV_PA = 9 | - * REV_PB = 10 | (b=>1) + 3 * (p=>3) = 1 + 3*3 = 10 | rev_fcts[10] ==> &do_pa + * SA = 0 | (a=>0) + 3 * (s=>0) = 0 + 3*0 = 0 | rev_fcts[0] => &do_sa + * SB = 1 | (b=>1) + 3 * (s=>0) = 1 + 3*0 = 1 | rev_fcts[1] => &do_sb + * SS = 2 | (r/s=>2) + 3 * (s=>0) = 2 + 3*0 = 2 | rev_fcts[5] => &do_ss + * RA = 3 | {...} + * RB = 4 | + * RR = 5 | (r/s=>2) + 3 * (r=>1) = 2+ 3*1 = 5 | rev_fcts[5] => &do_rrr + * RRA = 6 | {...} + * RRB = 7 | (b=>1) + 3 * (rr=>q=>2) = 1 + 3*2 = 7| rev_fcts[7] => &do_rb + * RRR = 8 | {...} + * PA = 9 | + * PB = 10 | (b=>1) + 3 * (p=>3) = 1 + 3*3 = 10 | rev_fcts[10] ==> &do_pa */ int convert_move_to_index(int move) { diff --git a/src/utils.c b/src/utils.c index afe9e04..e143ad4 100644 --- a/src/utils.c +++ b/src/utils.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: iyahoui- Date: Thu, 21 Apr 2022 13:01:13 -0400 Subject: [PATCH 17/32] Updated push --- Makefile | 8 ++------ include/push_swap_bonus.h | 26 ++++++++++++++++++++++---- src/px_bonus.c | 9 ++++++++- src/rrx_bonus.c | 9 ++++++++- src/rx_bonus.c | 9 ++++++++- src/sx_bonus.c | 12 +++++++++++- 6 files changed, 59 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 1251e9f..5890453 100644 --- a/Makefile +++ b/Makefile @@ -55,14 +55,10 @@ CFILES_BONUS = checker_bonus.c \ deques.c \ deque_modify.c \ deque_operators.c \ + deque_utils.c \ errors.c \ - init.c \ - px.c \ px_bonus.c \ parse_bonus.c \ - rx.c \ - rrx.c \ - sx.c \ rx_bonus.c \ rrx_bonus.c \ sx_bonus.c \ @@ -113,7 +109,7 @@ COMPILE_EXE_OUT = $$($(COMPILE_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\0 COMPILE_C = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< COMPILE_C_OUT = $$($(COMPILE_C) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(OBJS) -o $(NAME_BONUS) +COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(OBJS_BONUS) -o $(NAME_BONUS) COMPILE_EXE_BONUS_OUT = $$($(COMPILE_EXE_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') COMPILE_C_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< diff --git a/include/push_swap_bonus.h b/include/push_swap_bonus.h index 21650ee..830d00e 100644 --- a/include/push_swap_bonus.h +++ b/include/push_swap_bonus.h @@ -3,7 +3,21 @@ #include "../libft/libft.h" #include "deques.h" -#include "moves.h" + +typedef enum e_moves_to_indices +{ + SA_INDEX = 0, + SB_INDEX = 1, + SS_INDEX = 2, + RA_INDEX = 3, + RB_INDEX = 4, + RR_INDEX = 5, + RRA_INDEX = 6, + RRB_INDEX = 7, + RRR_INDEX = 8, + PA_INDEX = 9, + PB_INDEX = 10 +} t_moves_to_indices; typedef struct s_checker t_checker; typedef struct s_checker @@ -24,17 +38,21 @@ void parse_bonus(t_checker *checker, int argc, char *argv[]); // moves +void rotate(t_deque *stack); void checker_ra(t_checker *checker); void checker_rb(t_checker *checker); void checker_rr(t_checker *checker); +void rev_rotate(t_deque *stack); +void checker_rra(t_checker *checker); +void checker_rrb(t_checker *checker); +void checker_rrr(t_checker *checker); +void swap(t_deque *stack); void checker_sa(t_checker *checker); void checker_sb(t_checker *checker); void checker_ss(t_checker *checker); +void push(t_deque *stack_src, t_deque *stack_dest); void checker_pa(t_checker *checker); void checker_pb(t_checker *checker); -void checker_rra(t_checker *checker); -void checker_rrb(t_checker *checker); -void checker_rrr(t_checker *checker); // utils.c diff --git a/src/px_bonus.c b/src/px_bonus.c index 6505157..a7e959a 100644 --- a/src/px_bonus.c +++ b/src/px_bonus.c @@ -6,12 +6,19 @@ /* By: iyahoui- add_front(stack_dest, stack_src->elems[0]); + stack_src->remove_front(stack_src); + return ; +} + void checker_pa(t_checker *checker) { push(&checker->stack_b, &checker->stack_a); diff --git a/src/rrx_bonus.c b/src/rrx_bonus.c index 0cd84ff..74c776b 100644 --- a/src/rrx_bonus.c +++ b/src/rrx_bonus.c @@ -6,12 +6,19 @@ /* By: iyahoui- add_front(stack, stack->elems[stack->size - 1]); + stack->remove_last(stack); + return ; +} + void checker_rra(t_checker *checker) { rev_rotate(&checker->stack_a); diff --git a/src/rx_bonus.c b/src/rx_bonus.c index 88f28d9..db3602c 100644 --- a/src/rx_bonus.c +++ b/src/rx_bonus.c @@ -6,12 +6,19 @@ /* By: iyahoui- add_last(stack, stack->elems[0]); + stack->remove_front(stack); + return ; +} + void checker_ra(t_checker *checker) { rotate(&checker->stack_a); diff --git a/src/sx_bonus.c b/src/sx_bonus.c index 77a9e10..634c1dc 100644 --- a/src/sx_bonus.c +++ b/src/sx_bonus.c @@ -6,12 +6,22 @@ /* By: iyahoui- elems[0]; + stack->set_elem(stack, 0, stack->elems[1]); + stack->set_elem(stack, 1, temp); + return ; +} + void checker_sa(t_checker *checker) { swap(&checker->stack_a); From b5a6a1f9fd0b0b6773baa39a6d37fcb4832f2077 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Thu, 21 Apr 2022 13:09:45 -0400 Subject: [PATCH 18/32] Added checker_bonus --- .gitignore | 2 +- src/checker_bonus.c | 108 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/checker_bonus.c diff --git a/.gitignore b/.gitignore index 505eb4f..3540db9 100644 --- a/.gitignore +++ b/.gitignore @@ -57,7 +57,7 @@ dkms.conf *.swp .vscode *.txt -checker* +checker_Mac push_swap push_swap_debug *.o diff --git a/src/checker_bonus.c b/src/checker_bonus.c new file mode 100644 index 0000000..9dc6a54 --- /dev/null +++ b/src/checker_bonus.c @@ -0,0 +1,108 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* checker_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- stack_a); + init_deque(&checker->stack_b); + checker->moves_fcts = ft_safealloc(11 * sizeof(void *)); + i = -1; + while (args[++i] != NULL) + checker->stack_a.add_last(&checker->stack_a, ft_atoi(args[i])); + set_moves_pointers(checker->moves_fcts); + return ; +} + +void do_moves(t_checker *checker) +{ + int move; + int pos; + char c; + + pos = 0; + move = 0; + while (read(STDIN_FILENO, &c, 1)) + { + pos++; + move = (move << 8) | c; + if ((pos == 2 && (c == 'a' || c == 'b' || c == 's' || c == 'r')) + || (pos == 3 && (c != 'r' || c != 's' || c != 'a' || c != 'b'))) + { + checker->moves_fcts[convert_move_to_index(move)](checker); + pos = 0; + move = 0; + } + if ((pos == 1 && (c == 'r' || c == 'p' || c == 's')) + || (pos == 2 && (c == 'r'|| c == 'a' || c == 'b')) + || (pos == 3 && (c != 'r' || c == 's' || c == 'a' || c == 'b' || c == '\n' || !c))) + continue; + else + { + free_checker(checker); + exit_on_err("Error\n"); + } + } +} + +void free_checker(t_checker *checker) +{ + checker->stack_a.free_list(&checker->stack_a); + checker->stack_b.free_list(&checker->stack_b); + free(checker->moves_fcts); + free(checker); + return ; +} + +int main(int argc, char *argv[]) +{ + t_checker *checker; + int i; + + if (argc < 2) + exit(EXIT_SUCCESS); + checker = ft_safealloc(sizeof(t_checker)); + parse_bonus(checker, argc, argv); + do_moves(checker); + i = 0; + while (++i < checker->stack_a.size) + { + if (checker->stack_a.elems[i] > checker->stack_a.elems[i] - 1) + { + write(STDIN_FILENO, "KO\n", 3); + free_checker(checker); + return (1); + } + } + write(STDIN_FILENO, "OK\n", 3); + free_checker(checker); + return (0); +} From 066fbdfc97797e668d7e987b1fdaab18a8f75fc6 Mon Sep 17 00:00:00 2001 From: Ismael Yahyaoui Racine Date: Mon, 25 Apr 2022 15:39:22 -0400 Subject: [PATCH 19/32] Updated submodule --- libft | 2 +- src/checker_bonus.c | 74 ++++++++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/libft b/libft index 624d3b1..d48073f 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 624d3b17712c0d9ee4b44d31c714882d4577b68a +Subproject commit d48073f1657add2bfcf2332ee641801c3e6a81fe diff --git a/src/checker_bonus.c b/src/checker_bonus.c index 9dc6a54..09d4b1e 100644 --- a/src/checker_bonus.c +++ b/src/checker_bonus.c @@ -6,7 +6,7 @@ /* By: iyahoui- moves_fcts[convert_move_to_index(move)](checker); - pos = 0; - move = 0; + ft_putstr_fd("Error\n", 1); + free(curr_line); + return ; } - if ((pos == 1 && (c == 'r' || c == 'p' || c == 's')) - || (pos == 2 && (c == 'r'|| c == 'a' || c == 'b')) - || (pos == 3 && (c != 'r' || c == 's' || c == 'a' || c == 'b' || c == '\n' || !c))) - continue; else { - free_checker(checker); - exit_on_err("Error\n"); + move = 0; + i = 0; + while (curr_line[i] && curr_line[i] != '\n') + { + move |= (move << 8) | curr_line[i]; + i++; + } + checker->moves_fcts[convert_move_to_index(move)](checker); } + free(curr_line); + curr_line = get_next_line(STDIN_FILENO); } + return ; } void free_checker(t_checker *checker) @@ -93,16 +107,22 @@ int main(int argc, char *argv[]) parse_bonus(checker, argc, argv); do_moves(checker); i = 0; + printf("back in main\n"); while (++i < checker->stack_a.size) { - if (checker->stack_a.elems[i] > checker->stack_a.elems[i] - 1) + if (checker->stack_a.elems[i] < checker->stack_a.elems[i - 1]) { - write(STDIN_FILENO, "KO\n", 3); - free_checker(checker); - return (1); + printf("checker found to not be sorted\n"); + printf("\n"); + write(STDOUT_FILENO, "KO\n", 3); + break ; } } - write(STDIN_FILENO, "OK\n", 3); + if (i == checker->stack_a.size) + { + printf("checker found to be sorted"); + write(STDOUT_FILENO, "OK\n", 3); + } free_checker(checker); return (0); } From b9d46cad027a12935bc774fc7b17d86ff86be471 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Mon, 25 Apr 2022 15:41:07 -0400 Subject: [PATCH 20/32] Updated submodule --- libft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libft b/libft index 624d3b1..f064af8 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 624d3b17712c0d9ee4b44d31c714882d4577b68a +Subproject commit f064af8adee51cb5129ee07c83e866a4cd5b3a75 From 7cd1402c2e20a990d41d310c8d2406e7faaf7520 Mon Sep 17 00:00:00 2001 From: Ismael Yahyaoui Racine Date: Wed, 27 Apr 2022 18:02:21 -0400 Subject: [PATCH 21/32] Started modifications --- include/deques.h | 2 ++ libft | 2 +- src/delta_insert.c | 6 ++---- src/deques.c | 12 +++--------- src/utils.c | 3 ++- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/deques.h b/include/deques.h index 77f151b..30f391d 100644 --- a/include/deques.h +++ b/include/deques.h @@ -62,6 +62,8 @@ void copy_deque(t_deque *src, t_deque *dest); void cat_deque(t_deque *src, t_deque *dest); void cat_deque_front(t_deque *src, t_deque *dest); +// utils.c +void *ft_safealloc(size_t size); //DUMB SHIT TO REMOVE //ERROR HANDLING diff --git a/libft b/libft index d48073f..9aaae99 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit d48073f1657add2bfcf2332ee641801c3e6a81fe +Subproject commit 9aaae99768086c6e0902a793b04923bd303a4fbd diff --git a/src/delta_insert.c b/src/delta_insert.c index dba1412..ddfe3b9 100644 --- a/src/delta_insert.c +++ b/src/delta_insert.c @@ -6,7 +6,7 @@ /* By: iyahoui- a_info.pos, cont->stack_a.size, 1); iterate_once(iter, 1); delta_insert = calc_delta_two_values( diff --git a/src/deques.c b/src/deques.c index 25a4277..ec7c094 100644 --- a/src/deques.c +++ b/src/deques.c @@ -6,7 +6,7 @@ /* By: iyahoui- capacity_end = VECTOR_INIT_SIZE; deque->capacity_front = VECTOR_INIT_SIZE; deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); - if (!deque->malloced_space) - exit_on_err("init_deque error\n"); - ft_bzero(deque->malloced_space, 2 * VECTOR_INIT_SIZE); + deque->malloced_space = ft_safealloc(2 * VECTOR_INIT_SIZE * sizeof(int)); deque->elems = &(deque->malloced_space[VECTOR_INIT_SIZE]); return ; } @@ -48,10 +45,7 @@ bool deque_reinit_list(t_deque *deque) deque->capacity_end = VECTOR_INIT_SIZE; deque->capacity_front = VECTOR_INIT_SIZE; deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = malloc(2 * VECTOR_INIT_SIZE * sizeof(int)); - if (!deque->malloced_space) - return (FAILURE); - ft_bzero(deque->malloced_space, 2 * VECTOR_INIT_SIZE); + deque->malloced_space = ft_safealloc(2 * VECTOR_INIT_SIZE * sizeof(int)); deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; return (SUCCESS); } diff --git a/src/utils.c b/src/utils.c index e143ad4..b4e0a9d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -6,7 +6,7 @@ /* By: iyahoui- Date: Wed, 27 Apr 2022 23:04:13 -0400 Subject: [PATCH 22/32] ft_safealloc() --> libft/ft_xalloc() Also removed all malloc calls --- checker_bonus | Bin 0 -> 57424 bytes include/deques.h | 4 +--- include/push_swap.h | 3 --- include/push_swap_bonus.h | 3 --- libft | 2 +- src/checker_bonus.c | 6 +++--- src/delta_insert.c | 4 ++-- src/deque_operators.c | 6 ++---- src/deque_utils.c | 6 ++---- src/deques.c | 6 +++--- src/parse.c | 6 ++---- src/parse_bonus.c | 4 +--- src/utils.c | 27 --------------------------- 13 files changed, 17 insertions(+), 60 deletions(-) create mode 100755 checker_bonus delete mode 100644 src/utils.c diff --git a/checker_bonus b/checker_bonus new file mode 100755 index 0000000000000000000000000000000000000000..738bb017abd187cf24b34f0fd36cf11236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EvlS?qf&h5esO`wA=jK4CsPew>*2FPHNFD&-YESNU2gKOp55 zR`UJ=`%X;uyQTbdQeI&tA1IJ_;)(b>2z}1+^9SJZ+HXYKzq(YkpTf$%v%iklf4!d- z{9h;K6+Tyazm&g8$}6nooqUmfCno;drF^xNS6Io{7Vzi96Y+N&^f~!!03MIOVQK$+ z(!RpV{$Jvc-5~heE#(zHSNU=&|1VNrVI}XZFY)KZoIfewC*|8ER`QJn{5kPN{QV00 zocz54O#J<>VE)cXdmqKSOc{(Stn54e9nXLNBEes|lvh~EcNh5Y#8m%bDZfa{E3D*u z3gn%bqy6N1bhE_ea(=l*Vl_X~OAwV;^IeO?YX11T z#A-g+DX|*g_e-qC%XcMK{r|_RyzF0(O04#``y^KV?LQ?}``1y4)%(mziPihb6!=d5 ztNq@k607~we2LY5XtBiVeeD*By>kEl6^YgR#}ixJ;V)ee>EU|k3*&wmnk90_^_Gh~!R_oojB=*Yw z`W=bY`N%^OtNHyAl`rRyr&PYgF93rc{1exK0*qtTy!_u6;G+fj?E-u`G=CiTY}`KF zSKz)9_ju{#fsdKvoE@9t>=9xvDvtxz39#8#$8z!dTs-PXk2=$%jxu?L@=H02#T=?) z4pp%jR5^}4&2Z~@hnYyu9(RgUPm|7W#j&O%fgij|oIA>u3AyuJ9B`hIhVxFD7LDYN zdb3IV#5d1gG{V!ICZiF4AWSE!SwWtXCzw5MHXHJes!g2Ii}OkT9YLMr^A8ECeVEx8 zH~DEjMZ|eM#T@7K1l0jP#beonc#il{J&(nsbRaLIbSlrI;`kni$oP^Vj(9~}9J}L7 z1`(C}?tspdI}A44=zJL8H?oJj>X6r@O7qI)&iBn2o$s6c>x8T~kE^p;@im24jj1mv z;@gS*YI4Sh7?YZ~r56lB>u zW1f? # include # include +# include "../libft/libft.h" # define VECTOR_INIT_SIZE 16 # define SUCCESS 0 @@ -62,9 +63,6 @@ void copy_deque(t_deque *src, t_deque *dest); void cat_deque(t_deque *src, t_deque *dest); void cat_deque_front(t_deque *src, t_deque *dest); -// utils.c -void *ft_safealloc(size_t size); - //DUMB SHIT TO REMOVE //ERROR HANDLING void exit_on_err(char *err_message); diff --git a/include/push_swap.h b/include/push_swap.h index 9535f4c..fb00989 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -208,9 +208,6 @@ int get_pos_smallest_val(t_deque *stack); int get_pos_biggest_val(t_deque *stack); void rotate_to_0_in_a(t_main_cont *cont, t_deque *curr_moves, int pos); -// utils.c -void *ft_safealloc(size_t size); - // print_utils.c void print_move(int move); void print_all_moves(t_deque *curr_moves); diff --git a/include/push_swap_bonus.h b/include/push_swap_bonus.h index 830d00e..d4d3cd9 100644 --- a/include/push_swap_bonus.h +++ b/include/push_swap_bonus.h @@ -55,9 +55,6 @@ void checker_pa(t_checker *checker); void checker_pb(t_checker *checker); -// utils.c -void *ft_safealloc(size_t size); - // undo_moves.c int convert_move_to_index(int move); diff --git a/libft b/libft index 9aaae99..6c48df6 160000 --- a/libft +++ b/libft @@ -1 +1 @@ -Subproject commit 9aaae99768086c6e0902a793b04923bd303a4fbd +Subproject commit 6c48df64977f3c63adc8e4c7492d5b9823c26f14 diff --git a/src/checker_bonus.c b/src/checker_bonus.c index 09d4b1e..eea0aa3 100644 --- a/src/checker_bonus.c +++ b/src/checker_bonus.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_a); init_deque(&checker->stack_b); - checker->moves_fcts = ft_safealloc(11 * sizeof(void *)); + checker->moves_fcts = ft_xalloc(11 * sizeof(void *)); i = -1; while (args[++i] != NULL) checker->stack_a.add_last(&checker->stack_a, ft_atoi(args[i])); @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) if (argc < 2) exit(EXIT_SUCCESS); - checker = ft_safealloc(sizeof(t_checker)); + checker = ft_xalloc(sizeof(t_checker)); parse_bonus(checker, argc, argv); do_moves(checker); i = 0; diff --git a/src/delta_insert.c b/src/delta_insert.c index ddfe3b9..b84d4cb 100644 --- a/src/delta_insert.c +++ b/src/delta_insert.c @@ -6,7 +6,7 @@ /* By: iyahoui- a_info.pos, cont->stack_a.size, 1); iterate_once(iter, 1); delta_insert = calc_delta_two_values( diff --git a/src/deque_operators.c b/src/deque_operators.c index 0edc0b4..551ed9f 100644 --- a/src/deque_operators.c +++ b/src/deque_operators.c @@ -6,7 +6,7 @@ /* By: iyahoui- capacity_front; - temp = malloc(total_new_size * sizeof(int)); - if (!temp) - return (FAILURE); + temp = ft_xalloc(total_new_size * sizeof(int)); temp += deque->capacity_front; pos_in_deque = 0; while (pos_in_deque < deque->size) diff --git a/src/deques.c b/src/deques.c index ec7c094..8de35de 100644 --- a/src/deques.c +++ b/src/deques.c @@ -6,7 +6,7 @@ /* By: iyahoui- capacity_end = VECTOR_INIT_SIZE; deque->capacity_front = VECTOR_INIT_SIZE; deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = ft_safealloc(2 * VECTOR_INIT_SIZE * sizeof(int)); + deque->malloced_space = ft_xalloc(2 * VECTOR_INIT_SIZE * sizeof(int)); deque->elems = &(deque->malloced_space[VECTOR_INIT_SIZE]); return ; } @@ -45,7 +45,7 @@ bool deque_reinit_list(t_deque *deque) deque->capacity_end = VECTOR_INIT_SIZE; deque->capacity_front = VECTOR_INIT_SIZE; deque->capacity_total = 2 * VECTOR_INIT_SIZE; - deque->malloced_space = ft_safealloc(2 * VECTOR_INIT_SIZE * sizeof(int)); + deque->malloced_space = ft_xalloc(2 * VECTOR_INIT_SIZE * sizeof(int)); deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; return (SUCCESS); } diff --git a/src/parse.c b/src/parse.c index 9b75c16..c7befd9 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,7 +6,7 @@ /* By: iyahoui- Date: Wed, 27 Apr 2022 23:46:05 -0400 Subject: [PATCH 23/32] Fixed delta_insert --- Makefile | 3 +-- src/cherrypick.c | 5 ++--- src/delta_insert.c | 17 ++--------------- src/init.c | 8 ++++---- src/insert.c | 4 ++-- src/insert_blocks_utils.c | 4 ++-- src/partition_leaving_vals.c | 4 ++-- src/push_swap.c | 4 ++-- 8 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 5890453..fe8cc9c 100644 --- a/Makefile +++ b/Makefile @@ -48,8 +48,7 @@ CFILES = block_utils.c \ split_in_two.c \ split_in_two_utils.c \ sx.c \ - undo_moves.c \ - utils.c + undo_moves.c CFILES_BONUS = checker_bonus.c \ deques.c \ diff --git a/src/cherrypick.c b/src/cherrypick.c index 8f61d2f..f7d5e2a 100644 --- a/src/cherrypick.c +++ b/src/cherrypick.c @@ -6,7 +6,7 @@ /* By: iyahoui- max_elem * sizeof(t_deque *)); - ft_bzero(list, stack->max_elem); + list = ft_xalloc(stack->max_elem * sizeof(t_deque *)); new_deque(&list[0]); list[0]->add_last(list[0], stack->elems[0]); list_size = longest_increasing_subsequence(list, stack); diff --git a/src/delta_insert.c b/src/delta_insert.c index b84d4cb..fedcdd3 100644 --- a/src/delta_insert.c +++ b/src/delta_insert.c @@ -6,7 +6,7 @@ /* By: iyahoui- a_info.pos, cont->stack_a.size, 1); - iterate_once(iter, 1); - delta_insert = calc_delta_two_values( - cont, - cont->stack_a.elems[iter->index], - cont->stack_b.elems[iter->index]); - delta_insert = ft_min(delta_insert, \ - calc_delta_two_values(cont, info->a_info.val, info->b_info.val)); - free(iter); - return (delta_insert); + return (calc_delta_two_values(cont, info->a_info.val, info->b_info.val)); } diff --git a/src/init.c b/src/init.c index 30e5d9f..820eb96 100644 --- a/src/init.c +++ b/src/init.c @@ -6,7 +6,7 @@ /* By: iyahoui- initial_stack); init_deque(&cont->staying_vals); init_deque(&cont->leaving_vals); - cont->reverse_fcts = ft_safealloc(11 * sizeof(void *)); + cont->reverse_fcts = ft_xalloc(11 * sizeof(void *)); + init_reverse_moves_array(cont->reverse_fcts); i = -1; while (args[++i] != NULL) if (cont->stack_a.add_last(&cont->stack_a, ft_atoi(args[i]))) @@ -34,7 +35,6 @@ void init(t_main_cont *cont, char **args) set_iterator(&cont->head_a, get_pos_smallest_val(&cont->stack_a), cont->stack_a.size, 0); set_iterator(&cont->head_b, 0, 0, 1); - init_reverse_moves_array(cont->reverse_fcts); cont->min_nb_moves = INT_MAX; return ; } @@ -62,7 +62,7 @@ void normalize_stack_values(t_deque *stack) int pos_in_stack; int i; - normalized_stack = ft_safealloc(stack->size * sizeof(int)); + normalized_stack = ft_xalloc(stack->size * sizeof(int)); pos_in_stack = 0; while (pos_in_stack < stack->size) { diff --git a/src/insert.c b/src/insert.c index 47d6be3..1df7122 100644 --- a/src/insert.c +++ b/src/insert.c @@ -6,7 +6,7 @@ /* By: iyahoui- stack_b.size <= 0) return ; - info = ft_safealloc(sizeof(t_insert_info)); + info = ft_xalloc(sizeof(t_insert_info)); info->b_info.pos = 0; info->min_cost = 1000; info->min_delta_insert = 1000; diff --git a/src/insert_blocks_utils.c b/src/insert_blocks_utils.c index e891017..6c5753d 100644 --- a/src/insert_blocks_utils.c +++ b/src/insert_blocks_utils.c @@ -6,7 +6,7 @@ /* By: iyahoui- min_cost = INT_MAX; info->min_delta_insert = INT_MAX; info->b_info.pos = 0; diff --git a/src/partition_leaving_vals.c b/src/partition_leaving_vals.c index a756c04..587c083 100644 --- a/src/partition_leaving_vals.c +++ b/src/partition_leaving_vals.c @@ -6,7 +6,7 @@ /* By: iyahoui- size * sizeof(int)); + temp_array = ft_xalloc(leaving_vals->size * sizeof(int)); ft_memset(temp_array, -1, leaving_vals->size * 4); i = 0; while (i < leaving_vals->size) diff --git a/src/push_swap.c b/src/push_swap.c index 509912b..93a0cb4 100644 --- a/src/push_swap.c +++ b/src/push_swap.c @@ -6,7 +6,7 @@ /* By: iyahoui- best_moves); From ceb30de21194e04b4fa3f936e465630105cfa057 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Thu, 28 Apr 2022 01:05:58 -0400 Subject: [PATCH 24/32] Unfucked the bonus, but found worse My gnl does not seem to return any of the last blank characters at the end of a file... --- Makefile | 3 +- checker_bonus | Bin 57424 -> 57864 bytes include/push_swap_bonus.h | 1 - src/checker_bonus.c | 65 +++++++++++++++++++++++--------------- src/parse.c | 2 +- src/parse_bonus.c | 29 +++++++++-------- 6 files changed, 57 insertions(+), 43 deletions(-) diff --git a/Makefile b/Makefile index fe8cc9c..b434247 100644 --- a/Makefile +++ b/Makefile @@ -61,8 +61,7 @@ CFILES_BONUS = checker_bonus.c \ rx_bonus.c \ rrx_bonus.c \ sx_bonus.c \ - undo_moves.c \ - utils.c + undo_moves.c HFILES = push_swap.h \ deques.h diff --git a/checker_bonus b/checker_bonus index 738bb017abd187cf24b34f0fd36cf11236ecf2e5..d775fd2c9b7365c418245e4b5c95c87e4aef544b 100755 GIT binary patch literal 57864 zcmeHwdwf*Yz3-YlAc8nU8!fF`Mhq6TO48z$lyIDpjO<8)Q9!v>+$58UiG)l#4+J$3 z?<76hY$G|Xw%mG7o1W8Swdc{Co|gJLn1CfwtH#IGv_6O}%1qHRDi;G%=6rwaF|%h9 zDeC8bKKGBkKi#v}cdhk%tnd1*$6nje=Z?L5Vk%>fe8yNFZWr$HLdLq78!5)Vh+D(0 z>$ToxzHj=jy_#~fFGn_<6p@~JFre$Jd}~%^SK;!W>^vqhTw!!ik;S?m32cf;fJd&r zwpnNl^8ZvK>JTo-R4343g}NS&MC-%ptXzHHTq5*U$QlYOfg-6d;~(kMn*uFufef0gpsU{F6-qY6v|NP-dsJZoKSs_>7>3<{JE6WL6uPogt&~<;XHLR>p^p9OG^pz?l zz*+pMeEHP%XzQ)btqpo}Yh#e>&+gw+sqYC{pKz{ER+SVdJGh=o?<%jp^y(EWMYMQ? zUn(wgpA^4zQ{Phz>-x>XOe+abuCEAn`Q;Jv67hJOrU0Jg*CHqvdMpJUIer22%Of7j zFM86Y>n(M9c=Lw(V2j=s34N@-T2Y-*v?^K3!dPX~DIqUiZ>WpZDKyc)+798LYA0c< zzKo3V%QGa4r9Ta%-Yq^$agf9sW*KdP%%EcaDbiQZ&vAcr?#x{BtAC+V^3L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mia;(qXZjQ70=)R!qbNmL!`nKG`u|6CB;JBG@+ffzc3ag(( zziIm?ibu7pF2AIXMzV$8Om>;9$PLB1H>vtUMXVw;m{V4Pu_%W^!;|`zU zIK*+L+<1m+JaBQEXwV%UrjN=6yXWyX7mx}mfy&Aw|jj@U==r@;Aj`e%fI*#=dc>~A# zHrv3lzT@xUSl^lcz_FDl>C+_7WZ)leG_?|V}0?yqs#fKJr0cK_^16o?T7K! zyh{F6KYUi|$M~@yW`BLU9$yMR8@^P06Yve-x5j^(DlWSG1of2q_%l|eeAVnJ%1QPf zRY~pPinkLU(b~&KquGO#zH-t{hjyhTt8aYmbRa*U^`|XOCkmoves_fcts[convert_move_to_index(move)](checker); } free(curr_line); - curr_line = get_next_line(STDIN_FILENO); + curr_line = get_next_line(fd); + } + char c; + if (read(fd, &c, 1)) + { + printf("Error, char = %c\n", c); } + close(fd); return ; } @@ -101,11 +116,11 @@ int main(int argc, char *argv[]) t_checker *checker; int i; - if (argc < 2) + if (argc < 3) exit(EXIT_SUCCESS); checker = ft_xalloc(sizeof(t_checker)); parse_bonus(checker, argc, argv); - do_moves(checker); + do_moves(checker, argv[2]); i = 0; printf("back in main\n"); while (++i < checker->stack_a.size) diff --git a/src/parse.c b/src/parse.c index c7befd9..9e9d90c 100644 --- a/src/parse.c +++ b/src/parse.c @@ -6,7 +6,7 @@ /* By: iyahoui- Date: Sat, 30 Apr 2022 18:56:54 -0400 Subject: [PATCH 25/32] Fixed bonus I ended up having to rewrite a get_next_line from scratch, but I did and it works. It's a simplified version that would not necessarily work with long files, but it can read *up to* buff_size --- Makefile | 2 + checker_bonus | Bin 57864 -> 0 bytes include/push_swap_bonus.h | 28 +++++++++++--- src/checker_bonus.c | 75 +++++++------------------------------- src/checker_utils_bonus.c | 38 +++++++++++++++++++ src/ft_read_line.c | 37 +++++++++++++++++++ 6 files changed, 114 insertions(+), 66 deletions(-) delete mode 100755 checker_bonus create mode 100644 src/checker_utils_bonus.c create mode 100644 src/ft_read_line.c diff --git a/Makefile b/Makefile index b434247..eb884fc 100644 --- a/Makefile +++ b/Makefile @@ -51,11 +51,13 @@ CFILES = block_utils.c \ undo_moves.c CFILES_BONUS = checker_bonus.c \ + checker_utils_bonus.c \ deques.c \ deque_modify.c \ deque_operators.c \ deque_utils.c \ errors.c \ + ft_read_line.c \ px_bonus.c \ parse_bonus.c \ rx_bonus.c \ diff --git a/checker_bonus b/checker_bonus deleted file mode 100755 index d775fd2c9b7365c418245e4b5c95c87e4aef544b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 57864 zcmeHwdwf*Yz3-YlAc8nU8!fF`Mhq6TO48z$lyIDpjO<8)Q9!v>+$58UiG)l#4+J$3 z?<76hY$G|Xw%mG7o1W8Swdc{Co|gJLn1CfwtH#IGv_6O}%1qHRDi;G%=6rwaF|%h9 zDeC8bKKGBkKi#v}cdhk%tnd1*$6nje=Z?L5Vk%>fe8yNFZWr$HLdLq78!5)Vh+D(0 z>$ToxzHj=jy_#~fFGn_<6p@~JFre$Jd}~%^SK;!W>^vqhTw!!ik;S?m32cf;fJd&r zwpnNl^8ZvK>JTo-R4343g}NS&MC-%ptXzHHTq5*U$QlYOfg-6d;~(kMn*uFufef0gpsU{F6-qY6v|NP-dsJZoKSs_>7>3<{JE6WL6uPogt&~<;XHLR>p^p9OG^pz?l zz*+pMeEHP%XzQ)btqpo}Yh#e>&+gw+sqYC{pKz{ER+SVdJGh=o?<%jp^y(EWMYMQ? zUn(wgpA^4zQ{Phz>-x>XOe+abuCEAn`Q;Jv67hJOrU0Jg*CHqvdMpJUIer22%Of7j zFM86Y>n(M9c=Lw(V2j=s34N@-T2Y-*v?^K3!dPX~DIqUiZ>WpZDKyc)+798LYA0c< zzKo3V%QGa4r9Ta%-Yq^$agf9sW*KdP%%EcaDbiQZ&vAcr?#x{BtAC+V^3LUsp_ z$pO@%dU#@Jr!O~fH_!ukCgD&X(o{Zn2UeH-O;FUEZy>R5S2R@U{< zD~z3)l_S6zc(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58#*PmqH3kR70(0H)I%cu9g2}QXsBZ!LgqNM+=;AY8$^1)g`bgcq3HWl>)GE=4Y40ne}*WRemcVV z8K9ru2-om1s_mK@W_wU=AcFiP{R~9$)4vhsd6cp@r?$%QcpLRPZYB9mRAn;;On-iD ze_qnz>2QqX_2t#}BhLVE29TmU^l~eqDl}u?s|cCCW=In956Vci^Ur z@Cy8N5Wq#4Wdpu8Txjx0F|y>XW<&H(g5J!;!!wUn}LmC*>7Z@-9l?Qu0>Z zAj_ycxBvbg`WmP}UjGbC{kQw{?EYK#RiXP$XjM6;|?nl)yy~lDA@#@A#T1 z`=yjunCh3{?!`@)lDA@#cYR%y?UnKhD|zdDNA|6l_+28 zc%3YMYo+{iQeNRxmG6-9uSt1@mAsWNvTw!2-++`)NO^^od~FVYR(vx4jzFK4KL_^i zlkw-mn>X3I9OV>$3M>16jX#f+_ept$PgTB6%3mYp6;|@r_7Z+eR{O1|BzDX7 z;AM$xWxT&3u{tk#UzN`h{vVfE&EGica%ANPg0FT#DQb*bfUrcZLl zuKUv`pqZpR%~XfudRraKr0X;3kR?B4%@0}XWL3(pWvLdns0v$Dg~L!~IknaO!O6~I zk)1xR6^FJu9X*RvSxW{#HSosfs)TA3FLWKOEnS^U5{%U&qJ^Q z+Xkh@hYg;Jgy=(rOlH1P$PD^aA(O3^daZtZap3vlGY2K*2NFH|^9>Hpal$W-wMANd zZ-6`MV+1}n5z(1%ItaeZSvWp1;dmThlhS9~>Wo__(l|MpFC_TpCBL8OVft30^KU?s zL7rBJ)bcx+_yWecV(P1x_}-Q39dKziY`aS`$9A@z&FKE1fgPxv0lLingwY zDB8@wmhoCVQ&iKr9(-BbNay(33|@kmB7PRE4&xKhg68msx5|sP>av3 zA&leDXJLh6S1N(KmNAtxqh_YgldJ~9t!SjVPhx1nN{Y~b)ZEaW4 diff --git a/include/push_swap_bonus.h b/include/push_swap_bonus.h index 42413c3..b350a71 100644 --- a/include/push_swap_bonus.h +++ b/include/push_swap_bonus.h @@ -1,9 +1,13 @@ #ifndef PUSH_SWAP_BONUH_H # define PUSH_SWAP_BONUH_H -#include "../libft/libft.h" -#include "deques.h" +# include "../libft/libft.h" +# include "deques.h" + +# ifndef BUFFSIZE +# define BUFFSIZE 4194304 +# endif typedef enum e_moves_to_indices { SA_INDEX = 0, @@ -19,6 +23,8 @@ typedef enum e_moves_to_indices PB_INDEX = 10 } t_moves_to_indices; + + typedef struct s_checker t_checker; typedef struct s_checker { @@ -27,14 +33,29 @@ typedef struct s_checker void (**moves_fcts)(t_checker *); } t_checker; +typedef struct s_read_info +{ + char *buff; + char *mem_space; + char *line; + int line_len; + int nb_bytes_read; +} t_read_info; + // checker_bonus.c void set_moves_pointers(void (**array)(t_checker *)); +void do_moves(t_checker *checker, char *file); + +// checker_utils_bonus.c +void bonus_exit_on_err(t_checker *checker, char *curr_line, int fd); void init_bonus(t_checker *checker, char **args); void free_checker(t_checker *checker); // parse_bonus.c void parse_bonus(t_checker *checker, int argc, char *argv[]); +// ft_read_line.c +char *read_line(int fd); // moves void rotate(t_deque *stack); @@ -57,7 +78,4 @@ void checker_pb(t_checker *checker); // undo_moves.c int convert_move_to_index(int move); -// errors.c -void exit_on_err(char *err_message); - #endif diff --git a/src/checker_bonus.c b/src/checker_bonus.c index c2ba4a5..8106645 100644 --- a/src/checker_bonus.c +++ b/src/checker_bonus.c @@ -16,21 +16,7 @@ void set_moves_pointers(void (**array)(t_checker *)) return ; } -void init_bonus(t_checker *checker, char **args) -{ - int i; - - init_deque(&checker->stack_a); - init_deque(&checker->stack_b); - checker->moves_fcts = ft_xalloc(11 * sizeof(void *)); - i = -1; - while (args[++i] != NULL) - checker->stack_a.add_last(&checker->stack_a, ft_atoi(args[i])); - set_moves_pointers(checker->moves_fcts); - return ; -} - -bool is_a_move(char *curr_line) +static bool is_a_move(char *curr_line) { int strlen; @@ -39,6 +25,8 @@ bool is_a_move(char *curr_line) return (false); if (curr_line[strlen - 1] == '\n') strlen--; + else + return (false); if (!ft_strncmp(curr_line, "rr", strlen) || !ft_strncmp(curr_line, "ra", strlen) || !ft_strncmp(curr_line, "rb", strlen) @@ -63,54 +51,25 @@ void do_moves(t_checker *checker, char *file) int fd; fd = open(file, O_RDONLY); - - curr_line = get_next_line(fd); - write(1, "entered do_moves\n", 17); - printf("entered do_moves (printf)\n"); + curr_line = read_line(fd); line_number = 0; while (curr_line) { line_number++; - printf("Reached line #%d\n", line_number); - printf("line: \"%s\"\n", curr_line); if (!is_a_move(curr_line)) - { - free(curr_line); - return ; - } - else - { - move = 0; - i = 0; - while (curr_line[i] && curr_line[i] != '\n') - { - move = (move << 8) | curr_line[i]; - i++; - } - printf("move_to_index = %d\n", convert_move_to_index(move)); - checker->moves_fcts[convert_move_to_index(move)](checker); - } + bonus_exit_on_err(checker, curr_line, fd); + move = 0; + i = 0; + while (curr_line[i] && curr_line[i] != '\n') + move = (move << 8) | curr_line[i++]; + checker->moves_fcts[convert_move_to_index(move)](checker); free(curr_line); - curr_line = get_next_line(fd); - } - char c; - if (read(fd, &c, 1)) - { - printf("Error, char = %c\n", c); + curr_line = read_line(fd); } close(fd); return ; } -void free_checker(t_checker *checker) -{ - checker->stack_a.free_list(&checker->stack_a); - checker->stack_b.free_list(&checker->stack_b); - free(checker->moves_fcts); - free(checker); - return ; -} - int main(int argc, char *argv[]) { t_checker *checker; @@ -122,22 +81,16 @@ int main(int argc, char *argv[]) parse_bonus(checker, argc, argv); do_moves(checker, argv[2]); i = 0; - printf("back in main\n"); while (++i < checker->stack_a.size) { if (checker->stack_a.elems[i] < checker->stack_a.elems[i - 1]) { - printf("checker found to not be sorted\n"); - printf("\n"); write(STDOUT_FILENO, "KO\n", 3); - break ; + free_checker(checker); + return (0); } } - if (i == checker->stack_a.size) - { - printf("checker found to be sorted"); - write(STDOUT_FILENO, "OK\n", 3); - } + write(STDOUT_FILENO, "OK\n", 3); free_checker(checker); return (0); } diff --git a/src/checker_utils_bonus.c b/src/checker_utils_bonus.c new file mode 100644 index 0000000..02fe7c1 --- /dev/null +++ b/src/checker_utils_bonus.c @@ -0,0 +1,38 @@ +#include "push_swap_bonus.h" + +void init_bonus(t_checker *checker, char **args) +{ + int i; + + init_deque(&checker->stack_a); + init_deque(&checker->stack_b); + checker->moves_fcts = ft_xalloc(11 * sizeof(void *)); + i = -1; + while (args[++i] != NULL) + checker->stack_a.add_last(&checker->stack_a, ft_atoi(args[i])); + set_moves_pointers(checker->moves_fcts); + return ; +} + +void bonus_exit_on_err(t_checker *checker, char *curr_line, int fd) +{ + free(curr_line); + curr_line = read_line(fd); + while (curr_line) + { + free(curr_line); + curr_line = read_line(fd); + } + free_checker(checker); + ft_putstr_fd("Error\n", STDERR_FILENO); + exit (255); +} + +void free_checker(t_checker *checker) +{ + checker->stack_a.free_list(&checker->stack_a); + checker->stack_b.free_list(&checker->stack_b); + free(checker->moves_fcts); + free(checker); + return ; +} diff --git a/src/ft_read_line.c b/src/ft_read_line.c new file mode 100644 index 0000000..a26c41a --- /dev/null +++ b/src/ft_read_line.c @@ -0,0 +1,37 @@ +#include "push_swap_bonus.h" + +static void free_read_vars(t_read_info *info) +{ + free(info->mem_space); + info->buff = NULL; + info->mem_space = NULL; +} + +char *read_line(int fd) +{ + static t_read_info info; + + info.line = NULL; + if (!info.buff) + { + info.mem_space = ft_xalloc(BUFFSIZE); + info.buff = info.mem_space; + info.nb_bytes_read = read(fd, info.buff, BUFFSIZE); + } + else + info.nb_bytes_read = ft_strlen(info.buff); + if (info.nb_bytes_read > 0) + { + info.line_len = strlen_c(info.buff, '\n'); + if (info.line_len <= 0) + info.line_len = ft_strlen(info.buff); + info.line = ft_xalloc(info.line_len * sizeof(char)); + info.line = ft_strncpy(info.line, info.buff, info.line_len); + info.buff += info.line_len; + if (info.line_len == info.nb_bytes_read) + free_read_vars(&info); + return (info.line); + } + free_read_vars(&info); + return (NULL); +} From 9d833ede8eb1508ee40c4f185c007e0d91aa2a69 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Sat, 30 Apr 2022 19:20:45 -0400 Subject: [PATCH 26/32] Fixed i/o redir Next problem : prototypes in deques.h I cannot seem to find a way to declare my function prototypes properly... --- include/deques.h | 38 ++++++++++++++++++------------------- include/iterators.h | 13 ++++++++++++- include/moves.h | 35 ++++++++++++++++++++++------------ include/push_swap.h | 12 ++++++++++++ include/push_swap_bonus.h | 25 ++++++++++++++++-------- src/checker_bonus.c | 27 +++++++++++++++++--------- src/checker_utils_bonus.c | 22 ++++++++++++++------- src/ft_read_line.c | 12 ++++++++++++ src/parse_bonus.c | 40 +++++++++++++++++++++++++-------------- 9 files changed, 154 insertions(+), 70 deletions(-) diff --git a/include/deques.h b/include/deques.h index 216ea7c..0c5ce12 100644 --- a/include/deques.h +++ b/include/deques.h @@ -14,7 +14,7 @@ //VECTORS (need to learn how to properly link multiple headers in Makefile) //Learned structure from https://aticleworld.com/implement-vector-in-c/ //Decided to fuck it up of my own volition, though -typedef struct s_deque t_deque; +typedef struct s_deque t_deque; typedef struct s_deque { int *elems; @@ -25,33 +25,33 @@ typedef struct s_deque int capacity_total; int capacity_end; int capacity_front; - bool (*add_front)(t_deque *, int); - bool (*add_last)(t_deque *, int); - void (*free_list)(t_deque *); - int (*get_elem_max)(t_deque *); - int (*get_elem_min)(t_deque *); - bool (*reinit_list)(t_deque *); - void (*remove_front)(t_deque *); - void (*remove_last)(t_deque *); - bool (*resize_end)(t_deque *, int); - bool (*resize_front)(t_deque *, int); - void (*set_elem)(t_deque *, int, int); + bool (*add_front)(t_deque * deque, int val); + bool (*add_last)(t_deque *deque, int val); + void (*free_list)(t_deque *deque); + int (*get_elem_max)(t_deque *deque); + int (*get_elem_min)(t_deque *deque); + bool (*reinit_list)(t_deque *deque); + void (*remove_front)(t_deque *deque); + void (*remove_last)(t_deque *deque); + bool (*resize_end)(t_deque *deque, int val); + bool (*resize_front)(t_deque *deque, int val); + void (*set_elem)(t_deque *deque, int val); } t_deque; // deques.c -void init_deque(t_deque *deque); -bool deque_reinit_list(t_deque *deque); +void init_deque(t_deque *deque); +bool deque_reinit_list(t_deque *deque); // deque_utils.c -bool deque_resize_end(t_deque *deque, int new_size); -bool deque_resize_front(t_deque *deque, int new_size); -void deque_free_list(t_deque *deque); +bool deque_resize_end(t_deque *deque, int new_size); +bool deque_resize_front(t_deque *deque, int new_size); +void deque_free_list(t_deque *deque); int deque_get_elem_max(t_deque *deque); int deque_get_elem_min(t_deque *deque); // deque_modify.c -bool deque_add_front(t_deque *deque, int new_elem); -bool deque_add_last(t_deque *deque, int new_elem); +bool deque_add_front(t_deque *deque, int new_elem); +bool deque_add_last(t_deque *deque, int new_elem); void deque_remove_front(t_deque *deque); void deque_remove_last(t_deque *deque); void deque_set_elem(t_deque *deque, int pos, int new_value); diff --git a/include/iterators.h b/include/iterators.h index 12b94ec..21dc194 100644 --- a/include/iterators.h +++ b/include/iterators.h @@ -1,9 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* iterators.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- - //ITERATORS (still need to learn how to link headers...) # define REVERSE 1 # define CANONICAL 0 diff --git a/include/moves.h b/include/moves.h index 23c3371..9bc97b2 100644 --- a/include/moves.h +++ b/include/moves.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* moves.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- moves_fcts[convert_move_to_index(move)](checker); free(curr_line); - curr_line = read_line(fd); + curr_line = read_line(STDIN_FILENO); } - close(fd); return ; } @@ -75,11 +84,11 @@ int main(int argc, char *argv[]) t_checker *checker; int i; - if (argc < 3) + if (argc < 2) exit(EXIT_SUCCESS); checker = ft_xalloc(sizeof(t_checker)); parse_bonus(checker, argc, argv); - do_moves(checker, argv[2]); + do_moves(checker); i = 0; while (++i < checker->stack_a.size) { diff --git a/src/checker_utils_bonus.c b/src/checker_utils_bonus.c index 02fe7c1..c2e8a4c 100644 --- a/src/checker_utils_bonus.c +++ b/src/checker_utils_bonus.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* checker_utils_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- Date: Sat, 30 Apr 2022 19:33:34 -0400 Subject: [PATCH 27/32] Norminetted all but deques.h I cannot seem to find a way to declare my function pointers that does not mess with norminette --- include/deques.h | 16 ++++++++++++-- include/push_swap.h | 53 +++++++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/include/deques.h b/include/deques.h index 0c5ce12..59536eb 100644 --- a/include/deques.h +++ b/include/deques.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deques.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- Date: Sun, 1 May 2022 07:12:07 -0400 Subject: [PATCH 28/32] Still can't fix norminette --- include/deques.h | 25 +++++++++++++------------ include/push_swap.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/deques.h b/include/deques.h index 59536eb..1debdc0 100644 --- a/include/deques.h +++ b/include/deques.h @@ -6,7 +6,7 @@ /* By: iyahoui- Date: Sun, 1 May 2022 16:36:03 -0400 Subject: [PATCH 29/32] It is fixed ! So I figured out what the norminette fuckup was : it does not accept multi-variable function pointer declaration when the return type was not standard (in my case, bool). Switching the return types of the 4 affected functions should do it add_front add_last resize_end resize_front (should add reinit_list for coherence purposes) --- include/deques.h | 23 +++++------------------ include/push_swap.h | 9 +++------ src/checker_bonus.c | 2 +- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/include/deques.h b/include/deques.h index 1debdc0..5228804 100644 --- a/include/deques.h +++ b/include/deques.h @@ -1,15 +1,3 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* deques.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: iyahoui- Date: Sun, 1 May 2022 20:49:14 -0400 Subject: [PATCH 30/32] Finally finished cleaning up Might want to lighten libft by only moving some items, but otherwise done --- 5_permutations.txt | 120 --- 5_permutations_post_pb.txt | 51 - Makefile | 12 +- REMINDER | 44 - backup/diff_algo.log | 80 -- backup/make_moves.c | 25 - backup/moves.c | 47 - backup/no_try_pb.log | 249 ----- backup/normalize.c | 30 - backup/print_utils.c | 69 -- backup/push_swap_no_try_pb | Bin 56152 -> 0 bytes backup/push_swap_no_try_pb_debug | Bin 56624 -> 0 bytes backup/push_swap_try_pb | Bin 56152 -> 0 bytes backup/push_swap_try_pb_debug | Bin 56624 -> 0 bytes backup/results_5.log | 964 ------------------ backup/sort.c | 127 --- backup/sort_5.c | 262 ----- backup/sort_big.c | 8 - backup/try_pb.log | 245 ----- backup/vectors.c | 86 -- include/deques.h | 33 +- include/push_swap.h | 2 +- src/calc_insert_cost.c | 2 +- src/delta_insert.c | 3 +- src/deque_modify.c | 28 +- src/deque_operators.c | 2 +- src/deque_utils.c | 14 +- src/deques.c | 6 +- src/init.c | 5 +- src/iterators.c | 2 +- src/{cherrypick_utils.c => lis_utils.c} | 4 +- ...{cherrypick.c => longest_increas_subseq.c} | 0 tester100.sh | 91 -- tester5.sh | 89 -- tester500.sh | 91 -- 35 files changed, 53 insertions(+), 2738 deletions(-) delete mode 100644 5_permutations.txt delete mode 100644 5_permutations_post_pb.txt delete mode 100644 REMINDER delete mode 100644 backup/diff_algo.log delete mode 100644 backup/make_moves.c delete mode 100644 backup/moves.c delete mode 100644 backup/no_try_pb.log delete mode 100644 backup/normalize.c delete mode 100644 backup/print_utils.c delete mode 100755 backup/push_swap_no_try_pb delete mode 100755 backup/push_swap_no_try_pb_debug delete mode 100755 backup/push_swap_try_pb delete mode 100755 backup/push_swap_try_pb_debug delete mode 100644 backup/results_5.log delete mode 100644 backup/sort.c delete mode 100644 backup/sort_5.c delete mode 100644 backup/sort_big.c delete mode 100644 backup/try_pb.log delete mode 100644 backup/vectors.c rename src/{cherrypick_utils.c => lis_utils.c} (91%) rename src/{cherrypick.c => longest_increas_subseq.c} (100%) delete mode 100755 tester100.sh delete mode 100755 tester5.sh delete mode 100755 tester500.sh diff --git a/5_permutations.txt b/5_permutations.txt deleted file mode 100644 index 8add09f..0000000 --- a/5_permutations.txt +++ /dev/null @@ -1,120 +0,0 @@ -1: 0 1 2 3 4 -2: 0 1 2 4 3 -3: 0 1 3 2 4 -4: 0 1 3 4 2 -5: 0 1 4 2 3 -6: 0 1 4 3 2 -7: 0 2 1 3 4 -8: 0 2 1 4 3 -9: 0 2 3 1 4 -10: 0 2 3 4 1 -11: 0 2 4 1 3 -12: 0 2 4 3 1 -13: 0 3 1 2 4 -14: 0 3 1 4 2 -15: 0 3 2 1 4 -16: 0 3 2 4 1 -17: 0 3 4 1 2 -18: 0 3 4 2 1 -19: 0 4 1 2 3 -20: 0 4 1 3 2 -21: 0 4 2 1 3 -22: 0 4 2 3 1 -23: 0 4 3 1 2 -24: 0 4 3 2 1 -25: 1 0 2 3 4 -26: 1 0 2 4 3 -27: 1 0 3 2 4 -28: 1 0 3 4 2 -29: 1 0 4 2 3 -30: 1 0 4 3 2 -31: 1 2 0 3 4 -32: 1 2 0 4 3 -33: 1 2 3 0 4 -34: 1 2 3 4 0 -35: 1 2 4 0 3 -36: 1 2 4 3 0 -37: 1 3 0 2 4 -38: 1 3 0 4 2 -39: 1 3 2 0 4 -40: 1 3 2 4 0 -41: 1 3 4 0 2 -42: 1 3 4 2 0 -43: 1 4 0 2 3 -44: 1 4 0 3 2 -45: 1 4 2 0 3 -46: 1 4 2 3 0 -47: 1 4 3 0 2 -48: 1 4 3 2 0 -49: 2 0 1 3 4 -50: 2 0 1 4 3 -51: 2 0 3 1 4 -52: 2 0 3 4 1 -53: 2 0 4 1 3 -54: 2 0 4 3 1 -55: 2 1 0 3 4 -56: 2 1 0 4 3 -57: 2 1 3 0 4 -58: 2 1 3 4 0 -59: 2 1 4 0 3 -60: 2 1 4 3 0 -61: 2 3 0 1 4 -62: 2 3 0 4 1 -63: 2 3 1 0 4 -64: 2 3 1 4 0 -65: 2 3 4 0 1 -66: 2 3 4 1 0 -67: 2 4 0 1 3 -68: 2 4 0 3 1 -69: 2 4 1 0 3 -70: 2 4 1 3 0 -71: 2 4 3 0 1 -72: 2 4 3 1 0 -73: 3 0 1 2 4 -74: 3 0 1 4 2 -75: 3 0 2 1 4 -76: 3 0 2 4 1 -77: 3 0 4 1 2 -78: 3 0 4 2 1 -79: 3 1 0 2 4 -80: 3 1 0 4 2 -81: 3 1 2 0 4 -82: 3 1 2 4 0 -83: 3 1 4 0 2 -84: 3 1 4 2 0 -85: 3 2 0 1 4 -86: 3 2 0 4 1 -87: 3 2 1 0 4 -88: 3 2 1 4 0 -89: 3 2 4 0 1 -90: 3 2 4 1 0 -91: 3 4 0 1 2 -92: 3 4 0 2 1 -93: 3 4 1 0 2 -94: 3 4 1 2 0 -95: 3 4 2 0 1 -96: 3 4 2 1 0 -97: 4 0 1 2 3 -98: 4 0 1 3 2 -99: 4 0 2 1 3 -100: 4 0 2 3 1 -101: 4 0 3 1 2 -102: 4 0 3 2 1 -103: 4 1 0 2 3 -104: 4 1 0 3 2 -105: 4 1 2 0 3 -106: 4 1 2 3 0 -107: 4 1 3 0 2 -108: 4 1 3 2 0 -109: 4 2 0 1 3 -110: 4 2 0 3 1 -111: 4 2 1 0 3 -112: 4 2 1 3 0 -113: 4 2 3 0 1 -114: 4 2 3 1 0 -115: 4 3 0 1 2 -116: 4 3 0 2 1 -117: 4 3 1 0 2 -118: 4 3 1 2 0 -119: 4 3 2 0 1 -120: 4 3 2 1 0 diff --git a/5_permutations_post_pb.txt b/5_permutations_post_pb.txt deleted file mode 100644 index 4bcd625..0000000 --- a/5_permutations_post_pb.txt +++ /dev/null @@ -1,51 +0,0 @@ -0 1 3 4[2] -0 1 4[3][2] -0 2[1]4[3] -rra-> [3] 0 1 2 4 -pb-> 0 1 2 4 | 3 [SORTED] -rra-> 4 0 1 2 | 3 -pa-> 3 4 0 1 2 -ra x 2-> 0 1 2 3 4 [DONE] -0 2 4[1][3] -0 2 4[3][1] -0 3[2][1]4 -0 4[2]3[1] -0 4[3][2][1] -[1]0 3 4[2] -[1]0 4[3][2] -[1][2]0 4 3 -- will cause problem -- -[1][2]4 0 3 -pb-> 2 4 0 3 | 1 -!in_order->-!try_swap->-pb-> 4 0 3 | 2 1 -in_order-> //insert// -rra; pa-> 2 3 4 0 | 1 -pa-> 1 2 3 4 0 -rra-> [DONE] -[1][3]0 2 4 -[1][3][2]0 4 -1 4[3][2]0 -[2]0 3 4[1] -[2]0 4[3][1] -try_pb->-ra; pb-> 4 3 1 2 | 0 -try_swap->-sa-> 3 4 1 2 | 0 //insert// -rax2; pa-> [DONE] (6 moves) -[2][1]0 4[3] -try_pb-> -[2][1]4 0 3 -[2][3]0 1 4 -[2][3][1]0 4 -2 4[1][3]0 -try_pb->-pb-> 4 1 3 0 | 2 -try_swap->-rra; sa-> 4 0 1 3 | 2 //insert// -rra; pa-> 2 3 4 0 1 -rra x 2-> [DONE] (7 moves) -2 4[3][1]0 -[3]0 2 4[1] -[3]0 4[2][1] -[3][1]0 4[2] -pb-> 1 0 4 2 | 3 -!in_order->-!try_swap->-push_next_b->-rra; pb-> 0 1 4 | 2 3 //insert// -rrr; pa-> 3 4 0 1 | 2 -pa-> 2 3 4 0 1 -rra x2-> [DONE] (8 moves) -[3][1]0 4[2] -try_pb(for each pb, try_swap)->-ra; pb-> 0 4 2 3 | 1 -sa-> 4 0 2 3 | 1 //insert// -ra x2; pa-> 1 2 3 4 0 -rra-> [DONE] (7 moves) -3[1]4 0 2 -[3][2]0 1 4 -[3][2][1]0 4 -3 4[1][2]0 -3 4[2][1]0 -4 0 2 3[1] -4 0 3[2][1] -4[1]0 3[2] -//4[1][3]0 2 -rra x2; pb-> 2 4 1 3 | 0 -rra x 2; pb-> 2 4 3 | 1 0 -sa; ra-> 2 3 4 | 1 0 -pb x 2-> [DONE] (10 moves) -//4[1][3]0 2 -pb-> 1 3 0 2 | 4 -!in_order->-!try_swap->-pb-> 3 0 2 | 1 4 -in_order-> //insert// -rra; pa-> 1 2 3 0 | 4 -ra; pa-> 4 0 1 2 3 -ra-> [DONE] (6 moves) -4[1][3]0 2 -try_pb->-ra; pb-> 3 0 2 4 | 1 -try_swap->-rra; sa-> 3 4 0 2 | 1 //insert// -rra; pa-> 1 2 3 4 0 -rra-> [DONE] (7 moves) -4[2]0 1 3 -try_pb->-pb-> 2 0 1 3 | 4 -try_swap->-rra; sa-> 2 3 0 1 | 4 //insert// -ra x2; pa-> 4 0 1 2 3 -ra-> [DONE] (7 moves) -//4[2][1]0 3 -ra-> [2][1] 0 3 4 -pb-> [1] 0 3 4 | 2 -!in_order->try_swap->-sa-> 0 1 3 4 | 2 //insert// -ra x2-> 3 4 0 1 | 2 -pa-> 2 3 4 0 1 -rra x 2-> [DONE] (8 moves) -//4[2][1]0 3 -pb-> [2][1] 0 3 | 4 -!in_order->!try_swap->--pb-> 1 0 3 | 2 4 -!in_order->sa-> 0 1 3 | 2 4 //insert// -rra; pa -> 2 3 0 1 | 4 --ra x 2; pa-> 4 0 1 2 3 -ra-> [DONE] (9 moves) -//4[2][1]0 3 -ra; pb x 2-> 0 3 4 | 1 2 -in_order-> //insert// -ra; pa-> 1 3 4 0 | 2 -ra pa -> 2 3 4 0 1 -rra x2-> [DONE] (9 moves) -4[2][1]0 3 -pb x 2-> 1 0 3 | 2 4 -!in_order->-sa-> 0 1 3 | 2 4 //insert// -rra; pa-> 2 3 0 1 | 4 -ra x2; pa-> 4 0 1 2 3 -ra->[DONE] (9 moves) -4[3][1][2]0 -//4[3][2][1]0 -pb-> 3 2 1 0 | 4 -!in_order->!try_swap->--pb-> 2 1 0 | 3 4 -!in_order->sa-> 1 2 0 | 3 4 //insert// -ra; pa-> 3 0 1 2 -ra; pa-> 4 0 1 2 3 -ra-> [DONE] (8 moves) -//4[3][2][1]0 -ra; pb-> 2 1 0 4 | 3 -!in_order->!try_swap->--pb-> 1 0 4 | 2 3 -!in_order->-sa-> 0 1 4 | 2 3 //insert// -rra; pa-> 2 4 0 1 | 3 -ra; pa-> 3 4 0 1 2 -rra x2-> [DONE] (10 moves) -//4[3][2][1]0 -!try_pb(for each pb, try_swap)->-pb x2-> 2 1 0 | 3 4 -sa-> 1 2 0 | 3 4 //insert// -ra; pa-> 3 0 1 2 -ra; pa-> 4 0 1 2 3 -ra-> [DONE] (8 moves) -4[3][2][1]0 -pb; sa-> 2 3 1 0 | 4 -ra x2; sa-> 0 1 2 3 -pa-> 4 0 1 2 3 -ra-> [DONE] (7 moves) - -[Legend] -[]: out of place in stack, meaning it is not bigger than the biggest previous one. diff --git a/Makefile b/Makefile index eb884fc..f72cecc 100644 --- a/Makefile +++ b/Makefile @@ -16,8 +16,6 @@ RESET_COL = \033[0m CFILES = block_utils.c \ calc_insert_cost.c \ - cherrypick.c \ - cherrypick_utils.c \ cleanup.c \ delta_insert.c \ deques.c \ @@ -33,6 +31,8 @@ CFILES = block_utils.c \ insert_blocks_utils.c \ insert_utils.c \ iterators.c \ + longest_increas_subseq.c \ + lis_utils.c \ parse.c \ partition_leaving_vals.c \ partition_stack.c \ @@ -98,7 +98,7 @@ LIBFT_FLAGS = -lft -Llibft RM_OBJS = rm -rf $(OBJ_DIR) RM_OBJS_OUT = $$($(RM_OBJS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -RM_EXE = rm -f $(NAME) +RM_EXE = rm -f $(NAME) $(NAME_BONUS) RM_EXE_OUT = $$($(RM_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') RM_LIBFT = make clean -sC ./libft RM_LIBFT_OUT = $$($(RM_LIBFT) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') @@ -117,7 +117,7 @@ COMPILE_C_BONUS_OUT = $$($(COMPILE_C_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31me $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR) - @printf "$(CYAN)%-30s-->%30s $(RESET_COL)$(COMPILE_C_OUT)\n" $^ $@ + @printf "$(CYAN)%-32s-->%32s $(RESET_COL)$(COMPILE_C_OUT)\n" $^ $@ # # DEBUG MACROS @@ -126,7 +126,7 @@ COMPILE_DBG_EXE = $(CC) $(DBG_CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(DBG_OBJS) - COMPILE_DBG_EXE_OUT = $$($(COMPILE_DBG_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') COMPILE_DBGC = $(CC) $(DBG_CFLAGS) $(INCLFLAGS) -o $@ -c $< COMPILE_DBGC_OUT = $$($(COMPILE_DBGC) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -RM_DBG_EXE = rm $(DBG_EXE) +RM_DBG_EXE = rm -f $(DBG_EXE) RM_DBG_EXE_OUT = $$($(RM_DBG_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') $(DBG_DIR)/%.o: $(SRC_DIR)/%.c @@ -149,7 +149,7 @@ $(NAME_BONUS): libft $(OBJS_BONUS) @echo -e "\n$(CYAN)>>>>>>>> Compiling $(NAME_BONUS) ...$(RESET_COL)$(COMPILE_EXE_BONUS_OUT)" silent_libft: - @echo -e "---------------------- libft.a ----------------------\n" + @echo -e "---------------------- libft ----------------------\n" @echo -e "$(CYAN)>>>>>>>> Archiving libft.a ...$(RESET_COL)" @make -s bonus -C $(LIBFT_DIR) @if [ -e $(LIBFT) ]; \ diff --git a/REMINDER b/REMINDER deleted file mode 100644 index 0287710..0000000 --- a/REMINDER +++ /dev/null @@ -1,44 +0,0 @@ - ___ | - / _ \ | -| (_) | | - \___/ | - _ __ | __ _ -| '_ \ | / _` | -| | | | | | (_| | -|_| |_| | \__,_| - ___ | _ - / _ \ | | | -| __/ | | |_ - \___| | | __| - | | |_ - _ | \__| - | | | - | |_ | - | __| | __ _ - | |_ | / _` | - \__| | | (_| | - __ _ | \__,_| - / _` | | -| (_| | | - \__,_| | _ - ___ | | | - / __| | | |_ - \__ \ | | __| - |___/ | | |_ - _ | \__| -| | | _ -| | __ | (_) -| |/ / | _ -| < | | | -|_|\_\ | | | - | |_| - | - | _ __ ___ - | | '_ ` _ \ - | | | | | | | - | |_| |_| |_| - | - | ___ - | / _ \ - | | __/ - | \___| diff --git a/backup/diff_algo.log b/backup/diff_algo.log deleted file mode 100644 index e681f4d..0000000 --- a/backup/diff_algo.log +++ /dev/null @@ -1,80 +0,0 @@ -12c12 -< 8 ---- -> 6 -34c34 -< 7 ---- -> 4 -78c78 -< 7 ---- -> 8 -86c86 -< 6 ---- -> 5 -96c96 -< 7 ---- -> 9 -98c98 -< 5 ---- -> 6 -108c108 -< 6 ---- -> 10 -144c144 -< 6 ---- -> 9 -156c156 -< 5 ---- -> 9 -160c160 -< 7 ---- -> 10 -192c192 -< 9 ---- -> 8 -204c204 -< 9 ---- -> 7 -208c208 -< 6 ---- -> 8 -222c222 -< 8 ---- -> 9 -226c226 -< 7 ---- -> 5 -242d241 -< 0 1 4 3 2 --> 8 -244a244,245 -> 1 3 2 0 4 --> 8 -> 1 4 3 2 0 --> 9 -245a247 -> 2 0 4 3 1 --> 10 -250a253 -> 2 4 3 1 0 --> 9 -252a256,257 -> 3 0 4 2 1 --> 9 -> 3 1 0 4 2 --> 10 -256,258c261,263 -< 3 4 2 1 0 --> 9 -< 4 0 3 2 1 --> 9 -< 4 2 1 0 3 --> 8 ---- -> 3 4 2 1 0 --> 8 -> 4 1 0 3 2 --> 8 -> 4 2 1 0 3 --> 9 diff --git a/backup/make_moves.c b/backup/make_moves.c deleted file mode 100644 index a6b26bb..0000000 --- a/backup/make_moves.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "push_swap.h" - -void make_rab(int **stack, int size, int move) -{ - rotate(stack, size); - print_move(move); -} - -void make_rrab(int **stack, int size, int move) -{ - rev_rotate(stack, size); - print_move(move); -} - -void make_sab(int *stack, int size, int move) -{ - swap(stack, size); - print_move(move); -} - -void make_push(t_main_cont *cont, int move) -{ - push(cont, move); - print_move(move); -} diff --git a/backup/moves.c b/backup/moves.c deleted file mode 100644 index e83d84b..0000000 --- a/backup/moves.c +++ /dev/null @@ -1,47 +0,0 @@ -#include "push_swap.h" - -void rotate(int **stack, int size) -{ - *(*stack + size) = *stack[0]; - *stack[0] = 0; - *stack += 1; - return ; -} - -void rev_rotate(int **stack, int size) -{ - *(*stack - 1) = *(*stack + size - 1); - *(*stack + size) = 0; - *stack -= 1; - return ; -} - -void swap(int *stack, int size) -{ - int temp; - - if (size <= 1) - return ; - temp = stack[0]; - stack[0] = stack[1]; - stack[1] = temp; -} - -static void private_push(int **stack_src, int **stack_dest, \ - int *size_src, int *size_dest) -{ - *(*stack_dest - 1) = *stack_src[0]; - *stack_src[0] = 0; - *size_dest += 1; - *size_src -= 1; - *stack_dest -= 1; - *stack_src += 1; -} - -void push(t_main_cont *cont, int move) -{ - if (move == PA) - private_push(&cont->B, &cont->A, &cont->sizeB, &cont->sizeA); - else if (move == PB) - private_push(&cont->A, &cont->B, &cont->sizeA, &cont->sizeB); -} diff --git a/backup/no_try_pb.log b/backup/no_try_pb.log deleted file mode 100644 index 6456109..0000000 --- a/backup/no_try_pb.log +++ /dev/null @@ -1,249 +0,0 @@ -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: OK - 4 -0 1 4 2 3: OK - 4 -0 1 4 3 2: OK - 6 -0 2 1 3 4: OK - 3 -0 2 1 4 3: OK - 7 -0 2 3 1 4: OK - 6 -0 2 3 4 1: OK - 2 -0 2 4 1 3: OK - 5 -0 2 4 3 1: OK - 6 -0 3 1 2 4: OK - 6 -0 3 1 4 2: OK - 5 -0 3 2 1 4: OK - 8 -0 3 2 4 1: OK - 4 -0 3 4 1 2: OK - 4 -0 3 4 2 1: OK - 5 -0 4 1 2 3: OK - 2 -0 4 1 3 2: OK - 6 -0 4 2 1 3: OK - 4 -0 4 2 3 1: OK - 5 -0 4 3 1 2: OK - 5 -0 4 3 2 1: OK - 7 -1 0 2 3 4: OK - 1 -1 0 2 4 3: OK - 7 -1 0 3 2 4: OK - 5 -1 0 3 4 2: OK - 6 -1 0 4 2 3: OK - 6 -1 0 4 3 2: OK - 8 -1 2 0 3 4: OK - 5 -1 2 0 4 3: OK - 7 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: OK - 5 -1 2 4 3 0: OK - 5 -1 3 0 2 4: OK - 6 -1 3 0 4 2: OK - 7 -1 3 2 0 4: OK - 8 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: OK - 7 -1 4 0 2 3: OK - 5 -1 4 0 3 2: OK - 6 -1 4 2 0 3: OK - 6 -1 4 2 3 0: OK - 7 -1 4 3 0 2: OK - 5 -1 4 3 2 0: OK - 9 -2 0 1 3 4: OK - 6 -2 0 1 4 3: OK - 7 -2 0 3 1 4: OK - 7 -2 0 3 4 1: OK - 8 -2 0 4 1 3: OK - 6 -2 0 4 3 1: OK - 10 -2 1 0 3 4: OK - 7 -2 1 0 4 3: OK - 9 -2 1 3 0 4: OK - 8 -2 1 3 4 0: OK - 2 -2 1 4 0 3: OK - 7 -2 1 4 3 0: OK - 6 -2 3 0 1 4: OK - 6 -2 3 0 4 1: OK - 4 -2 3 1 0 4: OK - 8 -2 3 1 4 0: OK - 6 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: OK - 8 -2 4 1 0 3: OK - 8 -2 4 1 3 0: OK - 7 -2 4 3 0 1: OK - 4 -2 4 3 1 0: OK - 9 -3 0 1 2 4: OK - 4 -3 0 1 4 2: OK - 8 -3 0 2 1 4: OK - 8 -3 0 2 4 1: OK - 7 -3 0 4 1 2: OK - 3 -3 0 4 2 1: OK - 9 -3 1 0 2 4: OK - 6 -3 1 0 4 2: OK - 10 -3 1 2 0 4: OK - 7 -3 1 2 4 0: OK - 6 -3 1 4 0 2: OK - 8 -3 1 4 2 0: OK - 7 -3 2 0 1 4: OK - 7 -3 2 0 4 1: OK - 6 -3 2 1 0 4: OK - 9 -3 2 1 4 0: OK - 7 -3 2 4 0 1: OK - 3 -3 2 4 1 0: OK - 8 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: OK - 6 -3 4 2 0 1: OK - 6 -3 4 2 1 0: OK - 8 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: OK - 5 -4 0 3 1 2: OK - 5 -4 0 3 2 1: OK - 7 -4 1 0 2 3: OK - 2 -4 1 0 3 2: OK - 8 -4 1 2 0 3: OK - 7 -4 1 2 3 0: OK - 3 -4 1 3 0 2: OK - 6 -4 1 3 2 0: OK - 7 -4 2 0 1 3: OK - 7 -4 2 0 3 1: OK - 6 -4 2 1 0 3: OK - 9 -4 2 1 3 0: OK - 5 -4 2 3 0 1: OK - 5 -4 2 3 1 0: OK - 6 -4 3 0 1 2: OK - 3 -4 3 0 2 1: OK - 7 -4 3 1 0 2: OK - 5 -4 3 1 2 0: OK - 6 -4 3 2 0 1: OK - 6 -4 3 2 1 0: OK - 8 -** stacks resulting in nb_moves > 8 : ** - 1 4 3 2 0 --> 9 - 2 0 4 3 1 --> 10 - 2 1 0 4 3 --> 9 - 2 4 3 1 0 --> 9 - 3 0 4 2 1 --> 9 - 3 1 0 4 2 --> 10 - 3 2 1 0 4 --> 9 - 4 2 1 0 3 --> 9 diff --git a/backup/normalize.c b/backup/normalize.c deleted file mode 100644 index e26b795..0000000 --- a/backup/normalize.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "push_swap.h" - -int *normalize_stack_values(int *src_stack, int size) -{ - int i; - int stack_pos; - int nb_smaller_elements; - int *normalized_stack; - - normalized_stack = malloc(size * sizeof(int)); - if (!normalized_stack) - exit_on_err("Malloc error\n"); - stack_pos = 0; - while (stack_pos < size) - { - i = 0; - nb_smaller_elements = 0; - while (i < size) - { - if (src_stack[i] < src_stack[stack_pos]) - nb_smaller_elements++; - i++; - } - normalized_stack[stack_pos] = nb_smaller_elements; - stack_pos++; - } - src_stack = ft_memcpy(src_stack, normalized_stack, size * sizeof(int)); - free(normalized_stack); - return (src_stack); -} diff --git a/backup/print_utils.c b/backup/print_utils.c deleted file mode 100644 index ed880a5..0000000 --- a/backup/print_utils.c +++ /dev/null @@ -1,69 +0,0 @@ -#include "push_swap.h" - -void print_single_stack(int *stack, int size) -{ - int i; - - printf(" |\033[38;5;5m [A] \033[0m|\n"); - printf("+---+-----+\n"); - i = 0; - while (i < size) - { - printf("|%-3d|", i); - if (i < size) - printf("\033[38;5;5m %-3d \033[0;0;0m|\n", stack[i]); - else - printf("\t\033[0m|\n"); - i++; - } - printf("+---+-----+\n"); -} - -void print_stacks(t_main_cont *cont) -{ - int i; - - printf(" |\033[38;5;5m [A] \033[0m|\033[38;5;6m [B] \033[0;0;0m|\n"); - printf("+---+-----+-----+\n"); - i = 0; - while (i < cont->sizeA || i < cont->sizeB) - { - printf("|%-3d|", i); - if (i < cont->sizeA) - printf("\033[38;5;5m %-3d \033[0;0;0m", cont->A[i]); - else - printf("\t\033[0m|"); - if (i < cont->sizeB) - printf("|\033[38;5;6m %-3d \033[0m|\n", cont->B[i]); - else - printf("| |\n\033[0m"); - i++; - } - printf("+---+-----+-----+\n"); -} - -void print_move(int move) -{ - if (move == RA) - write(1, "ra\n", 3); - else if (move == RB) - write(1, "rb\n", 3); - else if (move == RR) - write(1, "rr\n", 3); - else if (move == RRA) - write(1, "rra\n", 4); - else if (move == RRB) - write(1, "rrb\n", 4); - else if (move == RRR) - write(1, "rrr\n", 4); - else if (move == SA) - write(1, "sa\n", 3); - else if (move == SB) - write(1, "sb\n", 3); - else if (move == SS) - write(1, "ss\n", 3); - else if (move == PA) - write(1, "pa\n", 3); - else if (move == PB) - write(1, "pb\n", 3); -} diff --git a/backup/push_swap_no_try_pb b/backup/push_swap_no_try_pb deleted file mode 100755 index 0bf048d9f01bec988c55ef05f02167d40ca01910..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56152 zcmeHve|S{Yng5x|1V=<~tY}fwWz^t`3M3V(v&c51GjgZS01BwP8i)LtK-!RG=ZA_- zAnqi}WgJPLZWq_DE$p^Wb*-&=>VAv0yEsXZ1gIK*v<+f0tyO0X;<#80NHgEhd+s?i zcLrqfuYI2Hb8o%(p7)&h*ZG`t-gE9d4R4(IaN-=sEG3LFEABGf_mnc$%^WB(b}4QZ zcObCDwb1kTo;w#)ZQ*4pBu`6`o)Itx0?R!2EGuN;^3{cPOwe$J$(uL=fk^P72$l4! zSYIy;k-itN(%Xr)310rPu}&iy2!tcix^S+lSYN{eU0;RZkhB!A3w@JBg|08KD%ji> z456-A-+H0XC-{jb+;i6{{?&&gp{ACVf}vR7exWZe27zefRiGOUfk3q7!KRjmKvPR& zE2j&`W5w6?{yr^~5M8XpsGr95Nv_B3TILGex_Hr2eRQjJJ#rk2-!$LoCbwzM1p+Hu z4Z{lh^!n`JMZgLG{36#m-I{aIS^>B4TRUMu4`=$ zv_(RntFKZQXEeJ=hrF=17~S#;1R821wURp3zsgSCKiN;Bjr#JEdWrg}uTP(M(d{0$ zS4W?*WKlms({<0~`kQbUQ-)Vu3D0>Sl8ljUJKocHi~ewcUV>s9-YOg-e5k!_J7XvC zPVGY*I(i<;#77sJ_&o>jqqvPYfGoIrA%A{BjZR#Emjm|{+;gJg(46L`x;YJNnj1jV zMcpAkp1Sz&o9*BFn`>V9OU)~rS>J14MV$jT@1ruAO~OrOj-|cUdM(OjxaD;X`cHZ? z*U1|FO?Gd>O>N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Xrqg0k~h*M zUm@hz2zg0Mc_#_ulJZVY=`_hN74l&rFKH=XZ{R2UM*3{{t%be@Axp1r(5J&MS+4u? zD%#7TU((Wkk_x!!MfQ#K+3b%%UjvuaAETg8XTS3rUH5sVV*UzR+W#A?E-&pH>9g6t z2>Oin%RrybKAWxEzf0Jcw6xzN`XKEaX&S#CAs-a-l9uugD&UgxMw;Y%uhZMYLSE8R z{+1$nBYn31uZKQk|Kp%f*Z(o>KV)K?urFz8zlM9C_uojL&HnZx`@7Fzzv>2E_i`>pFfh8^1O2f{Eal1pQp>0NqIq^vpfO<@y?a+Bwsep@KByXfi ze(6HJ?Je1VK@&g8V|wvR${T5t?-cxL>3@-YUy;0#Ci#k6bo-wOc}YwAON-=yf_a$Bxrda*(hjvzIa;D^1S#%$&W>kB70HLW5S=G z3R=eJ0YS@n`?jRTdPoUc?k7iNyTJRHpgRTsq@d;b*Jjo6lks?(pk=(7F54IC{+0_` z#t)a|7xC0BXc?dH0u7V+zkc0YMAsD2!6JH15gjg~A1$Jf!px_*|BU+>?$2;f;69G~ zOl@dlP8K*#&Mi=wRtw1N8_)R3)5Gs3+5SDH5V& zm?%<4j2HFP887CtX8}s&<+3`QDoFY8ntZBk|zcw>-(K2GJQbSPisvpc^IzNi)M6by(Y zbHF%-_36f!S8lPKI}~{lsLv6Fd1k)W&RwO>4t4q(oPl2{5uE~%3dg>hoR7xN{sfI1?= zi~K2~h|WhBW2iDl9jd2jl#k~;Xc^*?PK)4HlyTSN;sW*sM_y-#_l2SM)LkmSC;bP1 C*c^KR diff --git a/backup/push_swap_try_pb_debug b/backup/push_swap_try_pb_debug deleted file mode 100755 index e11ba8f1ea26e1f12fb30fc3ca430668a652db7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 56624 zcmeHPeRy0|nLjg0N(kTtsaT-cDNscrZJ;es(!!MXx&x9@3Xw1C?PM}-29lX!K3dvs zG&l`rG6aIc%JQsGsn6;vE`bGESS@J_q_RqbC{WN_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{>J8AO2Q_3HKy9mvHMNd_JK*}E{EmLX?1^CBx$vueM!=^s8M7= zNvrePwUSo*|9ZtQ&lf$CR_BX56~8<`-z{l%e*clA)qUVWNvrt0Q_?ElzNF;ke6%Fp zFZYwTC9U?S_av>>??q36|YW_w2B{#B(37F}o&nrznFOX?pk7TdJhEE|g5ML)G0+cOB7h3}f6BDW}90V(xOm0q!vUyDy z@5H?D#z1Q{6|S2Xi$|{w1(S(+H0B(Rd5L&%9+NYEZg46REurSrIy2gQZDO91i!yuB zAfX?PCk|PY6oVq?F9YF7IC;pbxDXVTu4+EjX*wRdZw^tYM_HV;bWw z!j4Suo6bccCa_qrCDX%RjE9U?Q4%(7qBQN#m-HcP7E;hEBf`{XF#mnYOeMo@hdxkF zS+dK2(>Q3@;T$|j*(>7E`>EE_T-fAsm7>oftKmX41`{GJ?F0WyU?-N+&4JXZ*vB}r z@MF1TE~IYBc&L73Dx-_x&>35uVUp@8d=@t#9%UVYRM0XSm;IC?0{KGr@n(gPLMKYM Lh>5#vaWDNJ&c{KA diff --git a/backup/results_5.log b/backup/results_5.log deleted file mode 100644 index 66494e4..0000000 --- a/backup/results_5.log +++ /dev/null @@ -1,964 +0,0 @@ -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: KO - 0 -0 1 4 2 3: KO - 0 -0 1 4 3 2: KO - 0 -0 2 1 3 4: OK - 3 -0 2 1 4 3: KO - 0 -0 2 3 1 4: KO - 0 -0 2 3 4 1: OK - 2 -0 2 4 1 3: KO - 0 -0 2 4 3 1: KO - 0 -0 3 1 2 4: KO - 0 -0 3 1 4 2: KO - 0 -0 3 2 1 4: KO - 0 -0 3 2 4 1: KO - 0 -0 3 4 1 2: KO - 0 -0 3 4 2 1: KO - 0 -0 4 1 2 3: OK - 2 -0 4 1 3 2: KO - 0 -0 4 2 1 3: KO - 0 -0 4 2 3 1: KO - 0 -0 4 3 1 2: KO - 0 -0 4 3 2 1: KO - 0 -1 0 2 3 4: OK - 1 -1 0 2 4 3: KO - 0 -1 0 3 2 4: KO - 0 -1 0 3 4 2: KO - 0 -1 0 4 2 3: KO - 0 -1 0 4 3 2: KO - 0 -1 2 0 3 4: KO - 0 -1 2 0 4 3: KO - 0 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: KO - 0 -1 2 4 3 0: OK - 5 -1 3 0 2 4: KO - 0 -1 3 0 4 2: KO - 0 -1 3 2 0 4: KO - 0 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: KO - 0 -1 4 0 2 3: KO - 0 -1 4 0 3 2: KO - 0 -1 4 2 0 3: KO - 0 -1 4 2 3 0: KO - 0 -1 4 3 0 2: KO - 0 -1 4 3 2 0: KO - 0 -2 0 1 3 4: KO - 0 -2 0 1 4 3: KO - 0 -2 0 3 1 4: KO - 0 -2 0 3 4 1: KO - 0 -2 0 4 1 3: KO - 0 -2 0 4 3 1: KO - 0 -2 1 0 3 4: KO - 0 -2 1 0 4 3: KO - 0 -2 1 3 0 4: KO - 0 -2 1 3 4 0: OK - 2 -2 1 4 0 3: KO - 0 -2 1 4 3 0: KO - 0 -2 3 0 1 4: KO - 0 -2 3 0 4 1: OK - 4 -2 3 1 0 4: KO - 0 -2 3 1 4 0: KO - 0 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: KO - 0 -2 4 1 0 3: KO - 0 -2 4 1 3 0: KO - 0 -2 4 3 0 1: OK - 4 -2 4 3 1 0: KO - 0 -3 0 1 2 4: OK - 4 -3 0 1 4 2: KO - 0 -3 0 2 1 4: KO - 0 -3 0 2 4 1: KO - 0 -3 0 4 1 2: OK - 3 -3 0 4 2 1: KO - 0 -3 1 0 2 4: KO - 0 -3 1 0 4 2: KO - 0 -3 1 2 0 4: KO - 0 -3 1 2 4 0: KO - 0 -3 1 4 0 2: KO - 0 -3 1 4 2 0: KO - 0 -3 2 0 1 4: KO - 0 -3 2 0 4 1: KO - 0 -3 2 1 0 4: KO - 0 -3 2 1 4 0: KO - 0 -3 2 4 0 1: OK - 3 -3 2 4 1 0: KO - 0 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: KO - 0 -3 4 2 0 1: KO - 0 -3 4 2 1 0: KO - 0 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: KO - 0 -4 0 3 1 2: KO - 0 -4 0 3 2 1: KO - 0 -4 1 0 2 3: OK - 2 -4 1 0 3 2: KO - 0 -4 1 2 0 3: KO - 0 -4 1 2 3 0: OK - 3 -4 1 3 0 2: KO - 0 -4 1 3 2 0: KO - 0 -4 2 0 1 3: KO - 0 -4 2 0 3 1: KO - 0 -4 2 1 0 3: KO - 0 -4 2 1 3 0: KO - 0 -4 2 3 0 1: KO - 0 -4 2 3 1 0: KO - 0 -4 3 0 1 2: OK - 3 -4 3 0 2 1: KO - 0 -4 3 1 0 2: KO - 0 -4 3 1 2 0: KO - 0 -4 3 2 0 1: KO - 0 -4 3 2 1 0: KO - 0 -** stacks resulting in nb_moves > 7 : ** -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: KO - 0 -0 1 4 2 3: KO - 0 -0 1 4 3 2: KO - 0 -0 2 1 3 4: OK - 3 -0 2 1 4 3: KO - 0 -0 2 3 1 4: KO - 0 -0 2 3 4 1: OK - 2 -0 2 4 1 3: KO - 0 -0 2 4 3 1: KO - 0 -0 3 1 2 4: KO - 0 -0 3 1 4 2: KO - 0 -0 3 2 1 4: KO - 0 -0 3 2 4 1: KO - 0 -0 3 4 1 2: KO - 0 -0 3 4 2 1: KO - 0 -0 4 1 2 3: OK - 2 -0 4 1 3 2: KO - 0 -0 4 2 1 3: KO - 0 -0 4 2 3 1: KO - 0 -0 4 3 1 2: KO - 0 -0 4 3 2 1: KO - 0 -1 0 2 3 4: OK - 1 -1 0 2 4 3: KO - 0 -1 0 3 2 4: KO - 0 -1 0 3 4 2: KO - 0 -1 0 4 2 3: KO - 0 -1 0 4 3 2: KO - 0 -1 2 0 3 4: KO - 0 -1 2 0 4 3: KO - 0 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: KO - 0 -1 2 4 3 0: OK - 5 -1 3 0 2 4: KO - 0 -1 3 0 4 2: KO - 0 -1 3 2 0 4: KO - 0 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: KO - 0 -1 4 0 2 3: KO - 0 -1 4 0 3 2: KO - 0 -1 4 2 0 3: KO - 0 -1 4 2 3 0: KO - 0 -1 4 3 0 2: KO - 0 -1 4 3 2 0: KO - 0 -2 0 1 3 4: KO - 0 -2 0 1 4 3: KO - 0 -2 0 3 1 4: KO - 0 -2 0 3 4 1: KO - 0 -2 0 4 1 3: KO - 0 -2 0 4 3 1: KO - 0 -2 1 0 3 4: KO - 0 -2 1 0 4 3: KO - 0 -2 1 3 0 4: KO - 0 -2 1 3 4 0: OK - 2 -2 1 4 0 3: KO - 0 -2 1 4 3 0: KO - 0 -2 3 0 1 4: KO - 0 -2 3 0 4 1: OK - 4 -2 3 1 0 4: KO - 0 -2 3 1 4 0: KO - 0 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: KO - 0 -2 4 1 0 3: KO - 0 -2 4 1 3 0: KO - 0 -2 4 3 0 1: OK - 4 -2 4 3 1 0: KO - 0 -3 0 1 2 4: OK - 4 -3 0 1 4 2: KO - 0 -3 0 2 1 4: KO - 0 -3 0 2 4 1: KO - 0 -3 0 4 1 2: OK - 3 -3 0 4 2 1: KO - 0 -3 1 0 2 4: KO - 0 -3 1 0 4 2: KO - 0 -3 1 2 0 4: KO - 0 -3 1 2 4 0: KO - 0 -3 1 4 0 2: KO - 0 -3 1 4 2 0: KO - 0 -3 2 0 1 4: KO - 0 -3 2 0 4 1: KO - 0 -3 2 1 0 4: KO - 0 -3 2 1 4 0: KO - 0 -3 2 4 0 1: OK - 3 -3 2 4 1 0: KO - 0 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: KO - 0 -3 4 2 0 1: KO - 0 -3 4 2 1 0: KO - 0 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: KO - 0 -4 0 3 1 2: KO - 0 -4 0 3 2 1: KO - 0 -4 1 0 2 3: OK - 2 -4 1 0 3 2: KO - 0 -4 1 2 0 3: KO - 0 -4 1 2 3 0: OK - 3 -4 1 3 0 2: KO - 0 -4 1 3 2 0: KO - 0 -4 2 0 1 3: KO - 0 -4 2 0 3 1: KO - 0 -4 2 1 0 3: KO - 0 -4 2 1 3 0: KO - 0 -4 2 3 0 1: KO - 0 -4 2 3 1 0: KO - 0 -4 3 0 1 2: OK - 3 -4 3 0 2 1: KO - 0 -4 3 1 0 2: KO - 0 -4 3 1 2 0: KO - 0 -4 3 2 0 1: KO - 0 -4 3 2 1 0: KO - 0 -** stacks resulting in nb_moves > 7 : ** -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: KO - 0 -0 1 4 2 3: KO - 0 -0 1 4 3 2: KO - 0 -0 2 1 3 4: OK - 3 -0 2 1 4 3: KO - 0 -0 2 3 1 4: KO - 0 -0 2 3 4 1: OK - 2 -0 2 4 1 3: KO - 0 -0 2 4 3 1: KO - 0 -0 3 1 2 4: KO - 0 -0 3 1 4 2: KO - 0 -0 3 2 1 4: KO - 0 -0 3 2 4 1: KO - 0 -0 3 4 1 2: KO - 0 -0 3 4 2 1: KO - 0 -0 4 1 2 3: OK - 2 -0 4 1 3 2: KO - 0 -0 4 2 1 3: KO - 0 -0 4 2 3 1: KO - 0 -0 4 3 1 2: KO - 0 -0 4 3 2 1: KO - 0 -1 0 2 3 4: OK - 1 -1 0 2 4 3: KO - 0 -1 0 3 2 4: KO - 0 -1 0 3 4 2: KO - 0 -1 0 4 2 3: KO - 0 -1 0 4 3 2: KO - 0 -1 2 0 3 4: KO - 0 -1 2 0 4 3: KO - 0 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: KO - 0 -1 2 4 3 0: OK - 5 -1 3 0 2 4: KO - 0 -1 3 0 4 2: KO - 0 -1 3 2 0 4: KO - 0 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: KO - 0 -1 4 0 2 3: KO - 0 -1 4 0 3 2: KO - 0 -1 4 2 0 3: KO - 0 -1 4 2 3 0: KO - 0 -1 4 3 0 2: KO - 0 -1 4 3 2 0: KO - 0 -2 0 1 3 4: KO - 0 -2 0 1 4 3: KO - 0 -2 0 3 1 4: KO - 0 -2 0 3 4 1: KO - 0 -2 0 4 1 3: KO - 0 -2 0 4 3 1: KO - 0 -2 1 0 3 4: KO - 0 -2 1 0 4 3: KO - 0 -2 1 3 0 4: KO - 0 -2 1 3 4 0: OK - 2 -2 1 4 0 3: KO - 0 -2 1 4 3 0: KO - 0 -2 3 0 1 4: KO - 0 -2 3 0 4 1: OK - 4 -2 3 1 0 4: KO - 0 -2 3 1 4 0: KO - 0 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: KO - 0 -2 4 1 0 3: KO - 0 -2 4 1 3 0: KO - 0 -2 4 3 0 1: OK - 4 -2 4 3 1 0: KO - 0 -3 0 1 2 4: OK - 4 -3 0 1 4 2: KO - 0 -3 0 2 1 4: KO - 0 -3 0 2 4 1: KO - 0 -3 0 4 1 2: OK - 3 -3 0 4 2 1: KO - 0 -3 1 0 2 4: KO - 0 -3 1 0 4 2: KO - 0 -3 1 2 0 4: KO - 0 -3 1 2 4 0: KO - 0 -3 1 4 0 2: KO - 0 -3 1 4 2 0: KO - 0 -3 2 0 1 4: KO - 0 -3 2 0 4 1: KO - 0 -3 2 1 0 4: KO - 0 -3 2 1 4 0: KO - 0 -3 2 4 0 1: OK - 3 -3 2 4 1 0: KO - 0 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: KO - 0 -3 4 2 0 1: KO - 0 -3 4 2 1 0: KO - 0 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: KO - 0 -4 0 3 1 2: KO - 0 -4 0 3 2 1: KO - 0 -4 1 0 2 3: OK - 2 -4 1 0 3 2: KO - 0 -4 1 2 0 3: KO - 0 -4 1 2 3 0: OK - 3 -4 1 3 0 2: KO - 0 -4 1 3 2 0: KO - 0 -4 2 0 1 3: KO - 0 -4 2 0 3 1: KO - 0 -4 2 1 0 3: KO - 0 -4 2 1 3 0: KO - 0 -4 2 3 0 1: KO - 0 -4 2 3 1 0: KO - 0 -4 3 0 1 2: OK - 3 -4 3 0 2 1: KO - 0 -4 3 1 0 2: KO - 0 -4 3 1 2 0: KO - 0 -4 3 2 0 1: KO - 0 -4 3 2 1 0: KO - 0 -** stacks resulting in nb_moves > 7 : ** -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: KO - 0 -0 1 4 2 3: KO - 0 -0 1 4 3 2: KO - 0 -0 2 1 3 4: OK - 3 -0 2 1 4 3: KO - 0 -0 2 3 1 4: KO - 0 -0 2 3 4 1: OK - 2 -0 2 4 1 3: KO - 0 -0 2 4 3 1: KO - 0 -0 3 1 2 4: KO - 0 -0 3 1 4 2: KO - 0 -0 3 2 1 4: KO - 0 -0 3 2 4 1: KO - 0 -0 3 4 1 2: KO - 0 -0 3 4 2 1: KO - 0 -0 4 1 2 3: OK - 2 -0 4 1 3 2: KO - 0 -0 4 2 1 3: KO - 0 -0 4 2 3 1: KO - 0 -0 4 3 1 2: KO - 0 -0 4 3 2 1: KO - 0 -1 0 2 3 4: OK - 1 -1 0 2 4 3: KO - 0 -1 0 3 2 4: KO - 0 -1 0 3 4 2: KO - 0 -1 0 4 2 3: KO - 0 -1 0 4 3 2: KO - 0 -1 2 0 3 4: KO - 0 -1 2 0 4 3: KO - 0 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: KO - 0 -1 2 4 3 0: OK - 5 -1 3 0 2 4: KO - 0 -1 3 0 4 2: KO - 0 -1 3 2 0 4: KO - 0 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: KO - 0 -1 4 0 2 3: KO - 0 -1 4 0 3 2: KO - 0 -1 4 2 0 3: KO - 0 -1 4 2 3 0: KO - 0 -1 4 3 0 2: KO - 0 -1 4 3 2 0: KO - 0 -2 0 1 3 4: KO - 0 -2 0 1 4 3: KO - 0 -2 0 3 1 4: KO - 0 -2 0 3 4 1: KO - 0 -2 0 4 1 3: KO - 0 -2 0 4 3 1: KO - 0 -2 1 0 3 4: KO - 0 -2 1 0 4 3: KO - 0 -2 1 3 0 4: KO - 0 -2 1 3 4 0: OK - 2 -2 1 4 0 3: KO - 0 -2 1 4 3 0: KO - 0 -2 3 0 1 4: KO - 0 -2 3 0 4 1: OK - 4 -2 3 1 0 4: KO - 0 -2 3 1 4 0: KO - 0 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: KO - 0 -2 4 1 0 3: KO - 0 -2 4 1 3 0: KO - 0 -2 4 3 0 1: OK - 4 -2 4 3 1 0: KO - 0 -3 0 1 2 4: OK - 4 -3 0 1 4 2: KO - 0 -3 0 2 1 4: KO - 0 -3 0 2 4 1: KO - 0 -3 0 4 1 2: OK - 3 -3 0 4 2 1: KO - 0 -3 1 0 2 4: KO - 0 -3 1 0 4 2: KO - 0 -3 1 2 0 4: KO - 0 -3 1 2 4 0: KO - 0 -3 1 4 0 2: KO - 0 -3 1 4 2 0: KO - 0 -3 2 0 1 4: KO - 0 -3 2 0 4 1: KO - 0 -3 2 1 0 4: KO - 0 -3 2 1 4 0: KO - 0 -3 2 4 0 1: OK - 3 -3 2 4 1 0: KO - 0 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: KO - 0 -3 4 2 0 1: KO - 0 -3 4 2 1 0: KO - 0 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: KO - 0 -4 0 3 1 2: KO - 0 -4 0 3 2 1: KO - 0 -4 1 0 2 3: OK - 2 -4 1 0 3 2: KO - 0 -4 1 2 0 3: KO - 0 -4 1 2 3 0: OK - 3 -4 1 3 0 2: KO - 0 -4 1 3 2 0: KO - 0 -4 2 0 1 3: KO - 0 -4 2 0 3 1: KO - 0 -4 2 1 0 3: KO - 0 -4 2 1 3 0: KO - 0 -4 2 3 0 1: KO - 0 -4 2 3 1 0: KO - 0 -4 3 0 1 2: OK - 3 -4 3 0 2 1: KO - 0 -4 3 1 0 2: KO - 0 -4 3 1 2 0: KO - 0 -4 3 2 0 1: KO - 0 -4 3 2 1 0: KO - 0 -** stacks resulting in nb_moves > 7 : ** diff --git a/backup/sort.c b/backup/sort.c deleted file mode 100644 index df742cd..0000000 --- a/backup/sort.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "push_swap.h" - -int nb_sorted_at_pos(int *stack, int size, int pos) -{ - int nb_sorted; - int curr_value; - int i; - - i = pos + 1; - nb_sorted = 1; - while (i != pos && !(pos == 0 && i == size)) - { - if (i == size) - curr_value = stack[0]; - else - curr_value = stack[i]; - if (i == 0) - { - i++; - continue ; - } - if (curr_value > stack[i - 1]) - nb_sorted++; - if (i == size) - i = 0; - else - i++; - } - return (nb_sorted); -} - -int get_biggest_val(int *stack, int size) -{ - int pos_in_stack; - int pos_biggest; - int biggest_val; - - pos_in_stack = 0; - pos_biggest = 0; - biggest_val = 0; - while (pos_in_stack < size) - { - if (stack[pos_in_stack] > biggest_val) - { - biggest_val = stack[pos_in_stack]; - pos_biggest = pos_in_stack; - } - pos_in_stack++; - } - return (biggest_val); -} - -int get_smallest_val(int *stack, int size) -{ - int pos_in_stack; - int smallest_pos; - int smallest_val; - - pos_in_stack = 0; - smallest_pos = 0; - smallest_val = size; - while (pos_in_stack < size) - { - if (stack[pos_in_stack] < smallest_val) - { - smallest_val = stack[pos_in_stack]; - smallest_pos = pos_in_stack; - } - pos_in_stack++; - } - return (smallest_val); -} - -int get_smallest_pos(int *stack, int size) -{ - int pos_in_stack; - int smallest_pos; - int smallest_val; - - pos_in_stack = 0; - smallest_pos = 0; - smallest_val = size; - while (pos_in_stack < size) - { - if (stack[pos_in_stack] < smallest_val) - { - smallest_val = stack[pos_in_stack]; - smallest_pos = pos_in_stack; - } - pos_in_stack++; - } - return (smallest_pos); -} - -void sort_3(t_main_cont *cont) -{ - int smallest_pos; - int nb_sorted; - - smallest_pos = get_smallest_pos(cont->A, cont->sizeA); - nb_sorted = nb_sorted_at_pos(cont->A, cont->sizeA, smallest_pos); - if (DEBUG) - printf("in sort_3, smallest_pos = %d\n", smallest_pos); - if (smallest_pos == 0 && nb_sorted == cont->size) - return ; - else if (nb_sorted == cont->size) - { - if (smallest_pos == 1) - make_rab(&cont->A, cont->sizeA, RA); - else if (smallest_pos == cont->size - 1) - make_rrab(&cont->A, cont->sizeA, RRA); - return ; - } - make_sab(cont->A, cont->sizeA, SA); - sort_3(cont); - return ; -} - -void sort(t_main_cont *cont) -{ - if (cont->size <= 3) - sort_3(cont); - - else if (cont->size <= 5) - sort_5(cont); - return ; -} diff --git a/backup/sort_5.c b/backup/sort_5.c deleted file mode 100644 index 8d139fd..0000000 --- a/backup/sort_5.c +++ /dev/null @@ -1,262 +0,0 @@ -#include "push_swap.h" - -void rotate_a_to_pos0(t_main_cont *cont, int pos) -{ - if (pos < cont->sizeA - pos) - while (pos-- > 0) - make_rab(stack, size, RA); - else - while (pos++ < cont->sizeA) - make_rrab(&cont->A, cont->size, RRA); - if (DEBUG) - { - printf(YELLOW"--------AFTER rotate_a_to_pos0--------\n"RESET_COL); - print_single_stack(cont->A, cont->sizeA); - } - return ; -} - -void rotate_a_to_pos0_dry_run(t_main_cont *cont, int pos) -{ - if (pos < cont->sizeA - pos) - while (pos-- > 0) - rotate(stack, size); - else - while (pos++ < cont->sizeA) - rev_rotate(&cont->A, cont->size); - return ; -} - -bool try_pb(t_main_cont *cont) -{ - int pos_in_stack; - int stack_head_value; - - if (DEBUG) - printf(RED"-----ENTERED try_pb!!!-----\n"RESET_COL); - smallest_val = get_smallest_val(cont->A, cont->sizeA); - if (nb_sorted_at_pos(cont->A, cont->sizeA, smallest_val)) - { - rotate_a_to_pos0(cont, smallest_val); - return (true); - } - pos_in_stack = 0; - stack_head_value = cont->A[0]; - while (pos_in_stack < cont->sizeA) - { - rotate_a_to_pos0_dry_run(cont, pos_in_stack); - push(cont, PB); - if (DEBUG) - { - printf(RED"------after pushing stackA[%d]------\n"RESET_COL, pos_in_stack); - // print_stacks(cont); - - } - if (try_sa_dry_run(cont)) - { - push(cont, PA); - rotate_a_to_pos0_dry_run(cont, get_pos_in_stack(cont->A, cont->sizeA, stack_head_value)); - rotate_a_to_pos0(cont, pos_in_stack); - make_push(cont, PB); - try_sa(cont); - insert_b(cont); - if (DEBUG) - { - printf(GREEN"--------try_pb succeeded--------\n"RESET_COL); - // print_stacks(cont); - } - return (true); - } - else - { - push(cont, PA); - rotate_to_pos0_dry_run(&cont->A, cont->sizeA, get_stack_pos(cont->A, cont->sizeA, stack_head_value)); - } - pos_in_stack++; - } - return (false); -} - -bool try_sa_dry_run(t_main_cont *cont) -{ - int *stack; - int size; - int pos; - int stack_head; - int next_pos; - - stack = cont->A; - size = cont->sizeA; - pos = 0; - while (pos < size) - { - next_pos = get_next_pos(pos, size); - ft_swap_ints(&stack[pos], &stack[next_pos]); - stack_head = get_pos_smallest(stack, size); - if (nb_sorted_at_pos(stack, size, stack_head) == size) - { - ft_swap_ints(&stack[pos], &stack[next_pos]); - return (true); - } - else - ft_swap_ints(&stack[pos], &stack[next_pos]); - pos++; - } - return (false); -} - -bool try_sa(t_main_cont *cont) -{ - int *stack; - int size; - int pos; - int stack_head; - int next_pos; - - stack = cont->A; - size = cont->sizeA; - pos = 0; - while (pos < size) - { - next_pos = get_next_pos(pos, size); - ft_swap_ints(&stack[pos], &stack[next_pos]); - stack_head = get_pos_smallest(stack, size); - if (nb_sorted_at_pos(stack, size, stack_head) == size) - { - ft_swap_ints(&stack[pos], &stack[next_pos]); - rotate_to_pos0(&cont->A, cont->sizeA, pos); - make_sab(cont->A, cont->sizeA, SA); - if (DEBUG) - { - printf(YELLOW"--------AFTER try_sa--------\n"RESET_COL); - // print_stacks(cont); - } - return (true); - } - else - ft_swap_ints(&stack[pos], &stack[next_pos]); - pos++; - } - return (false); -} - -int try_ra_dry_run(t_main_cont *cont) -{ - int stack_head; - - smallest_val = get_smallest_pos(cont->A, cont->size); - if (nb_sorted_at_pos(cont->A, cont->size, smallest_val) == cont->sizeA) - { - return (true); - } - return (false); -} - -bool try_ra(t_main_cont *cont) -{ - int stack_head; - - smallest_val = get_smallest_pos(cont->A, cont->size); - if (nb_sorted_at_pos(cont->A, cont->size, smallest_val) == cont->sizeA) - { - rotate_a_to_pos0(cont, smallest_val); - return (true); - } - return (false); -} - -void insert_b(t_main_cont *cont) -{ - int pos_of_b0_in_a; - int insertion_val; - - while (cont->sizeB) - { - if (cont->B[0] < cont->size - 1) - insertion_val = cont->B[0] + 1; - else - insertion_val = 0; - if (DEBUG) - printf(RED"------>in insert_b, insertion_val of %d = %d\n"RESET_COL, cont->B[0], insertion_val); - pos_of_b0_in_a = 0; - while (cont->A[pos_of_b0_in_a] != insertion_val) - { - set_next_pos(&pos_of_b0_in_a, cont->sizeA); - if (pos_of_b0_in_a == 0) - set_next_pos(&insertion_val, cont->size); - } - if (DEBUG) - printf(RED"------>in insert_b, pos_of %d in a = %d\n"RESET_COL, insertion_val, pos_of_b0_in_a); - rotate_to_pos0(&cont->A, cont->sizeA, pos_of_b0_in_a); - make_push(cont, PA); - if (DEBUG) - { - printf(YELLOW"--------AFTER pa--------\n"RESET_COL); - // print_stacks(cont); - } - } - insertion_val = get_pos_smallest(cont->A, cont->sizeA); - rotate_to_pos0(&cont->A, cont->sizeA, insertion_val); - return ; -} - -bool try_rotate_and_swap(t_main_cont *cont) -{ - int stack_head; - - stack_head = get_pos_smallest(cont->A, cont->sizeA); - if (nb_sorted_at_pos(cont->A, cont->sizeA, stack_head) == cont->sizeA) - { - insert_b(cont); - if (DEBUG) - { - printf(RED"#############stack_head = %d\n"RESET_COL, stack_head); - printf(RED"#############cont->A[stack_head] = %d\n"RESET_COL, cont->A[stack_head]); - } - return (true); - } - else if (try_sa(cont) == true) - { - insert_b(cont); - if (DEBUG) - { - printf(RED"#############stack_head = %d\n"RESET_COL, stack_head); - printf(RED"#############cont->A[stack_head] = %d\n"RESET_COL, cont->A[stack_head]); - } - return (true); - } - return (false); -} - -//Need to code try_pb (which will try ALL positions in stack A to see which -//is closest to pos_0) to try to see if pushing a single value can allow -//try_sa to sort the 4 remaining ones. -//I believe that the only case that would result in more than 7 moves with this -//method is "4 3 2 1 0" (8 moves). The only way I found to make it in less is : -// -pb; sa-> 2 3 1 0 | 4 -ra x2; sa-> 0 1 2 3 | 4 -pa; ra-> [DONE] (7 moves) - -void sort_5(t_main_cont *cont) -{ - if (try_rotate_and_swap(cont) == true) - { - if (DEBUG) - { - printf("--------SOLVED BOARD--------"); - // print_stacks(cont); - } - return ; - } - else - { - if (try_pb(cont) == true) - return ; - make_push(cont, PB); - if (DEBUG) - { - printf(YELLOW"--------AFTER pb--------\n"RESET_COL); - // print_stacks(cont); - } - sort_5(cont); - } - return ; -} diff --git a/backup/sort_big.c b/backup/sort_big.c deleted file mode 100644 index edf3af0..0000000 --- a/backup/sort_big.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "push_swap.h" - -void sort_big(t_main_cont *cont) -{ - int max_index_in_a; - - max_index_in_a -} \ No newline at end of file diff --git a/backup/try_pb.log b/backup/try_pb.log deleted file mode 100644 index e8a0c27..0000000 --- a/backup/try_pb.log +++ /dev/null @@ -1,245 +0,0 @@ -0 1 2 3 4: OK - 0 -0 1 2 4 3: OK - 5 -0 1 3 2 4: OK - 5 -0 1 3 4 2: OK - 4 -0 1 4 2 3: OK - 4 -0 1 4 3 2: OK - 8 -0 2 1 3 4: OK - 3 -0 2 1 4 3: OK - 7 -0 2 3 1 4: OK - 6 -0 2 3 4 1: OK - 2 -0 2 4 1 3: OK - 5 -0 2 4 3 1: OK - 6 -0 3 1 2 4: OK - 6 -0 3 1 4 2: OK - 5 -0 3 2 1 4: OK - 8 -0 3 2 4 1: OK - 4 -0 3 4 1 2: OK - 7 -0 3 4 2 1: OK - 5 -0 4 1 2 3: OK - 2 -0 4 1 3 2: OK - 6 -0 4 2 1 3: OK - 4 -0 4 2 3 1: OK - 5 -0 4 3 1 2: OK - 5 -0 4 3 2 1: OK - 7 -1 0 2 3 4: OK - 1 -1 0 2 4 3: OK - 7 -1 0 3 2 4: OK - 5 -1 0 3 4 2: OK - 6 -1 0 4 2 3: OK - 6 -1 0 4 3 2: OK - 8 -1 2 0 3 4: OK - 5 -1 2 0 4 3: OK - 7 -1 2 3 0 4: OK - 4 -1 2 3 4 0: OK - 1 -1 2 4 0 3: OK - 5 -1 2 4 3 0: OK - 5 -1 3 0 2 4: OK - 6 -1 3 0 4 2: OK - 7 -1 3 2 0 4: OK - 7 -1 3 2 4 0: OK - 4 -1 3 4 0 2: OK - 3 -1 3 4 2 0: OK - 7 -1 4 0 2 3: OK - 6 -1 4 0 3 2: OK - 6 -1 4 2 0 3: OK - 6 -1 4 2 3 0: OK - 7 -1 4 3 0 2: OK - 5 -1 4 3 2 0: OK - 7 -2 0 1 3 4: OK - 5 -2 0 1 4 3: OK - 7 -2 0 3 1 4: OK - 7 -2 0 3 4 1: OK - 8 -2 0 4 1 3: OK - 6 -2 0 4 3 1: OK - 6 -2 1 0 3 4: OK - 7 -2 1 0 4 3: OK - 9 -2 1 3 0 4: OK - 8 -2 1 3 4 0: OK - 2 -2 1 4 0 3: OK - 7 -2 1 4 3 0: OK - 6 -2 3 0 1 4: OK - 6 -2 3 0 4 1: OK - 4 -2 3 1 0 4: OK - 8 -2 3 1 4 0: OK - 6 -2 3 4 0 1: OK - 2 -2 3 4 1 0: OK - 3 -2 4 0 1 3: OK - 4 -2 4 0 3 1: OK - 8 -2 4 1 0 3: OK - 8 -2 4 1 3 0: OK - 7 -2 4 3 0 1: OK - 4 -2 4 3 1 0: OK - 6 -3 0 1 2 4: OK - 4 -3 0 1 4 2: OK - 8 -3 0 2 1 4: OK - 8 -3 0 2 4 1: OK - 7 -3 0 4 1 2: OK - 3 -3 0 4 2 1: OK - 5 -3 1 0 2 4: OK - 6 -3 1 0 4 2: OK - 7 -3 1 2 0 4: OK - 7 -3 1 2 4 0: OK - 6 -3 1 4 0 2: OK - 8 -3 1 4 2 0: OK - 7 -3 2 0 1 4: OK - 7 -3 2 0 4 1: OK - 6 -3 2 1 0 4: OK - 9 -3 2 1 4 0: OK - 7 -3 2 4 0 1: OK - 3 -3 2 4 1 0: OK - 8 -3 4 0 1 2: OK - 2 -3 4 0 2 1: OK - 4 -3 4 1 0 2: OK - 3 -3 4 1 2 0: OK - 6 -3 4 2 0 1: OK - 6 -3 4 2 1 0: OK - 9 -4 0 1 2 3: OK - 1 -4 0 1 3 2: OK - 5 -4 0 2 1 3: OK - 4 -4 0 2 3 1: OK - 5 -4 0 3 1 2: OK - 5 -4 0 3 2 1: OK - 9 -4 1 0 2 3: OK - 2 -4 1 0 3 2: OK - 6 -4 1 2 0 3: OK - 7 -4 1 2 3 0: OK - 3 -4 1 3 0 2: OK - 6 -4 1 3 2 0: OK - 7 -4 2 0 1 3: OK - 7 -4 2 0 3 1: OK - 6 -4 2 1 0 3: OK - 8 -4 2 1 3 0: OK - 5 -4 2 3 0 1: OK - 7 -4 2 3 1 0: OK - 6 -4 3 0 1 2: OK - 3 -4 3 0 2 1: OK - 7 -4 3 1 0 2: OK - 5 -4 3 1 2 0: OK - 6 -4 3 2 0 1: OK - 6 -4 3 2 1 0: OK - 8 -** stacks resulting in nb_moves > 8 : ** - 2 1 0 4 3 --> 9 - 3 2 1 0 4 --> 9 - 3 4 2 1 0 --> 9 - 4 0 3 2 1 --> 9 diff --git a/backup/vectors.c b/backup/vectors.c deleted file mode 100644 index b633f2a..0000000 --- a/backup/vectors.c +++ /dev/null @@ -1,86 +0,0 @@ -#include "push_swap.h" - -bool vector_init(t_vector *vector) -{ - vector->ptr_vec_add = vec_add; - vector->ptr_vec_remove = vec_remove; - vector->ptr_vec_resize = vec_resize; - vector->ptr_vec_free_list = vec_free_list; - - vector.nb_elems = 0; - vector.capacity = VECTOR_INIT_SIZE; - vector.elems = malloc(VECTOR_INIT_SIZE * sizeof(int *)); - if (!vector.elems) - return (FAILURE); - return (SUCCESS); -} - -bool vec_add(t_vector *vector, int new_elem) -{ - t_vec_list *list; - bool status; - - list = &vector; - if (list->nb_elems == list->capacity) - { - status = vec_resize(vector, list->capacity + list->capacity); - if (status == FAILURE) - return (status); - } - list->elems[list->nb_elems] = new_elem; - list->nb_elems += 1; - status = SUCCESS; - return (status); -} - -//Need to add resize smaller when under a certain size -void vec_remove(t_vector *vector) -{ - t_vec_list *list; - - list = &vector; - list->elems[list->nb_elems - 1] = 0; - list->nb_elems -= 1; - return ; -} - -bool vec_resize(t_vector *vector, int new_size) -{ - int *temp; - int pos_in_vector; - bool status; - - if (new_size < vector.capacity) - return (FAILURE); - if (DEBUG) - printf(RED"ENTERED RESIZE_END() WITH SIZE = %d\n", new_size); - //To switch to a bzero, or write a ft_calloc - temp = malloc(new_size * sizeof(int)); - if (DEBUG) - printf("SURVIVED MALLOC\n"RESET_COL); - if (!temp) - status = FAILURE; - else - { - ft_bzero(temp, new_size); - pos_in_vector = 0; - while (pos_in_vector < vector.nb_elems) - { - temp[pos_in_vector] = vector.elems[pos_in_vector]; - pos_in_vector++; - } - free (vector.elems); - vector.elems = temp; - if (DEBUG) - printf(RED"SURVIVED FREE()\n"RESET_COL); - vector.capacity = new_size; - status = SUCCESS; - } - return (status); -} - -bool vec_free_list(t_vector *vector) -{ - free (vector.elems); - return (FAILURE); -} diff --git a/include/deques.h b/include/deques.h index 5228804..6a40b19 100644 --- a/include/deques.h +++ b/include/deques.h @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* deques.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: iyahoui- a_info.val, info->b_info.val)); diff --git a/src/deque_modify.c b/src/deque_modify.c index aa5b48e..aec1bb3 100644 --- a/src/deque_modify.c +++ b/src/deque_modify.c @@ -6,22 +6,16 @@ /* By: iyahoui- capacity_front == 0) - { - status = deque_resize_front(deque, deque->capacity_total); - if (status == FAILURE) - return (status); - } + deque_resize_front(deque, deque->capacity_total * 2); deque->elems -= 1; deque->elems[0] = new_elem; deque->size += 1; @@ -31,28 +25,20 @@ bool deque_add_front(t_deque *deque, int new_elem) deque->max_elem = new_elem; if (new_elem < deque->min_elem) deque->min_elem = new_elem; - status = SUCCESS; - return (status); + return ; } -bool deque_add_last(t_deque *deque, int new_elem) +void deque_add_last(t_deque *deque, int new_elem) { - bool status; - if (deque->size == deque->capacity_end) - { - status = deque_resize_end(deque, deque->capacity_total * 2); - if (status == FAILURE) - return (status); - } + deque_resize_end(deque, deque->capacity_total * 2); deque->elems[deque->size] = new_elem; deque->size += 1; if (new_elem > deque->max_elem) deque->max_elem = new_elem; if (new_elem < deque->min_elem) deque->min_elem = new_elem; - status = SUCCESS; - return (status); + return ; } //Need to add resize smaller when under a certain size diff --git a/src/deque_operators.c b/src/deque_operators.c index 551ed9f..93d011b 100644 --- a/src/deque_operators.c +++ b/src/deque_operators.c @@ -6,7 +6,7 @@ /* By: iyahoui- capacity_end; - temp = malloc(total_new_size * sizeof(int)); - if (!temp) - return (FAILURE); + temp = ft_xalloc(total_new_size * sizeof(int)); temp += new_size; pos_in_deque = 0; while (pos_in_deque < deque->size) @@ -41,10 +39,10 @@ bool deque_resize_front(t_deque *deque, int new_size) deque->elems = temp; deque->capacity_front = new_size; deque->capacity_total = total_new_size; - return (SUCCESS); + return ; } -bool deque_resize_end(t_deque *deque, int new_size) +void deque_resize_end(t_deque *deque, int new_size) { int *temp; int total_new_size; @@ -64,7 +62,7 @@ bool deque_resize_end(t_deque *deque, int new_size) deque->elems = temp; deque->capacity_end = new_size; deque->capacity_total = total_new_size; - return (SUCCESS); + return ; } int deque_get_elem_max(t_deque *deque) diff --git a/src/deques.c b/src/deques.c index 8de35de..61f57bc 100644 --- a/src/deques.c +++ b/src/deques.c @@ -6,7 +6,7 @@ /* By: iyahoui- malloced_space); deque->size = 0; @@ -47,5 +47,5 @@ bool deque_reinit_list(t_deque *deque) deque->capacity_total = 2 * VECTOR_INIT_SIZE; deque->malloced_space = ft_xalloc(2 * VECTOR_INIT_SIZE * sizeof(int)); deque->elems = deque->malloced_space + VECTOR_INIT_SIZE; - return (SUCCESS); + return ; } diff --git a/src/init.c b/src/init.c index 820eb96..77145b5 100644 --- a/src/init.c +++ b/src/init.c @@ -6,7 +6,7 @@ /* By: iyahoui- reverse_fcts); i = -1; while (args[++i] != NULL) - if (cont->stack_a.add_last(&cont->stack_a, ft_atoi(args[i]))) - exit_on_err("deque_add_last done fucked up\n"); + cont->stack_a.add_last(&cont->stack_a, ft_atoi(args[i])); normalize_stack_values(&cont->stack_a); copy_deque(&cont->stack_a, &cont->initial_stack); set_iterator(&cont->head_a, get_pos_smallest_val(&cont->stack_a), diff --git a/src/iterators.c b/src/iterators.c index 023141a..e33686e 100644 --- a/src/iterators.c +++ b/src/iterators.c @@ -6,7 +6,7 @@ /* By: iyahoui- $PS_TEMPFILE - NB_MOVES=$(< $PS_TEMPFILE wc -l | sed 's/ //g'); - if [ $(< $PS_TEMPFILE ./checker_Mac $ARG | grep -q KO) ]; - then - echo "Error!" - echo "Error!" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "nb_moves:" >> $LOG_FILE - echo $NB_MOVES >> $LOG_FILE - break - fi - if [ $(echo "$NB_MOVES > $LIMIT" | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "" >> $LOG_FILE - let NB_CASES_ABOVE_LIMIT+=1; - fi - if [ $(echo $NB_MOVES ">" $MAX_NB_MOVES | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo "$ARG" >> $LOG_FILE - echo "" >> $LOG_FILE - MAX_NB_MOVES=$NB_MOVES; - MAX_TEST_ID=$i; - fi - - if [ $(echo $NB_MOVES "<" $LIMIT | bc) -eq 1 ]; - then - echo -e "${i} : ${GREEN}${NB_MOVES}${ENDCOLOR}" - else - echo -e "${i} : ${RED}${NB_MOVES}${ENDCOLOR}" - fi - let SUM+=$NB_MOVES; - let ITERATIONS+=1; - let i+=1; -done - -rm $PS_TEMPFILE -echo "Nb tests done:" $(($ITERATIONS - 1)) -if [ $(echo "$(($SUM / ($ITERATIONS - 1))) < ${LIMIT}" | bc) -eq 1 ]; -then - echo -e "${GREEN}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -else - echo -e "${RED}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -fi - -if [ $(echo $MAX_NB_MOVES "<" $LIMIT | bc) -eq 1 ]; -then - echo -e "${GREEN}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -else - echo -e "${RED}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -fi - -if [ $NB_CASES_ABOVE_LIMIT -eq 0 ]; -then - printf "${GREEN}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -else - printf "${RED}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -fi - -echo "Nb tests done:" $ITERATIONS >> $LOG_FILE -echo "Average nb of moves: $(($SUM / ($ITERATIONS - 1)))" >> $LOG_FILE -echo "(Test #"$MAX_TEST_ID") Worst nb of moves:" $MAX_NB_MOVES >> $LOG_FILE -printf "%s %.0f %s %d\n" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT >> $LOG_FILE diff --git a/tester5.sh b/tester5.sh deleted file mode 100755 index eaa7dee..0000000 --- a/tester5.sh +++ /dev/null @@ -1,89 +0,0 @@ -#! /bin/bash - -RED="\033[31m" -GREEN="\033[32m" -ENDCOLOR="\033[0m" - -NB_VALS=5 -MAX_NB_MOVES=0 -MAX_TEST_ID=0 -N=1.38 -# LIMIT=$(bc -l <<< "e($N*l($NB_VALS))") -LIMIT=12 -INT_LIMIT=${LIMIT%.1} -NB_CASES_ABOVE_LIMIT=0 -ITERATIONS=1 -PERMUTATIONS_FILE=5_permutations_numbered.txt -LOG_FILE=sore_thumbs_$NB_VALS.log -PS_TEMPFILE=tester_temp_$NB_VALS.log - -echo -e "${GREEN}Testing for ${NB_VALS} values ${ENDCOLOR}" - -for i in {1..120} -do - export ARG=$(awk -F: -v i=$i 'NR==i{printf $2;}' $PERMUTATIONS_FILE) - ./push_swap $ARG > $PS_TEMPFILE - NB_MOVES=$(< $PS_TEMPFILE wc -l | sed 's/ //g'); - if [ $(< $PS_TEMPFILE ./checker_Mac $ARG | grep -q KO) ]; - then - echo "Error!" - echo "Error!" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "nb_moves:" >> $LOG_FILE - echo $NB_MOVES >> $LOG_FILE - break - fi - if [ $(echo "$NB_MOVES >= $LIMIT" | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "" >> $LOG_FILE - let NB_CASES_ABOVE_LIMIT+=1; - fi - if [ $(echo $NB_MOVES ">" $MAX_NB_MOVES | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo "$ARG" >> $LOG_FILE - echo "" >> $LOG_FILE - MAX_NB_MOVES=$NB_MOVES; - MAX_TEST_ID=$i; - fi - - if [ $(< $PS_TEMPFILE ./checker_Mac $ARG | grep OK) ]; - then - echo -e "$ARG: ${GREEN}${NB_MOVES} "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]"${ENDCOLOR}" - else - echo -e "$ARG: ${RED}${NB_MOVES} "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]"${ENDCOLOR}" - fi - let SUM+=$NB_MOVES; - let ITERATIONS+=1; - let i+=1; -done - -rm $PS_TEMPFILE -echo "Nb tests done:" $(($ITERATIONS - 1)) -if [ $(echo "$(($SUM / ($ITERATIONS - 1))) < ${LIMIT}" | bc) -eq 1 ]; -then - echo -e "${GREEN}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -else - echo -e "${RED}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -fi - -if [ $(echo $MAX_NB_MOVES "<" $LIMIT | bc) -eq 1 ]; -then - echo -e "${GREEN}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -else - echo -e "${RED}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -fi - -if [ $NB_CASES_ABOVE_LIMIT -eq 0 ]; -then - printf "${GREEN}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -else - printf "${RED}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -fi - -echo "Nb tests done:" $ITERATIONS >> $LOG_FILE -echo "Average nb of moves: $(($SUM / ($ITERATIONS - 1)))" >> $LOG_FILE -echo "(Test #"$MAX_TEST_ID") Worst nb of moves:" $MAX_NB_MOVES >> $LOG_FILE -printf "%s %.0f %s %d\n" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT >> $LOG_FILE diff --git a/tester500.sh b/tester500.sh deleted file mode 100755 index 682473e..0000000 --- a/tester500.sh +++ /dev/null @@ -1,91 +0,0 @@ -#! /bin/bash - -RED="\033[31m" -GREEN="\033[32m" -ENDCOLOR="\033[0m" - -NB_VALS=500 -MAX_NB_MOVES=0 -MAX_TEST_ID=0 -N=1.38 -# LIMIT=$(bc -l <<< "e($N*l($NB_VALS))") -LIMIT=5500 -INT_LIMIT=${LIMIT%.1} -NB_CASES_ABOVE_LIMIT=0 -ITERATIONS=1 -SUM=0 -LOG_FILE=sore_thumbs_$NB_VALS.log -PS_TEMPFILE=tester_temp_$NB_VALS.log -PS_EXE=./push_swap_$NB_VALS - -echo -e "${GREEN}Testing for ${NB_VALS} values ${ENDCOLOR}" - - -for i in {1..1000} -do - export ARG=`ruby -e "puts (1..$NB_VALS).to_a.shuffle.join(' ')"` - $PS_EXE $ARG > $PS_TEMPFILE - NB_MOVES=$(< $PS_TEMPFILE wc -l | sed 's/ //g'); - if [ $(< $PS_TEMPFILE ./checker_Mac $ARG | grep -q KO) ]; - then - echo "Error!" - echo "Error!" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "nb_moves:" >> $LOG_FILE - echo $NB_MOVES >> $LOG_FILE - break - fi - if [ $(echo "$NB_MOVES > $LIMIT" | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo $ARG >> $LOG_FILE - echo "" >> $LOG_FILE - let NB_CASES_ABOVE_LIMIT+=1; - fi - if [ $(echo $NB_MOVES ">" $MAX_NB_MOVES | bc) -eq 1 ]; - then - echo "Test #"$i":" $NB_MOVES "[$(cat $PS_TEMPFILE | ./checker_Mac $ARG)]" >> $LOG_FILE - echo "$ARG" >> $LOG_FILE - echo "" >> $LOG_FILE - MAX_NB_MOVES=$NB_MOVES; - MAX_TEST_ID=$i; - fi - - if [ $(echo $NB_MOVES "<" $LIMIT | bc) -eq 1 ]; - then - echo -e "${i} : ${GREEN}${NB_MOVES}${ENDCOLOR}" - else - echo -e "${i} : ${RED}${NB_MOVES}${ENDCOLOR}" - fi - let SUM+=$NB_MOVES; - let ITERATIONS+=1; - let i+=1; -done - -rm $PS_TEMPFILE -echo "Nb tests done:" $(($ITERATIONS - 1)) -if [ $(echo "$(($SUM / ($ITERATIONS - 1))) < ${LIMIT}" | bc) -eq 1 ]; -then - echo -e "${GREEN}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -else - echo -e "${RED}Average nb of moves: $(($SUM / ($ITERATIONS - 1)))${ENDCOLOR}" -fi - -if [ $(echo $MAX_NB_MOVES "<" $LIMIT | bc) -eq 1 ]; -then - echo -e "${GREEN}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -else - echo -e "${RED}Worst nb of moves: ${MAX_NB_MOVES}${ENDCOLOR}" -fi - -if [ $NB_CASES_ABOVE_LIMIT -eq 0 ]; -then - printf "${GREEN}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -else - printf "${RED}%s %.0f %s %d\n${ENDCOLOR}" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT -fi - -echo "Nb tests done:" $ITERATIONS >> $LOG_FILE -echo "Average nb of moves: $(($SUM / ($ITERATIONS - 1)))" >> $LOG_FILE -echo "(Test #"$MAX_TEST_ID") Worst nb of moves:" $MAX_NB_MOVES >> $LOG_FILE -printf "%s %.0f %s %d\n" "Nb of moves above" $LIMIT ":" $NB_CASES_ABOVE_LIMIT >> $LOG_FILE From e40089e8d3812256debec6366cda11fec0ad6c17 Mon Sep 17 00:00:00 2001 From: oddtiming <36460419+oddtiming@users.noreply.github.com> Date: Sun, 1 May 2022 21:29:25 -0400 Subject: [PATCH 31/32] Ready to remove libft --- Makefile | 61 +++++------------- greater_than_ideas.txt | 140 ----------------------------------------- include/push_swap.h | 2 +- src/calc_insert_cost.c | 2 +- 4 files changed, 16 insertions(+), 189 deletions(-) delete mode 100644 greater_than_ideas.txt diff --git a/Makefile b/Makefile index f72cecc..f006b97 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,6 @@ HFILES = push_swap.h \ SRC_DIR = src SRCS = $(addprefix $(SRC_DIR)/, $(CFILES)) - OBJ_DIR = obj OBJS = $(addprefix $(OBJ_DIR)/, $(CFILES:.c=.o)) OBJS_BONUS = $(addprefix $(OBJ_DIR)/, $(CFILES_BONUS:.c=.o)) @@ -81,16 +80,7 @@ INCLFLAGS = -I$(INCL) HEADERS = $(addprefix $(INCL)/, $(HFILES)) CC = gcc -CFLAGS = -Wall -Wextra -Werror -g -O3 - -# -# DEBUG build settings -# -DBG_DIR = debug_objs -DBG_EXE = push_swap_try_pb_debug -DBG_OBJS = $(addprefix $(DBG_DIR)/, $(CFILES:.c=.o)) -DBG_CFLAGS = -D DEBUG=1 -g - +CFLAGS = -Wall -Wextra -Werror -O3 LIBFT_DIR = ./libft LIBFT = $(LIBFT_DIR)/libft.a @@ -109,7 +99,7 @@ COMPILE_EXE_OUT = $$($(COMPILE_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\0 COMPILE_C = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< COMPILE_C_OUT = $$($(COMPILE_C) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(OBJS_BONUS) -o $(NAME_BONUS) +COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) $(OBJS_BONUS) -o $(NAME_BONUS) COMPILE_EXE_BONUS_OUT = $$($(COMPILE_EXE_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') COMPILE_C_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< @@ -119,20 +109,6 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c @mkdir -p $(OBJ_DIR) @printf "$(CYAN)%-32s-->%32s $(RESET_COL)$(COMPILE_C_OUT)\n" $^ $@ -# -# DEBUG MACROS -# -COMPILE_DBG_EXE = $(CC) $(DBG_CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(DBG_OBJS) -o $(DBG_EXE) -COMPILE_DBG_EXE_OUT = $$($(COMPILE_DBG_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -COMPILE_DBGC = $(CC) $(DBG_CFLAGS) $(INCLFLAGS) -o $@ -c $< -COMPILE_DBGC_OUT = $$($(COMPILE_DBGC) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -RM_DBG_EXE = rm -f $(DBG_EXE) -RM_DBG_EXE_OUT = $$($(RM_DBG_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') - -$(DBG_DIR)/%.o: $(SRC_DIR)/%.c - @mkdir -p $(DBG_DIR) - @echo -e "$(ON_RED)>\t$^\t--> $@ $(RESET_COL)$(COMPILE_DBGC_OUT)" - all: $(NAME) @if [ -e $(NAME) ]; \ then \ @@ -141,11 +117,19 @@ all: $(NAME) echo -e "$(RED)>>>>>>>> Compilation failed\n>>>>>>>>$(RESET_COL)"; \ fi +bonus: $(NAME_BONUS) + @if [ -e $(NAME_BONUS) ]; \ + then \ + echo -e "$(GREEN)>>>>>>>> Compilation successful\n>>>>>>>>$(RESET_COL)"; \ + else \ + echo -e "$(RED)>>>>>>>> Compilation failed\n>>>>>>>>$(RESET_COL)"; \ + fi + $(NAME): libft pretty_print $(OBJS) @echo -e "\n$(CYAN)>>>>>>>> Compiling $(NAME) ...$(RESET_COL)$(COMPILE_EXE_OUT)" -$(NAME_BONUS): libft $(OBJS_BONUS) +$(NAME_BONUS): libft pretty_print_bonus $(OBJS_BONUS) @echo -e "\n$(CYAN)>>>>>>>> Compiling $(NAME_BONUS) ...$(RESET_COL)$(COMPILE_EXE_BONUS_OUT)" silent_libft: @@ -164,7 +148,6 @@ libft: silent_libft pretty_print: @echo -e "\n--------------------- $(NAME) ---------------------" - clean: @echo -e "$(RED)>>>>>>>> Deleting obj files$(RESET_COL)$(RM_OBJS_OUT)" @echo -e "$(GREEN)>>>>>>>> obj files deleted\n>>>>>>>>$(RESET_COL)" @@ -173,32 +156,16 @@ clean_libft: @echo -e "$(RED)>>>>>>>> make fclean -sC libft $(RESET_COL)$(RM_LIBFT_OUT)" @echo -e "$(GREEN)>>>>>>>> libft cleaned\n>>>>>>>>$(RESET_COL)" -clean_debug: clean - @echo -e "$(RED)>>>>>>>> Deleting debug obj files$(RESET_COL)$(RM_DBG_EXE_OUT)" - @echo -e "$(GREEN)>>>>>>>> obj files deleted\n>>>>>>>>$(RESET_COL)" - -fclean: clean clean_libft clean_debug +fclean: clean clean_libft @echo -e "$(RED)>>>>>>>> Deleting $(NAME)$(RESET_COL)$(RM_EXE_OUT)" @echo -e "$(GREEN)>>>>>>>> ./$(NAME) deleted\n>>>>>>>>$(RESET_COL)" re: fclean all pretty_print_bonus: - @echo -e "$(RED)\n------------------- $(NAME_BONUS) -------------------$(RESET_COL)\n" - -bonus: $(NAME_BONUS) + @echo -e "$(GREEN)\n------------------- $(NAME_BONUS) -------------------$(RESET_COL)\n" run: all ./$(NAME) $(RUN_ARGS) -# -# Debug rules -# -pretty_print_debug: - @echo -e "$(RED)\n------------------- $(DBG_EXE) -------------------$(RESET_COL)\n" - -debug: all pretty_print_debug $(DBG_OBJS) - @echo -e "\n$(ON_RED)>>>>>>>> Compiling $(DBG_EXE) ...$(RESET_COL)$(COMPILE_DBG_EXE_OUT)" - ./$(DBG_EXE) $(RUN_ARGS) - -.PHONY: all clean clean_libft fclean re bonus libft silent_libft pretty_print pretty_print_debug pretty_print_bonus run debug +.PHONY: all clean clean_libft fclean re bonus libft silent_libft pretty_print pretty_print_bonus run diff --git a/greater_than_ideas.txt b/greater_than_ideas.txt deleted file mode 100644 index a7acd51..0000000 --- a/greater_than_ideas.txt +++ /dev/null @@ -1,140 +0,0 @@ -3 4 1 7 10 6 5 8 9 2 - ^ - HEAD -- - x x x - - - - - => 3 -- - x x - - - x x - => 4 - -3 4 1 7 10 6 5 8 9 2 - ^ - HEAD -x x - x x - - - - x => 5 -x x - x - - - x x x => 6 - -12 6 2 10 8 4 16 7 18 13 1 9 5 3 14 19 15 11 17 20 - ^ - HEAD -- - - - - - - - - - x x - - x x - - x x => 6 -- - - - - - - - - - x x - - x x - - x x => 6 -- - - - - - - - - - x x - - x - x - x x => 6 -- - - - - - - - - - x - x - x - x - x x => 6 -- - - - - - - - - - x - - x x - x - x x => 6 - -12 6 2 10 8 4 16 7 18 13 1 9 5 3 14 19 15 11 17 20 - ^ - HEAD -- - x x - - x - x - - - - - - x - - - x => 6 -- - x - - x - x - - - x - - x - x - x x => 8 -->so there are different ways to calculate... - - TAIL - v -15 8 20 12 13 17 1 7 4 3 14 18 10 11 2 6 16 19 9 5 - ^ - HEAD -- - x - - - x x - - x x - - - - - x - - => 6 - -1 7 4 3 14 18 10 11 2 6 16 19 9 5 15 8 20 12 13 17 -x x -----yes------> x --no->x --no---> x x x (range = 3) -x x----yes------> x --no->x --no---> x x x - -1 7 4 3 14 18 10 11 2 6 16 19 9 5 15 8 20 12 13 17 (range = 4) -x --x-----------------x-------x------------x-x--x - -12 19 17 7 3 18 1 8 5 6 14 10 16 13 11 15 4 9 20 2 - -1 8 5 6 14 10 16 13 11 15 4 9 20 2 12 19 17 7 3 18 -y y n y y n y n n y n y n n y y n n n y =>10 - -1 8 5 6 14 10 16 13 11 15 4 9 20 2 12 19 17 7 3 18 -x--------------------------------x------------x--- (range = 1) 3, best = 3 -x--------------------------------x------------x--- (range = 2) 3, best = 3 -x-------------------------x-----------------x----- (range = 3) 3, best = 3 -x---x-x----x-----x-----x--------------x----------- (range = 4) 7 - o->x pop the last one -x---x-x----x-----x-----x--------------o--x-----x- 8 -x<--ox pop the last one -x---x-x----x-----x-----x-------o------x----------- 7 -x---x-x----x-----x-----x-------o----->o--x pop the last one -x---x-x----x-----x-----x-------o------o--x------x- 8 -x<--o 12. -I believe this gives a good ballpark of theoretical max, but it almost always gonna be less than this - - -1. Map values to their positions ! This way you have a lookup table and don't have to iterate through values -e.g. -val_pos[1] : 6 -val_pos[2] : 14 -val_pos[3] : 9 - (...) -val_pos[19] : 17 -val_pos[20] : 2 -They could all be iterators, so that they're easy to commonly increment/decrement. Should not be done more than a max of nb_vals times anyways -could store a max_value_left variable to check if max_value_left - curr_value + nb_increasing > - -new stack: -15 20 13 17 1 7 14 18 11 6 16 19 ---->DOESN'T WORK, b/c you might want to exclude some of them, therefore including some that are not there rn - -temp result for 100 with up to 3 - - -with delta_values: -1. - Nb tests done: 1000 - Average nb of moves: 575 - Worst nb of moves: 639 - Nb of moves above 575 : 507 -2. - Nb tests done: 1000 - Average nb of moves: 576 - Worst nb of moves: 651 - Nb of moves above 575 : 524 - -without delta_values -1. - Nb tests done: 1000 - Average nb of moves: 580 - Worst nb of moves: 649 - Nb of moves above 575 : 567 -2. - Nb tests done: 1000 - Average nb of moves: 581 - Worst nb of moves: 657 - Nb of moves above 575 : 573 - - -5500: - Average nb of moves: 5155 - (Test #414) Worst nb of moves: 5534 - Nb of moves above 5304 : 125 - - Nb tests done: 5001 - Average nb of moves: 5169 - (Test #2538) Worst nb of moves: 5634 - Nb of moves above 5500 : 22 - - - -for now seems to reduce the nb of the max_moves, but could be an outlier \ No newline at end of file diff --git a/include/push_swap.h b/include/push_swap.h index c67f635..261babb 100644 --- a/include/push_swap.h +++ b/include/push_swap.h @@ -6,7 +6,7 @@ /* By: iyahoui- Date: Mon, 9 May 2022 11:06:27 -0400 Subject: [PATCH 32/32] Fixed libft include in Makefile's `bonus` rule --- Makefile | 2 +- include/deques.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f006b97..becf389 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,7 @@ COMPILE_EXE_OUT = $$($(COMPILE_EXE) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\0 COMPILE_C = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< COMPILE_C_OUT = $$($(COMPILE_C) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') -COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) $(OBJS_BONUS) -o $(NAME_BONUS) +COMPILE_EXE_BONUS = $(CC) $(CFLAGS) $(LIBFT_FLAGS) $(INCLFLAGS) $(OBJS_BONUS) -o $(NAME_BONUS) COMPILE_EXE_BONUS_OUT = $$($(COMPILE_EXE_BONUS) 2>&1 | sed -e 's/error/\\\033[0;31merror\\\033[0m/g' -e 's/warning/\\\033[0;33mwarning\\\033[0m/g') COMPILE_C_BONUS = $(CC) $(CFLAGS) $(INCLFLAGS) -o $@ -c $< diff --git a/include/deques.h b/include/deques.h index 6a40b19..c7fc8f6 100644 --- a/include/deques.h +++ b/include/deques.h @@ -6,7 +6,7 @@ /* By: iyahoui-