aoc_omni/c/2022/2/problem.c

27 lines
497 B
C
Raw Normal View History

2024-11-29 21:27:53 -05:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../../lib/aoc.h"
int round_score(const char *round) {
int shape = round[2] - 'X' + 1;
int opponent_shape = round[0] - 'A' + 1;
int result = (((shape - opponent_shape) + 4) % 3) * 3;
return shape + result;
}
int main() {
int total_score = 0;
2024-11-30 06:07:36 -05:00
char *round;
while ((round = aoc_read_line()) != NULL) {
2024-11-29 21:27:53 -05:00
total_score += round_score(round);
}
printf("Part 1: %d\n", total_score);
2024-11-30 06:07:36 -05:00
aoc_free();
2024-11-29 21:27:53 -05:00
return 0;
}