Restore aoc backup.

This commit is contained in:
2024-07-05 19:55:39 -04:00
parent e55b92bb46
commit d84e861477
29 changed files with 4175 additions and 0 deletions

31
2015/day01/answer01.c Normal file
View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
int main() {
int32_t floor = 0;
FILE *file = fopen("input", "r");
if (file == NULL) {
perror("Error opening file.");
return 1;
}
char buffer[256];
while (fgets(buffer, sizeof(buffer), file) != NULL) {
uint16_t length = strlen(buffer);
for (uint16_t i = 0; i < length; i++) {
if (buffer[i] == '(') floor++;
else if(buffer[i] == ')') floor--;
}
}
if (ferror(file)) {
perror("Error reading from file.");
return 1;
}
fclose(file);
printf("floor: %i\n", floor);
return 0;
}

47
2015/day01/answer02.c Normal file
View File

@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
int main() {
int32_t floor = 0;
uint32_t pos = 0;
FILE *file = fopen("input", "r");
if (file == NULL) {
perror("Error opening file.");
return 1;
}
char buffer[256];
bool breakout = false;
while (fgets(buffer, sizeof(buffer), file) != NULL) {
uint16_t length = strlen(buffer);
if (breakout) break;
for (uint16_t i = 0; i < length; i++) {
if (buffer[i] == '(') {
floor++;
pos++;
}
else if (buffer[i] == ')') {
floor--;
pos++;
}
if (floor == -1) {
breakout = true;
break;
}
}
}
if (ferror(file)) {
perror("Error reading form file.");
return 1;
}
fclose(file);
printf("position: %i\n", pos);
return 0;
}

1
2015/day01/input Normal file

File diff suppressed because one or more lines are too long

10
2015/day01/makefile Normal file
View File

@@ -0,0 +1,10 @@
CC = gcc
CFLAGS = -std=c99 -Wall -g
LDFLAGS =
answer01: answer01.c
$(CC) answer01.c -o answer01
answer02: answer02.c
$(CC) answer02.c -o answer02