2022 Day 2 Part 1
This commit is contained in:
parent
5ef21c471d
commit
ab94510404
1 changed files with 22 additions and 0 deletions
22
2022/day2.c
Normal file
22
2022/day2.c
Normal 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);
|
||||
}
|
Loading…
Add table
Reference in a new issue