day 20, part 2 (before code cleanup)

This commit is contained in:
2022-01-23 20:44:28 +01:00
parent 897453fb39
commit ec4684a756
2 changed files with 17 additions and 10 deletions

View File

@@ -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: **

View File

@@ -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]);