diff --git a/day4/p1.c b/day4/p1.c index d370be7..ba08bd9 100644 --- a/day4/p1.c +++ b/day4/p1.c @@ -3,7 +3,6 @@ #include #include #include -#include uint64_t parse_number(char *end); @@ -43,12 +42,14 @@ int main(int argc, char **argv) { for (char *n_pos = pipe_pos + 4;; n_pos += 3) { uint8_t n = parse_number(n_pos-1); + for (size_t i = 0; i < winning_numbers_len; ++i) { if (n != winning_numbers[i]) continue; points = (points == 0) ? 1 : points * 2; break; } + if (*n_pos == '\n') break; } diff --git a/day4/p2.c b/day4/p2.c index 5a60fec..62764bb 100644 --- a/day4/p2.c +++ b/day4/p2.c @@ -3,7 +3,6 @@ #include #include #include -#include #define STACK_SZ UINT8_MAX+1 @@ -42,24 +41,25 @@ int main(int argc, char **argv) { winning_numbers = (uint8_t *) calloc(winning_numbers_len, sizeof(uint8_t)); } - for (size_t i = 0, wl_pos = (size_t)colon_pos+4; i < winning_numbers_len; ++i, wl_pos += 3) { + for (size_t i = 0, wl_pos = (size_t)colon_pos+4; i < winning_numbers_len; ++i, wl_pos += 3) winning_numbers[i] = parse_number((char *)(wl_pos-1)); - } uint64_t card_copies = 1 + stack[stack_pos++]; total_copies += card_copies; - size_t old_sp = stack_pos; + stackpointer_t old_sp = stack_pos; for (char *n_pos = pipe_pos + 4;; n_pos += 3) { uint8_t n = parse_number(n_pos-1); + for (size_t i = 0; i < winning_numbers_len; ++i) { if (n != winning_numbers[i]) continue; stack[stack_pos++] += card_copies; break; } + if (*n_pos == '\n') break; }