aocc22

Advent of Code 2022
git clone git://www.tkruger.se/aocc22.git
Log | Files | Refs | README

uppgb.c (655B)


      1 #include "common.h"
      2 
      3 int main(int argc, char **argv) {
      4   char **lines;
      5   size_t nlines = readlines(&lines, "input");
      6 
      7   size_t h, w;
      8   size_t pos[4];
      9   uint8_t **grid = parse(&h, &w, pos, lines, nlines);
     10 
     11   uint64_t *stepsto = malloc(h * w * sizeof(*stepsto));
     12   memset(stepsto, 0xff, h * w * sizeof(*stepsto));
     13 
     14   stepsto[pos[2] * w + pos[3]] = 0;
     15   calculate_steps(stepsto, pos[2], pos[3], h, w, grid);
     16 
     17   uint64_t minsteps = UINT64_MAX;
     18   size_t i, j;
     19   for (i = 0; i < h; i++) {
     20     for (j = 0; j < w; j++) {
     21       if (grid[i][j] == 0 && minsteps > stepsto[i * w + j])
     22         minsteps = stepsto[i * w + j];
     23     }
     24   }
     25 
     26   printf("%llu\n", minsteps);
     27 }