aoc-2019-c

Advent of Code 2019 Solutions in C
git clone https://git.sinitax.com/sinitax/aoc-2019-c
Log | Files | Refs | README | sfeed.txt

main.c (813B)


      1#include "aoc.h"
      2#include "util.h"
      3
      4#include <err.h>
      5#include <stdlib.h>
      6#include <stdio.h>
      7#include <string.h>
      8#include <stdint.h>
      9
     10void
     11part1(void)
     12{
     13	char buf[256];
     14	const char *pos, *end;
     15	int64_t fuel, ans;
     16
     17	pos = aoc.input;
     18	end = aoc.input + aoc.input_size;
     19
     20	ans = 0;
     21	while (readtok(buf, sizeof(buf), '\n', &pos, end)) {
     22		fuel = strtoll(buf, NULL, 0);
     23		ans += fuel / 3 - 2;
     24	}
     25
     26	aoc.answer = aprintf("%llu", ans);
     27	aoc.solution = "3286680";
     28}
     29
     30void
     31part2(void)
     32{
     33	char buf[256];
     34	const char *pos, *end;
     35	int64_t fuel, ans;
     36
     37	pos = aoc.input;
     38	end = aoc.input + aoc.input_size;
     39
     40	ans = 0;
     41	while (readtok(buf, sizeof(buf), '\n', &pos, end)) {
     42		fuel = strtoll(buf, NULL, 0);
     43		while ((fuel = fuel / 3 - 2) > 0) {
     44			ans += fuel;
     45		}
     46	}
     47
     48	aoc.answer = aprintf("%llu", ans);
     49	aoc.solution = "4927158";
     50}