part 1 day 2
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
blackbeard420 2021-12-04 22:19:25 -05:00
parent 6282393eef
commit 0c30bef611
Signed by: blackbeard420
GPG Key ID: 88C719E09CDDA4A5
3 changed files with 41 additions and 2 deletions

37
day2.c Normal file
View File

@ -0,0 +1,37 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define INPUT "inputs/input-day2"
int
main()
{
static char buf[256];
static char cmd[256];
static int operand;
int hpos = 0;
int depth = 0;
FILE *f = fopen(INPUT, "r");
while(fgets(buf, 256, f)) {
sscanf(buf, "%s %d\n", cmd, &operand);
if(strcmp(cmd, "forward") == 0) {
hpos += operand;
} else if(strcmp(cmd, "up") == 0) {
depth -= operand;
} else if(strcmp(cmd, "down") == 0) {
depth += operand;
}
}
fclose(f);
printf("depth: %d hpos: %d\n", depth, hpos);
printf("result: %d\n", hpos * depth);
return 0;
}

View File

@ -1,5 +1,7 @@
DAYS = day1
DAYS = day1 day2
CFLAGS = -Wall -Werror
all: $(DAYS)

View File

@ -1,6 +1,6 @@
#!/bin/sh
DAYS="day1"
DAYS="day1 day2"
for x in $DAYS; do
echo "running" $x