From ec4684a756941d8167b03ec17902e69ae8d8aa22 Mon Sep 17 00:00:00 2001 From: Bruno Raoult Date: Sun, 23 Jan 2022 20:44:28 +0100 Subject: [PATCH] day 20, part 2 (before code cleanup) --- 2021/day20/README.txt | 13 +++++++++++++ 2021/day20/aoc-c.c | 14 ++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/2021/day20/README.txt b/2021/day20/README.txt index 72d7ad9..0ec53d7 100644 --- a/2021/day20/README.txt +++ b/2021/day20/README.txt @@ -103,3 +103,16 @@ Through further advances in imaging technology, the above output image can also Truly incredible - now the small details are really starting to come through. After enhancing the original input image twice, 35 pixels are lit. Start with the original input image and apply the image enhancement algorithm twice, being careful to account for the infinite size of the images. How many pixels are lit in the resulting image? + +Your puzzle answer was 5475. +--- Part Two --- + +You still can't quite make out the details in the image. Maybe you just didn't enhance it enough. + +If you enhance the starting input image in the above example a total of 50 times, 3351 pixels are lit in the final output image. + +Start again with the original input image and apply the image enhancement algorithm 50 times. How many pixels are lit in the resulting image? + +Your puzzle answer was 17548. + +Both parts of this puzzle are complete! They provide two gold stars: ** diff --git a/2021/day20/aoc-c.c b/2021/day20/aoc-c.c index bb2f526..bb548eb 100644 --- a/2021/day20/aoc-c.c +++ b/2021/day20/aoc-c.c @@ -32,7 +32,6 @@ int curlen; char **universe[2]; int left, right; -int iter; int current = 0, next = 1; /* read input @@ -168,7 +167,7 @@ static int read_data(int steps) return algolen - 1; } -static int part1(int iter) +static int doit(int iter) { for (int i = 0; i < iter; ++i) { step(); @@ -177,11 +176,6 @@ static int part1(int iter) return count(); } -static int part2() -{ - return 2; -} - static int usage(char *prg) { fprintf(stderr, "Usage: %s [-d debug_level] [-p part]\n", prg); @@ -190,7 +184,7 @@ static int usage(char *prg) int main(int ac, char **av) { - int opt, part = 1; + int opt, part = 1, iter; while ((opt = getopt(ac, av, "d:p:")) != -1) { switch (opt) { @@ -209,13 +203,13 @@ int main(int ac, char **av) if (optind < ac) return usage(*av); - iter = 2; + iter = part == 1? 2: 50; read_data(iter); print_data(0); //step(); //print_data(1); - printf("%s : res=%d\n", *av, part == 1? part1(iter): part2()); + printf("%s : res=%d\n", *av, doit(iter)); for (int i = 0; i < universe_size; ++i) { free(universe[0][i]); free(universe[1][i]);