From 4ed3ab8768359673f97f53c9bad028cbc2ec8492 Mon Sep 17 00:00:00 2001 From: Bill Rossi Date: Sat, 30 Nov 2024 06:07:36 -0500 Subject: [PATCH] Use `aoc_read_line` in c 2022 2 part 1 --- c/2022/2/problem.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/c/2022/2/problem.c b/c/2022/2/problem.c index c74dcff..e473453 100644 --- a/c/2022/2/problem.c +++ b/c/2022/2/problem.c @@ -5,28 +5,22 @@ #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) { + char *round; + while ((round = aoc_read_line()) != NULL) { total_score += round_score(round); - round = strtok(NULL, "\n"); } printf("Part 1: %d\n", total_score); - free(input); + aoc_free(); return 0; }