aocc23

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

uppga.c (753B)


      1 #include "common.h"
      2 
      3 static inline void move_north(char **grid, size_t nr, size_t nc, size_t r,
      4                               size_t c) {
      5   if (grid[r][c] != 'O')
      6     return;
      7   if (r == 0)
      8     return;
      9 
     10   if (grid[r - 1][c] == '.') {
     11     grid[r - 1][c] = 'O';
     12     grid[r][c] = '.';
     13     move_north(grid, nr, nc, r - 1, c);
     14   }
     15 }
     16 
     17 static inline void tilt_north(char **grid, size_t nr, size_t nc) {
     18   size_t i, j;
     19   for (i = 0; i < nr; i++) {
     20     for (j = 0; j < nc; j++) {
     21       move_north(grid, nr, nc, i, j);
     22     }
     23   }
     24 }
     25 
     26 int main(int argc, char **argv) {
     27   char **lines;
     28   size_t nlines = readlines(&lines, "input");
     29   size_t nc = strlen(lines[0]) - 1;
     30 
     31   tilt_north(lines, nlines, nc);
     32   uint64_t l = load(lines, nlines, nc);
     33 
     34   printf("%llu\n", l);
     35 }