38 lines
906 B
C
38 lines
906 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "../../lib/aoc.h"
|
|
|
|
int round_score_p1(const char *round) {
|
|
int opponent_shape = round[0] - 'A' + 1;
|
|
int player_shape = round[2] - 'X' + 1;
|
|
int result = (((player_shape - opponent_shape) + 4) % 3) * 3;
|
|
return player_shape + result;
|
|
}
|
|
|
|
int round_score_p2(const char *round) {
|
|
int opponent_shape = round[0] - 'A' + 1;
|
|
int result = (round[2] - 'X') * 3;
|
|
int player_shape = ((result / 3) + 2 + opponent_shape) % 3;
|
|
if (player_shape == 0) player_shape = 3;
|
|
return player_shape + result;
|
|
}
|
|
|
|
int main() {
|
|
int total_score_p1 = 0;
|
|
int total_score_p2 = 0;
|
|
|
|
char *round;
|
|
while ((round = aoc_read_line()) != NULL) {
|
|
total_score_p1 += round_score_p1(round);
|
|
total_score_p2 += round_score_p2(round);
|
|
}
|
|
|
|
printf("Part 1: %d\n", total_score_p1);
|
|
printf("Part 2: %d\n", total_score_p2);
|
|
|
|
aoc_free();
|
|
return 0;
|
|
}
|