From aec1c07260257ba7c28eff53f422ddb7daaf316a Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 31 Jul 2022 11:46:17 +0300 Subject: Big Bang --- Advent-of-Code-2021/AOC-15/aoc-15.c | 128 ++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Advent-of-Code-2021/AOC-15/aoc-15.c (limited to 'Advent-of-Code-2021/AOC-15/aoc-15.c') diff --git a/Advent-of-Code-2021/AOC-15/aoc-15.c b/Advent-of-Code-2021/AOC-15/aoc-15.c new file mode 100644 index 0000000..c7e1157 --- /dev/null +++ b/Advent-of-Code-2021/AOC-15/aoc-15.c @@ -0,0 +1,128 @@ +#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