Day 06 starter code

This commit is contained in:
Blizzard Finnegan 2025-01-08 21:36:58 -05:00
parent 39ff6674fb
commit 62a9c60fd7
Signed by: blizzardfinnegan
GPG key ID: 61C1E13067E0018E
4 changed files with 2358 additions and 0 deletions

2237
day06/data/input.txt Normal file

File diff suppressed because it is too large Load diff

15
day06/data/testInput.txt Normal file
View file

@ -0,0 +1,15 @@
abc
a
b
c
ab
ac
a
a
a
a
b

View file

@ -0,0 +1,43 @@
--- Day 6: Custom Customs ---
As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.
The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.
However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:
abcx
abcy
abcz
In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)
Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:
abc
a
b
c
ab
ac
a
a
a
a
b
This list represents answers from five groups:
The first group contains one person who answered "yes" to 3 questions: a, b, and c.
The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
The last group contains one person who answered "yes" to only 1 question, b.
In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.
For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?

63
day06/src/part1.c Normal file
View file

@ -0,0 +1,63 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Convert file into C structs for easier parsing */
int file_import(char * filename){
/* pointer to file */
FILE * file_pointer;
char intermediate_string[12];
char second_string[12];
char * line_get = second_string;
int highest_id;
/* Open file based on filename variable */
file_pointer = fopen(filename, "r");
/* Fail safely if invalid file name */
if (file_pointer == NULL) {
printf("no such file.");
exit(2);
} else {
printf("File successfully loaded.\n");
}
line_get = fgets(intermediate_string, sizeof(intermediate_string), file_pointer);
/* Read until the end of the file */
while( !(feof(file_pointer)) ){
/* Implementation: */
/* dump characters to Set; get count from set */
/* Loop back */
line_get = fgets(intermediate_string, sizeof(intermediate_string), file_pointer);
}
/* Close file when complete */
fclose(file_pointer);
/* sum count of set */
return highest_id;
}
int main(int argc, char **argv) {
/* Final return value */
int highest_id = 0;
/* Array index value */
int array_index = 0;
/* File name importing data from */
char filename_array[30];
char* filename = filename_array;
/* Check argument values, look for filename as first argument
* Fallback to test input if argument not provided */
if(argc >= 2){
filename = argv[1];
} else {
filename = "../data/testInput.txt";
}
highest_id = file_import(filename);
/* Print final calculation */
printf("Final value: %d\n",highest_id);
exit(0);
}