diff --git a/2015_day_3/day_3.c b/2015_day_3/day_3.c index 741b98e..4c52e47 100644 --- a/2015_day_3/day_3.c +++ b/2015_day_3/day_3.c @@ -96,6 +96,7 @@ void movenorth(Housearray* f, char direction){ int grid_x = f->x·coord - f->x_coord_origin; int grid_y = f->y·coord - f->y_coord_origin; f->houses[grid_y][grid_x]++; + //comment } void movesouth(Housearray* f, char direction){ @@ -106,7 +107,7 @@ void movesouth(Housearray* f, char direction){ //update y coordinate f->y·coord++; //check if expansion needed - if (f->y·coord > f->rows·in·array){ + if (f->y·coord - f->y_coord_origin >= f->rows·in·array){ //Expand south int new_rows = old_rows +1; int new_cols = old_cols; @@ -115,12 +116,12 @@ void movesouth(Housearray* f, char direction){ for (int i = 0; i< old_rows; ++i){ new_grid[i] = f->houses[i]; } - new_grid[0] = (int*)calloc(new_cols, sizeof(int));//Initialising the new row to empty + new_grid[new_rows - 1] = (int*)calloc(new_cols, sizeof(int));//Initialising the new row to empty free(f->houses); f->houses = new_grid; f->rows·in·array = new_rows; f->columns·in·array = new_cols; - f->y_coord_origin++; + } //updating the visit count int grid_x = f->x·coord - f->x_coord_origin;