From 48966f12832ac97228132e56fb3159099f3e466e Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 31 Jul 2022 11:55:45 +0300 Subject: cleanup --- Advent-of-Code-2021/AOC-1/aoc-1 | Bin 16640 -> 0 bytes Advent-of-Code-2021/AOC-1/aoc-1.c | 81 ------------- Advent-of-Code-2021/AOC-1/aoc-1.c~ | 1 - Advent-of-Code-2021/AOC-1/input-1.txt~ | 0 Advent-of-Code-2021/AOC-1/main.c | 81 +++++++++++++ Advent-of-Code-2021/AOC-11/main | Bin 21136 -> 0 bytes Advent-of-Code-2021/AOC-13/main | Bin 21624 -> 0 bytes Advent-of-Code-2021/AOC-14/aoc-14 | Bin 21216 -> 0 bytes Advent-of-Code-2021/AOC-14/aoc-14.c | 202 --------------------------------- Advent-of-Code-2021/AOC-14/main.c | 202 +++++++++++++++++++++++++++++++++ Advent-of-Code-2021/AOC-15/aoc-15 | Bin 16712 -> 0 bytes Advent-of-Code-2021/AOC-15/aoc-15.c | 128 --------------------- Advent-of-Code-2021/AOC-15/aoc-15.c~ | 0 Advent-of-Code-2021/AOC-15/input.txt~ | 0 Advent-of-Code-2021/AOC-15/main.c | 128 +++++++++++++++++++++ Advent-of-Code-2021/AOC-15/sample.txt~ | 0 Advent-of-Code-2021/AOC-2/aoc-2 | Bin 16568 -> 0 bytes Advent-of-Code-2021/AOC-2/aoc-2.c | 104 ----------------- Advent-of-Code-2021/AOC-2/aoc-2.c~ | 0 Advent-of-Code-2021/AOC-2/input-2.txt~ | 0 Advent-of-Code-2021/AOC-2/main.c | 104 +++++++++++++++++ Advent-of-Code-2021/AOC-25/aoc-25 | Bin 16896 -> 0 bytes Advent-of-Code-2021/AOC-25/aoc-25.c | 154 ------------------------- Advent-of-Code-2021/AOC-25/aoc-25.c~ | 139 ----------------------- Advent-of-Code-2021/AOC-25/input.txt~ | 0 Advent-of-Code-2021/AOC-25/main.c | 154 +++++++++++++++++++++++++ Advent-of-Code-2021/AOC-3/aoc-3 | Bin 16648 -> 0 bytes Advent-of-Code-2021/AOC-3/aoc-3.c | 86 -------------- Advent-of-Code-2021/AOC-3/aoc-3.c~ | 84 -------------- Advent-of-Code-2021/AOC-3/input.txt~ | 0 Advent-of-Code-2021/AOC-3/main.c | 86 ++++++++++++++ Advent-of-Code-2021/AOC-3/sample.txt~ | 0 Advent-of-Code-2021/AOC-5/main | Bin 21208 -> 0 bytes Advent-of-Code-2021/AOC-6/aoc-6 | Bin 16480 -> 0 bytes Advent-of-Code-2021/AOC-6/aoc-6.c | 78 ------------- Advent-of-Code-2021/AOC-6/aoc-6.c~ | 65 ----------- Advent-of-Code-2021/AOC-6/main.c | 78 +++++++++++++ Advent-of-Code-2021/AOC-7/aoc-7 | Bin 20984 -> 0 bytes Advent-of-Code-2021/AOC-7/aoc-7.c | 124 -------------------- Advent-of-Code-2021/AOC-7/main.c | 124 ++++++++++++++++++++ 40 files changed, 957 insertions(+), 1246 deletions(-) delete mode 100755 Advent-of-Code-2021/AOC-1/aoc-1 delete mode 100644 Advent-of-Code-2021/AOC-1/aoc-1.c delete mode 100644 Advent-of-Code-2021/AOC-1/aoc-1.c~ delete mode 100644 Advent-of-Code-2021/AOC-1/input-1.txt~ create mode 100644 Advent-of-Code-2021/AOC-1/main.c delete mode 100755 Advent-of-Code-2021/AOC-11/main delete mode 100755 Advent-of-Code-2021/AOC-13/main delete mode 100755 Advent-of-Code-2021/AOC-14/aoc-14 delete mode 100644 Advent-of-Code-2021/AOC-14/aoc-14.c create mode 100644 Advent-of-Code-2021/AOC-14/main.c delete mode 100755 Advent-of-Code-2021/AOC-15/aoc-15 delete mode 100644 Advent-of-Code-2021/AOC-15/aoc-15.c delete mode 100644 Advent-of-Code-2021/AOC-15/aoc-15.c~ delete mode 100644 Advent-of-Code-2021/AOC-15/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-15/main.c delete mode 100644 Advent-of-Code-2021/AOC-15/sample.txt~ delete mode 100755 Advent-of-Code-2021/AOC-2/aoc-2 delete mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c delete mode 100644 Advent-of-Code-2021/AOC-2/aoc-2.c~ delete mode 100644 Advent-of-Code-2021/AOC-2/input-2.txt~ create mode 100644 Advent-of-Code-2021/AOC-2/main.c delete mode 100755 Advent-of-Code-2021/AOC-25/aoc-25 delete mode 100644 Advent-of-Code-2021/AOC-25/aoc-25.c delete mode 100644 Advent-of-Code-2021/AOC-25/aoc-25.c~ delete mode 100644 Advent-of-Code-2021/AOC-25/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-25/main.c delete mode 100755 Advent-of-Code-2021/AOC-3/aoc-3 delete mode 100644 Advent-of-Code-2021/AOC-3/aoc-3.c delete mode 100644 Advent-of-Code-2021/AOC-3/aoc-3.c~ delete mode 100644 Advent-of-Code-2021/AOC-3/input.txt~ create mode 100644 Advent-of-Code-2021/AOC-3/main.c delete mode 100644 Advent-of-Code-2021/AOC-3/sample.txt~ delete mode 100755 Advent-of-Code-2021/AOC-5/main delete mode 100755 Advent-of-Code-2021/AOC-6/aoc-6 delete mode 100644 Advent-of-Code-2021/AOC-6/aoc-6.c delete mode 100644 Advent-of-Code-2021/AOC-6/aoc-6.c~ create mode 100644 Advent-of-Code-2021/AOC-6/main.c delete mode 100755 Advent-of-Code-2021/AOC-7/aoc-7 delete mode 100644 Advent-of-Code-2021/AOC-7/aoc-7.c create mode 100644 Advent-of-Code-2021/AOC-7/main.c (limited to 'Advent-of-Code-2021') diff --git a/Advent-of-Code-2021/AOC-1/aoc-1 b/Advent-of-Code-2021/AOC-1/aoc-1 deleted file mode 100755 index eb5fe13..0000000 Binary files a/Advent-of-Code-2021/AOC-1/aoc-1 and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-1/aoc-1.c b/Advent-of-Code-2021/AOC-1/aoc-1.c deleted file mode 100644 index 5574481..0000000 --- a/Advent-of-Code-2021/AOC-1/aoc-1.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include - -#define N 5000 - -int numbers[N]; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if (fp == NULL) - { - perror("Error while opening the file.\n"); - exit(EXIT_FAILURE); - } - - int i = 0; - int n = 0; - char *str = malloc(sizeof(char)*N); - while((ch= fgetc(fp)) != EOF) - { - if(ch != '\n') - { - str[i] = ch; - i += 1; - } - else - { - i = 0; - numbers[n] = atoi(str); - n += 1; - memset(str, ' ', sizeof(char)*N); - } - } - - free(str); - - fclose(fp); -} - -void PrintNumbers() -{ - for(int i=0; i numbers[(i-1)]) - bigger += 1; - } - - printf("Answer: %d", bigger); - */ - - // Part Two - int bigger = 0; - for(int i = 3; i - (numbers[i-3] + numbers[i-2] + numbers[i -1])) - bigger += 1; - } - - printf("Answer: %d", bigger); - - return 0; -} diff --git a/Advent-of-Code-2021/AOC-1/aoc-1.c~ b/Advent-of-Code-2021/AOC-1/aoc-1.c~ deleted file mode 100644 index 4525d8c..0000000 --- a/Advent-of-Code-2021/AOC-1/aoc-1.c~ +++ /dev/null @@ -1 +0,0 @@ -#includ diff --git a/Advent-of-Code-2021/AOC-1/input-1.txt~ b/Advent-of-Code-2021/AOC-1/input-1.txt~ deleted file mode 100644 index e69de29..0000000 diff --git a/Advent-of-Code-2021/AOC-1/main.c b/Advent-of-Code-2021/AOC-1/main.c new file mode 100644 index 0000000..5574481 --- /dev/null +++ b/Advent-of-Code-2021/AOC-1/main.c @@ -0,0 +1,81 @@ +#include +#include +#include + +#define N 5000 + +int numbers[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if (fp == NULL) + { + perror("Error while opening the file.\n"); + exit(EXIT_FAILURE); + } + + int i = 0; + int n = 0; + char *str = malloc(sizeof(char)*N); + while((ch= fgetc(fp)) != EOF) + { + if(ch != '\n') + { + str[i] = ch; + i += 1; + } + else + { + i = 0; + numbers[n] = atoi(str); + n += 1; + memset(str, ' ', sizeof(char)*N); + } + } + + free(str); + + fclose(fp); +} + +void PrintNumbers() +{ + for(int i=0; i numbers[(i-1)]) + bigger += 1; + } + + printf("Answer: %d", bigger); + */ + + // Part Two + int bigger = 0; + for(int i = 3; i + (numbers[i-3] + numbers[i-2] + numbers[i -1])) + bigger += 1; + } + + printf("Answer: %d", bigger); + + return 0; +} diff --git a/Advent-of-Code-2021/AOC-11/main b/Advent-of-Code-2021/AOC-11/main deleted file mode 100755 index 72ff31b..0000000 Binary files a/Advent-of-Code-2021/AOC-11/main and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-13/main b/Advent-of-Code-2021/AOC-13/main deleted file mode 100755 index 62869db..0000000 Binary files a/Advent-of-Code-2021/AOC-13/main and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-14/aoc-14 b/Advent-of-Code-2021/AOC-14/aoc-14 deleted file mode 100755 index 630caae..0000000 Binary files a/Advent-of-Code-2021/AOC-14/aoc-14 and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-14/aoc-14.c b/Advent-of-Code-2021/AOC-14/aoc-14.c deleted file mode 100644 index d23bfcb..0000000 --- a/Advent-of-Code-2021/AOC-14/aoc-14.c +++ /dev/null @@ -1,202 +0,0 @@ -#include -#include -#include -#include - -#if 0 -#define PFILE "sample.txt" -#else -#define PFILE "input.txt" -#endif - -#define T_CAP 100 -char template[T_CAP]; -size_t tmpl_sz = 0; - -#define R_CAP 100 -typedef struct { - char inp[2]; - char ch; -} rule_t; -rule_t rules[R_CAP]; -size_t rules_sz = 0; - -#define CAP 1000000 -typedef uint64_t lsize_t; -char product[CAP]; -lsize_t prod_sz = 0; - - -void Parse() -{ - - // some init - memset(template, '\0', T_CAP); - memset(product, '\0', CAP); - - char ch; - FILE *fp; - fp = fopen(PFILE, "r"); - - int mode = 0; // 0 - for template; 1 - for rules; 2 - intermid - int mode_s = 0; // 0 - has not encountered ' '; 1 - after ' ' - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n' && mode == 0) - { - mode = 2; - } - else if(ch == '\n' && mode == 2) - { - mode = 1; - } - else if(ch == '\n' && mode == 1) - { - memset(rules[rules_sz].inp, '\0', 2); - rules[rules_sz].ch = '\0'; - } - else if(ch != '\n' && mode == 0) - { - template[tmpl_sz] = ch; - tmpl_sz += 1; - } - else if(ch != '\n' && mode == 1) - { - switch(mode_s) - { - case 0: - if(rules[rules_sz].inp[0] == '\0') - { - rules[rules_sz].inp[0] = ch; - } - else - { - rules[rules_sz].inp[1] = ch; - mode_s = 1; - } - break; - case 1: - if(ch != ' ' && ch != '-' && ch != '>') - { - rules[rules_sz].ch = ch; - rules_sz += 1; - mode_s = 0; - } - } - } - } - - fclose(fp); -} - -void InsertAt(char ch, size_t pos) -{ - for(lsize_t i = prod_sz; i > pos; i--) - { - product[i] = product[i-1]; - } - product[pos] = ch; - - prod_sz += 1; -} - -void Part1() -{ - Parse(); - prod_sz = tmpl_sz; - memcpy(product, template, prod_sz); - - char elements[CAP]; memset(elements, '\0', CAP); - lsize_t positions[CAP]; - lsize_t inrt_sz = 0; - - printf("%s\n", product); - - for(int step = 0; step < 40; step++) - { - for(lsize_t i = 0; i < (prod_sz-1); i++) - { - for(int j = 0; j < rules_sz; j++) - { - if(product[i] == rules[j].inp[0] && - product[i+1] == rules[j].inp[1]) - { - elements[inrt_sz] = rules[j].ch; - positions[inrt_sz] = i + 1 + inrt_sz; //error potential - inrt_sz += 1; - break; - } - } - } - for(lsize_t i = 0; i < inrt_sz; i++) - { - InsertAt(elements[i], positions[i]); - } - inrt_sz = 0; - memset(elements, '\0', CAP); - } - - // Get count and subtract - lsize_t el_occurence[10]; - /* S - 0 */ - /* H - 1 */ - /* N - 2 */ - /* C - 3 */ - /* O - 4 */ - /* P - 5 */ - /* F - 6 */ - /* B - 7 */ - /* V - 8 */ - /* K - 9 */ - - for(lsize_t i = 0; i < prod_sz; i++) - { - switch(product[i]) - { - case 'S': el_occurence[0] += 1; break; - case 'H': el_occurence[1] += 1; break; - case 'N': el_occurence[2] += 1; break; - case 'C': el_occurence[3] += 1; break; - case 'O': el_occurence[4] += 1; break; - case 'P': el_occurence[5] += 1; break; - case 'F': el_occurence[6] += 1; break; - case 'B': el_occurence[7] += 1; break; - case 'V': el_occurence[8] += 1; break; - case 'K': el_occurence[9] += 1; break; - } - } - - //get biggest - lsize_t biggest = 0; - for(int i = 0; i < 10; i++) - { - int counter = 0; - for(int j = 0; j < 10; j++) - if(el_occurence[i] >= el_occurence[j]) counter += 1; - if(counter == 10) { biggest = el_occurence[i]; break; } - } - - //get smallest - lsize_t smallest = 0; - for(int i = 0; i < 10; i++) - { - int counter = 0; - for(int j = 0; j < 10; j++) - if(el_occurence[i] <= el_occurence[j]) counter += 1; - if(counter == 10) {smallest = el_occurence[i]; break; } - } - - lsize_t result = biggest - smallest; - printf("%llu-%llu=%llu", biggest, smallest, result); -} - -void Part2() -{ - -} - -int main(void) -{ - Part1(); - return 0; -} diff --git a/Advent-of-Code-2021/AOC-14/main.c b/Advent-of-Code-2021/AOC-14/main.c new file mode 100644 index 0000000..d23bfcb --- /dev/null +++ b/Advent-of-Code-2021/AOC-14/main.c @@ -0,0 +1,202 @@ +#include +#include +#include +#include + +#if 0 +#define PFILE "sample.txt" +#else +#define PFILE "input.txt" +#endif + +#define T_CAP 100 +char template[T_CAP]; +size_t tmpl_sz = 0; + +#define R_CAP 100 +typedef struct { + char inp[2]; + char ch; +} rule_t; +rule_t rules[R_CAP]; +size_t rules_sz = 0; + +#define CAP 1000000 +typedef uint64_t lsize_t; +char product[CAP]; +lsize_t prod_sz = 0; + + +void Parse() +{ + + // some init + memset(template, '\0', T_CAP); + memset(product, '\0', CAP); + + char ch; + FILE *fp; + fp = fopen(PFILE, "r"); + + int mode = 0; // 0 - for template; 1 - for rules; 2 - intermid + int mode_s = 0; // 0 - has not encountered ' '; 1 - after ' ' + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n' && mode == 0) + { + mode = 2; + } + else if(ch == '\n' && mode == 2) + { + mode = 1; + } + else if(ch == '\n' && mode == 1) + { + memset(rules[rules_sz].inp, '\0', 2); + rules[rules_sz].ch = '\0'; + } + else if(ch != '\n' && mode == 0) + { + template[tmpl_sz] = ch; + tmpl_sz += 1; + } + else if(ch != '\n' && mode == 1) + { + switch(mode_s) + { + case 0: + if(rules[rules_sz].inp[0] == '\0') + { + rules[rules_sz].inp[0] = ch; + } + else + { + rules[rules_sz].inp[1] = ch; + mode_s = 1; + } + break; + case 1: + if(ch != ' ' && ch != '-' && ch != '>') + { + rules[rules_sz].ch = ch; + rules_sz += 1; + mode_s = 0; + } + } + } + } + + fclose(fp); +} + +void InsertAt(char ch, size_t pos) +{ + for(lsize_t i = prod_sz; i > pos; i--) + { + product[i] = product[i-1]; + } + product[pos] = ch; + + prod_sz += 1; +} + +void Part1() +{ + Parse(); + prod_sz = tmpl_sz; + memcpy(product, template, prod_sz); + + char elements[CAP]; memset(elements, '\0', CAP); + lsize_t positions[CAP]; + lsize_t inrt_sz = 0; + + printf("%s\n", product); + + for(int step = 0; step < 40; step++) + { + for(lsize_t i = 0; i < (prod_sz-1); i++) + { + for(int j = 0; j < rules_sz; j++) + { + if(product[i] == rules[j].inp[0] && + product[i+1] == rules[j].inp[1]) + { + elements[inrt_sz] = rules[j].ch; + positions[inrt_sz] = i + 1 + inrt_sz; //error potential + inrt_sz += 1; + break; + } + } + } + for(lsize_t i = 0; i < inrt_sz; i++) + { + InsertAt(elements[i], positions[i]); + } + inrt_sz = 0; + memset(elements, '\0', CAP); + } + + // Get count and subtract + lsize_t el_occurence[10]; + /* S - 0 */ + /* H - 1 */ + /* N - 2 */ + /* C - 3 */ + /* O - 4 */ + /* P - 5 */ + /* F - 6 */ + /* B - 7 */ + /* V - 8 */ + /* K - 9 */ + + for(lsize_t i = 0; i < prod_sz; i++) + { + switch(product[i]) + { + case 'S': el_occurence[0] += 1; break; + case 'H': el_occurence[1] += 1; break; + case 'N': el_occurence[2] += 1; break; + case 'C': el_occurence[3] += 1; break; + case 'O': el_occurence[4] += 1; break; + case 'P': el_occurence[5] += 1; break; + case 'F': el_occurence[6] += 1; break; + case 'B': el_occurence[7] += 1; break; + case 'V': el_occurence[8] += 1; break; + case 'K': el_occurence[9] += 1; break; + } + } + + //get biggest + lsize_t biggest = 0; + for(int i = 0; i < 10; i++) + { + int counter = 0; + for(int j = 0; j < 10; j++) + if(el_occurence[i] >= el_occurence[j]) counter += 1; + if(counter == 10) { biggest = el_occurence[i]; break; } + } + + //get smallest + lsize_t smallest = 0; + for(int i = 0; i < 10; i++) + { + int counter = 0; + for(int j = 0; j < 10; j++) + if(el_occurence[i] <= el_occurence[j]) counter += 1; + if(counter == 10) {smallest = el_occurence[i]; break; } + } + + lsize_t result = biggest - smallest; + printf("%llu-%llu=%llu", biggest, smallest, result); +} + +void Part2() +{ + +} + +int main(void) +{ + Part1(); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-15/aoc-15 b/Advent-of-Code-2021/AOC-15/aoc-15 deleted file mode 100755 index 3fa17a1..0000000 Binary files a/Advent-of-Code-2021/AOC-15/aoc-15 and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-15/aoc-15.c b/Advent-of-Code-2021/AOC-15/aoc-15.c deleted file mode 100644 index c7e1157..0000000 --- a/Advent-of-Code-2021/AOC-15/aoc-15.c +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include -#include - -#define min(a, b) (((a) < (b)) ? (a) : (b)) - -#if 0 - #define N 1 -#else - #define N 5 -#endif - - -// part 2 doesnt work with input for some reason bruh -#if 1 - #define FILE_P "sample.txt" - #define T_CAP 10 * N - #define T_CAP_S 10 -#else - #define FILE_P "input.txt" - #define T_CAP 100 * N - #define T_CAP_S 100 -#endif - -int table[T_CAP][T_CAP]; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if(fp == NULL) - { - fprintf(stderr, "ERROR: something with file idk fuck you"); - exit(EXIT_FAILURE); - } - - int i = 0; - int j = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n') { i += 1; j = 0; continue; } - - table[i][j] = (ch - '0'); - j += 1; - } - - fclose(fp); -} - -void FindRisk() -{ - // dont add to total risk - table[0][0] = 0; - - for(int i=1; i +#include +#include + +#define min(a, b) (((a) < (b)) ? (a) : (b)) + +#if 0 + #define N 1 +#else + #define N 5 +#endif + + +// part 2 doesnt work with input for some reason bruh +#if 1 + #define FILE_P "sample.txt" + #define T_CAP 10 * N + #define T_CAP_S 10 +#else + #define FILE_P "input.txt" + #define T_CAP 100 * N + #define T_CAP_S 100 +#endif + +int table[T_CAP][T_CAP]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + int j = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i += 1; j = 0; continue; } + + table[i][j] = (ch - '0'); + j += 1; + } + + fclose(fp); +} + +void FindRisk() +{ + // dont add to total risk + table[0][0] = 0; + + for(int i=1; i -#include -#include - -int pos = 0; -int depth = 0; -int aim = 0; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if (fp == NULL) - { - perror("Error while opening the file.\n"); - exit(EXIT_FAILURE); - } - - char command; - char char_x_val; - int current_type = 0; // 0 - command; 1 - skip; 2 - val - /* Part 1 - while((ch= fgetc(fp)) != EOF) - { - if(ch == ' ') - { - current_type = 2; - } - else if(ch == '\n') - { - int x = atoi(&char_x_val); - switch(command) - { - case 'f': - pos += x; - break; - case 'd': - depth += x; - break; - case 'u': - depth -= x; - } - - current_type = 0; - } - else if(current_type == 0) - { - command = ch; - current_type = 1; - } - else if(current_type == 2) - { - char_x_val = ch; - } - } - */ - - /* Part2 */ - while((ch= fgetc(fp)) != EOF) - { - if(ch == ' ') - { - current_type = 2; - } - else if(ch == '\n') - { - int x = atoi(&char_x_val); - switch(command) - { - case 'f': - pos += x; - depth += aim * x; - break; - case 'd': - aim += x; - break; - case 'u': - aim -= x; - } - - current_type = 0; - } - else if(current_type == 0) - { - command = ch; - current_type = 1; - } - else if(current_type == 2) - { - char_x_val = ch; - } - } - - fclose(fp); -} - -int main(void) -{ - ParseInput("input-2.txt"); - printf("pos: %d, depth: %d; product: %d", pos, depth, pos * depth); - return 0; -} diff --git a/Advent-of-Code-2021/AOC-2/aoc-2.c~ b/Advent-of-Code-2021/AOC-2/aoc-2.c~ deleted file mode 100644 index e69de29..0000000 diff --git a/Advent-of-Code-2021/AOC-2/input-2.txt~ b/Advent-of-Code-2021/AOC-2/input-2.txt~ deleted file mode 100644 index e69de29..0000000 diff --git a/Advent-of-Code-2021/AOC-2/main.c b/Advent-of-Code-2021/AOC-2/main.c new file mode 100644 index 0000000..6c212b1 --- /dev/null +++ b/Advent-of-Code-2021/AOC-2/main.c @@ -0,0 +1,104 @@ +#include +#include +#include + +int pos = 0; +int depth = 0; +int aim = 0; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if (fp == NULL) + { + perror("Error while opening the file.\n"); + exit(EXIT_FAILURE); + } + + char command; + char char_x_val; + int current_type = 0; // 0 - command; 1 - skip; 2 - val + /* Part 1 + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + break; + case 'd': + depth += x; + break; + case 'u': + depth -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + */ + + /* Part2 */ + while((ch= fgetc(fp)) != EOF) + { + if(ch == ' ') + { + current_type = 2; + } + else if(ch == '\n') + { + int x = atoi(&char_x_val); + switch(command) + { + case 'f': + pos += x; + depth += aim * x; + break; + case 'd': + aim += x; + break; + case 'u': + aim -= x; + } + + current_type = 0; + } + else if(current_type == 0) + { + command = ch; + current_type = 1; + } + else if(current_type == 2) + { + char_x_val = ch; + } + } + + fclose(fp); +} + +int main(void) +{ + ParseInput("input-2.txt"); + printf("pos: %d, depth: %d; product: %d", pos, depth, pos * depth); + return 0; +} diff --git a/Advent-of-Code-2021/AOC-25/aoc-25 b/Advent-of-Code-2021/AOC-25/aoc-25 deleted file mode 100755 index 1528c81..0000000 Binary files a/Advent-of-Code-2021/AOC-25/aoc-25 and /dev/null differ diff --git a/Advent-of-Code-2021/AOC-25/aoc-25.c b/Advent-of-Code-2021/AOC-25/aoc-25.c deleted file mode 100644 index 089b141..0000000 --- a/Advent-of-Code-2021/AOC-25/aoc-25.c +++ /dev/null @@ -1,154 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#define XLEN 139 //10 -#define YLEN 137 //9 -#define LEN (XLEN * YLEN) - -typedef struct Sea_cuc_move { - int from_pos; - int to_pos; -} Sea_cuc_move; - -char map[LEN]; -char map_bak[LEN]; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if(fp == NULL) - { - fprintf(stderr, "ERROR: something with file idk what fuck you"); - exit(EXIT_FAILURE); - } - - int i = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n') continue; - - map[i] = ch; - i++; - } - - fclose(fp); -} - -void Move(char type, Sea_cuc_move pos) -{ - map[pos.from_pos] = '.'; - map[pos.to_pos] = type; -} - -void MoveEast() -{ - Sea_cuc_move positions_east[5000]; - int cucs_east = 0; - - for(int i=0; i') - { - int x = i % XLEN; - if(x == (XLEN-1)) - { - if(map[i - x] != '.') - continue; - - positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; - cucs_east += 1; - } - else if(map[i+1] == '.') - { - positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; - cucs_east += 1; - } - - } - } - - assert(cucs_east < 5000); - - if(cucs_east != 0) - for(int i=0; i', positions_east[i]); -} - -void MoveSouth() -{ - Sea_cuc_move positions_south[5000]; - int cucs_south = 0; - - for(int i=0; i -#include -#include -#include -#include -#include - -#define XLEN 139 //10 -#define YLEN 137 //9 -#define LEN (XLEN * YLEN) - -typedef struct Sea_cuc_move { - int from_pos; - int to_pos; -} Sea_cuc_move; - -char map[LEN]; -char map_bak[LEN]; - -void ParseInput(char *input) -{ - for(int i=0; i') - { - int x = i % XLEN; - if(x == (XLEN-1)) - { - if(map[i - x] != '.') - continue; - - positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; - cucs_east += 1; - } - else if(map[i+1] == '.') - { - positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; - cucs_east += 1; - } - - } - } - - assert(cucs_east < 5000); - - if(cucs_east != 0) - for(int i=0; i', positions_east[i]); -} - -void MoveSouth() -{ - Sea_cuc_move positions_south[5000]; - int cucs_south = 0; - - for(int i=0; i +#include +#include +#include +#include +#include + +#define XLEN 139 //10 +#define YLEN 137 //9 +#define LEN (XLEN * YLEN) + +typedef struct Sea_cuc_move { + int from_pos; + int to_pos; +} Sea_cuc_move; + +char map[LEN]; +char map_bak[LEN]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') continue; + + map[i] = ch; + i++; + } + + fclose(fp); +} + +void Move(char type, Sea_cuc_move pos) +{ + map[pos.from_pos] = '.'; + map[pos.to_pos] = type; +} + +void MoveEast() +{ + Sea_cuc_move positions_east[5000]; + int cucs_east = 0; + + for(int i=0; i') + { + int x = i % XLEN; + if(x == (XLEN-1)) + { + if(map[i - x] != '.') + continue; + + positions_east[cucs_east] = (Sea_cuc_move){i, i - x}; + cucs_east += 1; + } + else if(map[i+1] == '.') + { + positions_east[cucs_east] = (Sea_cuc_move){i, i + 1}; + cucs_east += 1; + } + + } + } + + assert(cucs_east < 5000); + + if(cucs_east != 0) + for(int i=0; i', positions_east[i]); +} + +void MoveSouth() +{ + Sea_cuc_move positions_south[5000]; + int cucs_south = 0; + + for(int i=0; i -#include -#include -#include -#include - -#define N 5 -#define INP_COUNT 12 - -int table[N]; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if(fp == NULL) - { - fprintf(stderr, "ERROR: something with file idk what fuck you"); - exit(EXIT_FAILURE); - } - - int i = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n') { i = 0; continue; } - - if(ch == '1') - table[i] += 1; - - i += 1; - } - - fclose(fp); -} - -void PrintTable() -{ - for(int i=0; i (INP_COUNT/2)) - { - gamma_val = gamma_val | (1 << (N-1-i)); - } - } - - int epsilon_val = gamma_val; - for(int i=0; i -#include -#include -#include -#include - -#define N 5 -#define INP_COUNT 12 - -int table[N]; - -void ParseInput(char *filepath) -{ - char ch; - FILE *fp; - fp = fopen(filepath, "r"); - - if(fp == NULL) - { - fprintf(stderr, "ERROR: something with file idk what fuck you"); - exit(EXIT_FAILURE); - } - - int i = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch == '\n') { i = 0; continue; } - - if(ch == '1') - table[i] += 1; - - i += 1; - } -} - -void PrintTable() -{ - for(int i=0; i (INP_COUNT/2)) - { - gamma_val = gamma_val | (1 << (N-1-i)); - } - } - - int epsilon_val = gamma_val; - for(int i=0; i +#include +#include +#include +#include + +#define N 5 +#define INP_COUNT 12 + +int table[N]; + +void ParseInput(char *filepath) +{ + char ch; + FILE *fp; + fp = fopen(filepath, "r"); + + if(fp == NULL) + { + fprintf(stderr, "ERROR: something with file idk what fuck you"); + exit(EXIT_FAILURE); + } + + int i = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch == '\n') { i = 0; continue; } + + if(ch == '1') + table[i] += 1; + + i += 1; + } + + fclose(fp); +} + +void PrintTable() +{ + for(int i=0; i (INP_COUNT/2)) + { + gamma_val = gamma_val | (1 << (N-1-i)); + } + } + + int epsilon_val = gamma_val; + for(int i=0; i -#include -#include -#include -#include - -#define N 9 -#define MAXDAYS 256 - -u_int64_t table[N]; -u_int64_t temp_table[N]; - -void PrintTable() -{ - for(int i=0; i -#include -#include -#include - -#define N 9 -#define MAXDAYS 80 - -int table[N]; - -void PrintTable() -{ - for(int i=0; i +#include +#include +#include +#include + +#define N 9 +#define MAXDAYS 256 + +u_int64_t table[N]; +u_int64_t temp_table[N]; + +void PrintTable() +{ + for(int i=0; i -#include -#include - -#define CAP 3000 - -#if 0 -#define PFILE "sample.txt" -#else -#define PFILE "input.txt" -#endif - -int vals[CAP]; -size_t vals_sz = 0; - -void Parse() -{ - // Parse - char ch; - FILE *fp; - fp = fopen(PFILE, "r"); - - char int_buf[6]; - memset(int_buf, '\0', sizeof(int_buf)); - int n = 0; - while((ch = fgetc(fp)) != EOF) - { - if(ch != ',') - { - int_buf[n] = ch; - n += 1; - continue; - } - - vals[vals_sz] = atoi(int_buf); - vals_sz += 1; - memset(int_buf, '\0', sizeof(int_buf)); - n = 0; - } - -} - -void Part1() -{ - Parse(); - size_t fuel_arr[CAP]; - size_t fuel = 0; - - for(int i = 0; i < CAP; i++) - { - int target = i; - for(int j = 0; j < vals_sz; j++) - fuel += abs(target - vals[j]); - - fuel_arr[i] = fuel; - fuel = 0; - } - - // Find the smallest in the fuel array - for(size_t i = 0; i < CAP; i++) - { - size_t counter = 0; - for(int j = 0; j < CAP; j++) - { - if(fuel_arr[i] <= fuel_arr[j]) - counter += 1; - } - - if(counter == CAP) - { - printf("%d\n", fuel_arr[i]); - break; - } - } -} - -size_t CountFuel(int target) -{ - // somehow works idk - size_t sum = 0; - for(size_t i = 1; i <= target; i++) - sum += i; - return sum; -} - -void Part2() -{ - Parse(); - size_t fuel_arr[CAP]; - size_t fuel = 0; - - for(int i = 0; i < CAP; i++) - { - size_t target = i; - for(int j = 0; j < vals_sz; j++) - fuel += CountFuel(abs(target - vals[j])); - - fuel_arr[i] = fuel; - fuel = 0; - } - - // Find the smallest in the fuel array - for(size_t i = 0; i < CAP; i++) - { - size_t counter = 0; - for(size_t j = 0; j < CAP; j++) - { - if(fuel_arr[i] <= fuel_arr[j]) - counter += 1; - } - - if(counter == CAP) - { - printf("%d: %d\n", i, fuel_arr[i]); - break; - } - } -} - -int main() -{ - Part2(); - return 0; -} diff --git a/Advent-of-Code-2021/AOC-7/main.c b/Advent-of-Code-2021/AOC-7/main.c new file mode 100644 index 0000000..165c671 --- /dev/null +++ b/Advent-of-Code-2021/AOC-7/main.c @@ -0,0 +1,124 @@ +#include +#include +#include + +#define CAP 3000 + +#if 0 +#define PFILE "sample.txt" +#else +#define PFILE "input.txt" +#endif + +int vals[CAP]; +size_t vals_sz = 0; + +void Parse() +{ + // Parse + char ch; + FILE *fp; + fp = fopen(PFILE, "r"); + + char int_buf[6]; + memset(int_buf, '\0', sizeof(int_buf)); + int n = 0; + while((ch = fgetc(fp)) != EOF) + { + if(ch != ',') + { + int_buf[n] = ch; + n += 1; + continue; + } + + vals[vals_sz] = atoi(int_buf); + vals_sz += 1; + memset(int_buf, '\0', sizeof(int_buf)); + n = 0; + } + +} + +void Part1() +{ + Parse(); + size_t fuel_arr[CAP]; + size_t fuel = 0; + + for(int i = 0; i < CAP; i++) + { + int target = i; + for(int j = 0; j < vals_sz; j++) + fuel += abs(target - vals[j]); + + fuel_arr[i] = fuel; + fuel = 0; + } + + // Find the smallest in the fuel array + for(size_t i = 0; i < CAP; i++) + { + size_t counter = 0; + for(int j = 0; j < CAP; j++) + { + if(fuel_arr[i] <= fuel_arr[j]) + counter += 1; + } + + if(counter == CAP) + { + printf("%d\n", fuel_arr[i]); + break; + } + } +} + +size_t CountFuel(int target) +{ + // somehow works idk + size_t sum = 0; + for(size_t i = 1; i <= target; i++) + sum += i; + return sum; +} + +void Part2() +{ + Parse(); + size_t fuel_arr[CAP]; + size_t fuel = 0; + + for(int i = 0; i < CAP; i++) + { + size_t target = i; + for(int j = 0; j < vals_sz; j++) + fuel += CountFuel(abs(target - vals[j])); + + fuel_arr[i] = fuel; + fuel = 0; + } + + // Find the smallest in the fuel array + for(size_t i = 0; i < CAP; i++) + { + size_t counter = 0; + for(size_t j = 0; j < CAP; j++) + { + if(fuel_arr[i] <= fuel_arr[j]) + counter += 1; + } + + if(counter == CAP) + { + printf("%d: %d\n", i, fuel_arr[i]); + break; + } + } +} + +int main() +{ + Part2(); + return 0; +} -- cgit v1.2.3