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

57
2015/day05/answer01.c Normal file
View File

@@ -0,0 +1,57 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main() {
//load input string
FILE *file = fopen("input", "r");
if (file == NULL) {
perror("main: error opening file.");
return -1;
}
//string exclusions
char *ab = "ab";
char *cd = "cd";
char *pq = "pq";
char *xy = "xy";
uint32_t ncount = 0;
uint8_t double_check = 0;
uint8_t vowel_check = 0;
char input[256];
while (fgets(input, sizeof(input), file) != NULL) {
//string exclusion test
if (strstr(input, ab) || strstr(input, cd) || strstr(input, pq) || strstr(input, xy)) {
continue;
}
//double letter test
double_check = 0;
for (uint8_t i = 0; i < strlen(input); i++) {
if (input[i] == input[i+1]) {
double_check = 1;
break;
}
}
//three vowel test
vowel_check = 0;
for (uint8_t i = 0; i < strlen(input); i++) {
if (input[i] == 'a' || input[i] == 'e' || input[i] == 'i' || input[i] == 'o' || input[i] == 'u')
vowel_check++;
}
if (double_check == 1 && vowel_check >= 3)
ncount++;
}
if (ferror(file)) {
perror("main: error reading file.");
return -1;
}
printf("ncount: %i\n", ncount);
return 0;
}

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

@@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
int main() {
//load input string
FILE *file = fopen("input", "r");
if (file == NULL) {
perror("main: error opening file.");
return -1;
}
uint32_t ncount = 0;
uint8_t two_repeating_check = 0;
uint8_t two_separated_check = 0;
char input[256];
while (fgets(input, sizeof(input), file) != NULL) {
//two letters repeating test
two_repeating_check = 0;
for (uint8_t i = 0; i < strlen(input) - 1; i++) {
for (uint8_t j = i + 2; j < strlen(input) - 1; j++) {
if (input[i] == input[j] && input[i+1] == input[j+1])
two_repeating_check = 1;
}
}
//two letters separated by one test
two_separated_check = 0;
for (uint8_t i = 0; i < strlen(input) - 1; i++) {
if (input[i] == input[i+2])
two_separated_check = 1;
}
if (two_repeating_check && two_separated_check)
ncount++;
}
if (ferror(file)) {
perror("main: error reading file.");
return -1;
}
printf("ncount: %i\n", ncount);
return 0;
}

1000
2015/day05/input Normal file

File diff suppressed because it is too large Load Diff

10
2015/day05/makefile Normal file
View File

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