#include "aoc.h" #include "util.h" #include #include #include #include #include void part1(void) { char buf[256]; const char *pos, *end; int64_t fuel, ans; pos = aoc.input; end = aoc.input + aoc.input_size; ans = 0; while (readtok(buf, sizeof(buf), '\n', &pos, end)) { fuel = strtoll(buf, NULL, 0); ans += fuel / 3 - 2; } aoc.answer = aprintf("%llu", ans); aoc.solution = "3286680"; } void part2(void) { char buf[256]; const char *pos, *end; int64_t fuel, ans; pos = aoc.input; end = aoc.input + aoc.input_size; ans = 0; while (readtok(buf, sizeof(buf), '\n', &pos, end)) { fuel = strtoll(buf, NULL, 0); while ((fuel = fuel / 3 - 2) > 0) { ans += fuel; } } aoc.answer = aprintf("%llu", ans); aoc.solution = "4927158"; }