diff options
Diffstat (limited to 'advent-of-code/2023/01/part1.c')
| -rw-r--r-- | advent-of-code/2023/01/part1.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/advent-of-code/2023/01/part1.c b/advent-of-code/2023/01/part1.c new file mode 100644 index 0000000..3aace2a --- /dev/null +++ b/advent-of-code/2023/01/part1.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#include "str.h" + + +int main() { + FILE* fp = fopen("./input", "r"); + int sum = 0; + while (1) { + char *line = str_strip(fgetline(fp)); + if (line == NULL || strlen(line) == 0) { + break; + } + int d1 = -1, d2 = -1; + while (*line != '\0') { + if (isdigit(*line)) { + if (d1 == -1) d1 = *line - '0'; + d2 = *line - '0'; + } + line++; + } + if (d2 == -1) d2 = d1; + sum += d1 * 10 + d2; + } + printf("%d\n", sum); + return 0; +} + |
