slower, but should be faster :(
This commit is contained in:
parent
2e4c79664f
commit
e1dadd9fbf
4 changed files with 9001 additions and 33 deletions
124
4_2/main.c
124
4_2/main.c
|
|
@ -7,6 +7,10 @@
|
|||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
|
||||
#define ANSI_COLOR_RED "\x1b[31m"
|
||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||
#define ANSI_COLOR_RESET "\x1b[0m"
|
||||
|
||||
char input[] =
|
||||
{
|
||||
#embed "input.txt"
|
||||
|
|
@ -29,13 +33,13 @@ void print_field(uint8_t* surrounds){
|
|||
for(int x = 0; x < height; x++){
|
||||
for(int y = 0; y < width; y++){
|
||||
if((surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
printf("%d", surrounds[(x)*(width+2)+(y)]-0x80);
|
||||
printf(ANSI_COLOR_GREEN"%d\t", surrounds[(x)*(width+2)+(y)]-0x80);
|
||||
}else{
|
||||
//printf("%c", input[(x)*(width+1)+(y)]);
|
||||
printf(".");
|
||||
printf(ANSI_COLOR_RED "%d\t", surrounds[(x)*(width+2)+(y)]);
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf(ANSI_COLOR_RESET "\n");
|
||||
}
|
||||
printf("==============================================\n");
|
||||
}
|
||||
|
|
@ -84,38 +88,39 @@ int main(int argc, char *argv[]){
|
|||
uint64_t count_2 = 0;
|
||||
bool cont = true;
|
||||
int* removes = calloc((height)*(width)*2, sizeof(int));
|
||||
int* new_removes = calloc((height)*(width)*2, sizeof(int));
|
||||
int new_count_2 = 0;
|
||||
count_2 = 0;
|
||||
|
||||
for(int x = 0; x < height; x++){
|
||||
for(int y = 0; y < width; y++){
|
||||
if((surrounds[(x)*(width+2)+(y)]&0x7f) < 4 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
|
||||
removes[count_2*2] = x;
|
||||
removes[count_2*2+1] = y;
|
||||
count_2++;
|
||||
//printf("removing %d, %d\n", x, y);
|
||||
//input[(x)*(width+1)+(y)] = 'x';
|
||||
//printf("%d", surrounds[(x)*width+(y)]);
|
||||
}//if((surrounds[(x)*(width+2)+(y)]&0x7f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
//cont = false;
|
||||
//}
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
//print_field(surrounds);
|
||||
count += count_2;
|
||||
|
||||
//printf("count = %lu\n========\n", count);
|
||||
if(count_2 == 0){
|
||||
cont = false;
|
||||
}
|
||||
//printf("cont: %s\n", cont ? "true" : "false");
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
//printf("count = %lu\n", count);
|
||||
|
||||
while (cont){
|
||||
count_2 = 0;
|
||||
for(int x = 0; x < height; x++){
|
||||
for(int y = 0; y < width; y++){
|
||||
if((surrounds[(x)*(width+2)+(y)]&0x7f) < 4 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
|
||||
removes[count_2*2] = x;
|
||||
removes[count_2*2+1] = y;
|
||||
count_2++;
|
||||
//printf("removing %d, %d\n", x, y);
|
||||
//input[(x)*(width+1)+(y)] = 'x';
|
||||
//printf("%d", surrounds[(x)*width+(y)]);
|
||||
}//if((surrounds[(x)*(width+2)+(y)]&0x7f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
//cont = false;
|
||||
//}
|
||||
}
|
||||
//printf("\n");
|
||||
}
|
||||
//print_field(surrounds);
|
||||
count += count_2;
|
||||
|
||||
//printf("count = %lu\n========\n", count);
|
||||
if(count_2 == 0){
|
||||
cont = false;
|
||||
}
|
||||
//printf("cont: %s\n", cont ? "true" : "false");
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
//printf("count = %lu\n", count);
|
||||
|
||||
|
||||
for(int i = 0; i < count_2; i++){
|
||||
int x = removes[i*2];
|
||||
int y = removes[i*2+1];
|
||||
|
|
@ -128,7 +133,60 @@ int main(int argc, char *argv[]){
|
|||
surrounds[(x+1)*(width+2)+(y-1)] -= 1;
|
||||
surrounds[(x+1)*(width+2)+(y)] -= 1;
|
||||
surrounds[(x+1)*(width+2)+(y+1)] -= 1;
|
||||
//printf("removed %d, %d\n", removes[i*2], removes[i*2+1]);
|
||||
//print_field(surrounds);
|
||||
}
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
|
||||
new_count_2 = 0;
|
||||
for(int i = 0; i < count_2; i++){
|
||||
int x = removes[i*2];
|
||||
int y = removes[i*2+1];
|
||||
for(int xd = -1; xd<=1; xd++){
|
||||
for(int yd = -1; yd<=1; yd++){
|
||||
if((surrounds[(x+xd)*(width+2)+(y+yd)]&0x7f) < 4 && (surrounds[(x+xd)*(width+2)+(y+yd)]&0x80) == 0x80){
|
||||
//this if clause should be irrellevant, because the paper roll is already removed
|
||||
if(!(xd == 0 && yd == 0)){
|
||||
bool repeat = false;
|
||||
for(int o = 0; o < new_count_2; o++){
|
||||
if(new_removes[o*2] == x+xd &&
|
||||
new_removes[o*2+1] == y+yd){
|
||||
repeat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!repeat){
|
||||
new_removes[new_count_2*2] = x+xd;
|
||||
new_removes[new_count_2*2+1] = y+yd;
|
||||
//printf("Tagged for removal %d, %d\n", new_removes[new_count_2*2], new_removes[new_count_2*2+1]);
|
||||
new_count_2++;
|
||||
}
|
||||
}
|
||||
}if((surrounds[(x)*(width+2)+(y)]&0x7f) > 8 && (surrounds[(x)*(width+2)+(y)]&0x80) == 0x80){
|
||||
//printf("underflow detechted, aborting\n");
|
||||
cont = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//for(int i = 0; i < new_count_2; i++){
|
||||
// printf("removed %d, %d\n", new_removes[i*2], new_removes[i*2+1]);
|
||||
//}
|
||||
|
||||
memcpy(removes, new_removes, new_count_2*2*sizeof(int));
|
||||
count_2 = new_count_2;
|
||||
//print_field(surrounds);
|
||||
count += count_2;
|
||||
|
||||
//printf("count_2 = %lu\n========\n", count_2);
|
||||
if(count_2 == 0){
|
||||
cont = false;
|
||||
}
|
||||
//printf("cont: %s\n", cont ? "true" : "false");
|
||||
//printf("count_2 = %lu\n", count_2);
|
||||
//printf("count = %lu\n", count);
|
||||
|
||||
|
||||
//print_field(surrounds);
|
||||
//sleep(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue