day 22 part 2 too high
[aoc_eblake.git] / 2019 / day1.c
blobf25a07113a9e20316217a30df41d2692b6021238
1 #define _GNU_SOURCE 1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <stdarg.h>
6 #include <stdbool.h>
8 void debug(const char *fmt, ...) {
9 va_list ap;
10 if (getenv("DEBUG")) {
11 va_start(ap, fmt);
12 vfprintf(stderr, fmt, ap);
13 va_end(ap);
17 int main(int argc, char **argv) {
18 size_t len = 0, count = 0;
19 int i, sum1 = 0, sum2 = 0;
20 char *line;
22 if (argc > 1)
23 if (!(stdin = freopen(argv[1], "r", stdin))) {
24 perror("failure");
25 exit(2);
28 while (getline(&line, &len, stdin) >= 0) {
29 ++count;
30 i = atoi(line);
31 if (i < 6) {
32 fprintf(stderr, "bad input\n");
33 exit(1);
35 sum1 += i / 3 - 2;
36 while (i > 8) {
37 sum2 += i / 3 - 2;
38 i = i / 3 - 2;
41 printf("Read %zu lines, sum1 %d, sum2 %d\n", count, sum1, sum2);
42 return 0;