advent2021

Advent of Code 2021 Solutions
git clone git://bsandro.tech/advent2021
Log | Files | Refs

commit e69485eb4aa4d214d8d2464c32ff9810a9c85fac
parent 92f03e4de6d97806719d0d9601ac993ed0f9dde3
Author: bsandro <[email protected]>
Date:   Thu,  9 Dec 2021 09:22:10 +0200

Slight optimization of d8p2 (no snprintf)

Diffstat:
Mday08/puzzle.c | 6++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/day08/puzzle.c b/day08/puzzle.c @@ -82,17 +82,15 @@ void puzzle(const char *filename, long long *result1, long long *result2) { deduce_digits(digits); - unsigned short answers[PUZZLE_NUMBERS]; - char answers_str[PUZZLE_NUMBERS + 1]; + char answers_str[PUZZLE_NUMBERS + 1] = {0}; for (int i = 0; i < PUZZLE_NUMBERS; ++i) { struct digit_t *digit = get_by_segments(digits, puzzles[i]); assert(digit != NULL); - answers[i] = digit->digit; + answers_str[i] = digit->digit + '0'; if (digit->digit == 1 || digit->digit == 4 || digit->digit == 7 || digit->digit == 8) { (*result1)++; } } - snprintf(answers_str, PUZZLE_NUMBERS + 1, "%d%d%d%d", answers[0], answers[1], answers[2], answers[3]); unsigned long solution = atol(answers_str); *result2 += solution;