diff --git a/.gitignore b/.gitignore index a35876c..c4569c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .extrc 2019/aoc2019 +2019/CMakeFiles/ 2019/CMakeCache.txt 2019/cmake_install.cmake 2019/Makefile diff --git a/2019/CMakeLists.txt b/2019/CMakeLists.txt index f4b89c4..a289d4e 100644 --- a/2019/CMakeLists.txt +++ b/2019/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.0) project(aoc2019 LANGUAGES C) -set(DAY 3) -set(PART 2) +set(DAY 4) +set(PART 1) add_executable(aoc2019 days/${DAY}/${PART}/main.c) #target_link_libraries(aoc2019 m) # If math.h is required, use this diff --git a/2019/days/3/2/main.c b/2019/days/3/2/main.c index 673f609..0823d5d 100644 --- a/2019/days/3/2/main.c +++ b/2019/days/3/2/main.c @@ -1,12 +1,12 @@ #include #include -#define POINTLIMIT 500000 +#define POINTLIMIT 200000 int main(void) { - signed int lines[2][POINTLIMIT][3]; + signed int lines[2][POINTLIMIT][2]; unsigned int bufpos = 0, pp = 0, linep[2]; - short line = 0, bufls = 0, res; + short line = 0, bufls = 0, res = -1; char numbuf[16], dir, c; fprintf(stderr,"\e[1;31mParsing input...\n"); while ((c=getchar())!=EOF) { @@ -21,7 +21,6 @@ int main(void) { } lines[line][pp][0] = lines[line][start][0]; lines[line][pp][1] = lines[line][start][1]; - lines[line][pp][2] = 0; int va,val; switch (dir) { case 'U': va = 1, val=1; break; @@ -37,7 +36,8 @@ int main(void) { line++; pp = 0; } - bufpos = 0, bufls = 0; + bufpos = 0; + bufls = 0; } else if (c >= '0' && c <= '9') { numbuf[bufpos++] = c; bufls = 1; @@ -45,32 +45,22 @@ int main(void) { return 1; } } - fprintf(stderr,"Finding closest match...\n"); - int num[3] = {0}; + fprintf(stderr,"\nFinding closest match...\n"); + int poi[POINTLIMIT][2][2], poip; // Comparasion buffer for (int x=0, m=0; x num[1] + num[2]) { - num[0] = num[1] + num[2]; - } - fprintf(stderr,"\e[0mFound %i|%i and %i|%i!\n\e[1;31mFound %i match(es)...\r", lines[0][x][0], lines[0][x][1], lines[1][y][0], lines[1][y][1], ++m); + poi[poip][0][0] = lines[0][x][0]; // Positions of the points + poi[poip][0][1] = lines[0][x][1]; + poi[poip][1][0] = x; // Steps of points + poi[poip++][1][1] = y; } } - res = num[0]; } + free(lines); // We don't need unimportant points anymore fprintf(stderr,"\nBingo:\n"); printf("%i\n", res); return 0; diff --git a/2019/days/4/1/input b/2019/days/4/1/input new file mode 100644 index 0000000..2793642 --- /dev/null +++ b/2019/days/4/1/input @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,1,6,19,2,19,6,23,1,23,5,27,1,9,27,31,1,31,10,35,2,35,9,39,1,5,39,43,2,43,9,47,1,5,47,51,2,51,13,55,1,55,10,59,1,59,10,63,2,9,63,67,1,67,5,71,2,13,71,75,1,75,10,79,1,79,6,83,2,13,83,87,1,87,6,91,1,6,91,95,1,10,95,99,2,99,6,103,1,103,5,107,2,6,107,111,1,10,111,115,1,115,5,119,2,6,119,123,1,123,5,127,2,127,6,131,1,131,5,135,1,2,135,139,1,139,13,0,99,2,0,14,0 diff --git a/2019/days/4/1/main.c b/2019/days/4/1/main.c index e69de29..e7b6227 100644 --- a/2019/days/4/1/main.c +++ b/2019/days/4/1/main.c @@ -0,0 +1,33 @@ +#include + +#define MINV 123257 +#define MAXV 647015 + +int main(void) { + int count=0; + fprintf(stderr,"\e[1J"); + for (int i=MINV+1, s=0, dd=0; i>MINV && i