#include "aoc.h" #include "util.h" #include #include #include #include const size_t width = 25; const size_t height = 6; const char *sol2 = "\ # # #### ## #### # # \n\ # # # # # # # # \n\ #### # # # # # \n\ # # # # # # # \n\ # # # # # # # # \n\ # # #### ## #### ## \n\ "; void part1(void) { size_t i, k; size_t count[3]; int minz = -1, res; i = 0; while (aoc.input[i] != '\n' && i < aoc.input_size) { memset(count, 0, sizeof(count)); for (k = 0; k < width * height; k++) count[aoc.input[i+k] - '0'] += 1; if (minz == -1 || minz > (int) count[0]) { minz = (int) count[0]; res = (int) (count[1] * count[2]); } i += k; } assert(minz != -1); aoc.answer = aprintf("%i", res); aoc.solution = "2016"; } void part2(void) { size_t i, k; int img[width * height]; char *str; for (k = 0; k < width * height; k++) { img[k] = 2; for (i = 0; aoc.input[i * width * height] != '\n'; i++) { if (aoc.input[i * width * height + k] != '2') { img[k] = aoc.input[i * width * height + k] - '0'; break; } } } str = malloc((width + 1) * height + 1); assert(str != NULL); for (i = 0; i < height; i++) { for (k = 0; k < width; k++) { assert(img[i * width + k] != 2); str[i * (width + 1) + k] = img[i * width + k] ? '#' : ' '; } str[i * (width + 1) + k] = '\n'; } str[(width + 1) * height] = '\0'; aoc.answer = str; aoc.solution = sol2; }