C 2022 2 part 1
This commit is contained in:
parent
c343871a2e
commit
5af0f941e9
32
c/2022/2/problem.c
Normal file
32
c/2022/2/problem.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../lib/aoc.h"
|
||||
|
||||
int round_score(const char *round) {
|
||||
printf("round: %s\n", round);
|
||||
int shape = round[2] - 'X' + 1;
|
||||
int opponent_shape = round[0] - 'A' + 1;
|
||||
int result = (((shape - opponent_shape) + 4) % 3) * 3;
|
||||
printf("Shape: %d, opp_shape: %d, result: %d\n", shape, opponent_shape, result);
|
||||
return shape + result;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *input = aoc_read_input();
|
||||
|
||||
int total_score = 0;
|
||||
|
||||
char *round = strtok(input, "\n");
|
||||
|
||||
while (round != NULL) {
|
||||
total_score += round_score(round);
|
||||
round = strtok(NULL, "\n");
|
||||
}
|
||||
|
||||
printf("Part 1: %d\n", total_score);
|
||||
|
||||
free(input);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user