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

14
.clang-format Normal file
View File

@@ -0,0 +1,14 @@
---
AlignConsecutiveShortCaseStatements:
Enabled: true
AcrossEmptyLines: true
AcrossComments: true
IndentCaseLabels: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
IndentWidth: 4
PointerAlignment: Left
AlignAfterOpenBracket: BlockIndent

8
.gitignore vendored Normal file
View File

@@ -0,0 +1,8 @@
*.o
*.so
tags
*.out
.cache
build/*
vgcore.*
compile_commands.json

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;
}

1
README.md Normal file
View File

@@ -0,0 +1 @@
My solutions to [Advent of Code](https://adventofcode.com/).