Initial commit.

This commit is contained in:
2025-11-30 12:12:05 -05:00
commit 17e3e4f9c5
5 changed files with 74 additions and 0 deletions

1
2015/one/input.txt Normal file

File diff suppressed because one or more lines are too long

50
2015/one/solution.c Normal file
View File

@@ -0,0 +1,50 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
/* Read the data. */
if (!(argc - 1)) exit(1);
FILE* f = fopen(argv[1], "rb");
if (!f) exit(2); // No file.
fseek(f, 0, SEEK_END);
long fsz = ftell(f);
fseek(f, 0, SEEK_SET);
if (fsz < 0) {
fclose(f);
exit(3); // Bad stream.
}
char* buf = malloc(fsz + 1);
if (!buf) {
fclose(f);
exit(4); // Bad malloc.
}
size_t nch = fread(buf, 1, fsz, f);
if (nch != fsz) {
free(buf);
exit(5); // Incomplete read.
}
buf[fsz] = '\0'; // Terminate.
int floor = 0;
int basement_pos = -1;
/* Parse the data. */
for (int i = 0; i < fsz; i++) {
switch (buf[i]) {
case '(': floor++; break;
case ')': floor--; break;
default: continue;
}
if (floor == -1 && basement_pos == -1) { basement_pos = i + 1; }
}
printf("Part 1 solution: %d\n", floor);
printf("Part 2 solution: %d\n", basement_pos);
return 0;
}