2022 Day 2 Part 1

This commit is contained in:
Sven Weidauer 2022-12-02 11:40:04 +01:00
parent 5ef21c471d
commit ab94510404

22
2022/day2.c Normal file
View file

@ -0,0 +1,22 @@
#include <stdio.h>
int outcomes[3][3] = {
// Rock Paper Scissor
/* Rock */ { 3, 0, 6 },
/* Paper */ { 6, 3, 0 },
/* Scissor */ { 0, 6, 3 }
};
int main() {
FILE *input = fopen("day2.input", "r");
int total = 0;
while (!feof(input)) {
char opponent, my;
fscanf(input, "%c %c\n", &opponent, &my);
total += my - 'X' + 1 + outcomes[my - 'X'][opponent - 'A'];
}
fclose(input);
printf("Total score %d\n", total);
}