makefile and readme

This commit is contained in:
blackbeard420 2021-12-04 21:56:37 -05:00
parent 44500bb0d1
commit 7bff31a8b3
Signed by: blackbeard420
GPG Key ID: 88C719E09CDDA4A5
4 changed files with 1004 additions and 87 deletions

View File

@ -1,87 +0,0 @@
#include <stdlib.h>
#include <stdio.h>
void
first()
{
int prev = -1;
int total = 0;
static char buffer[1024];
FILE *f = fopen("input", "r");
while(fgets(buffer, 1024, f)) {
int val = atoi(buffer);
if(prev != -1 && val > prev) {
total++;
}
prev = val;
}
printf("part 1: %d\n", total);
fclose(f);
}
int
count_lines()
{
int total = 0;
static char buf[256];
FILE *f = fopen("input", "r");
while(fgets(buf, 256, f))
total++;
fclose(f);
return total;
}
int*
load_all(int count)
{
int *i = calloc(sizeof(int), count);
int idx = 0;
static char buf[256];
FILE *f = fopen("input", "r");
while(fgets(buf, 256, f)) {
i[idx] = atoi(buf);
idx++;
}
fclose(f);
return i;
}
void
second()
{
int count = count_lines();
int *values = load_all(count);
int totals = 0;
int lastsum = -1;
for(int i = 0; i < count; ++i) {
if(i + 2 < count) {
int sum = values[i] + values[i+1] + values[i+2];
if(lastsum != -1 && sum > lastsum) {
totals++;
}
lastsum = sum;
}
}
printf("part 2: %d\n", totals);
free(values);
}
int
main()
{
first();
second();
return 0;
}

1000
02/input Normal file

File diff suppressed because it is too large Load Diff

4
makefile Normal file
View File

@ -0,0 +1,4 @@
DAYS = 01/day1
all: $(DAYS)

0
readme Normal file
View File