diff --git a/2022/day2.c b/2022/day2.c new file mode 100644 index 0000000..f74b6b3 --- /dev/null +++ b/2022/day2.c @@ -0,0 +1,22 @@ +#include + +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); +} \ No newline at end of file