aocc22

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

uppgb_old.c (837B)


      1 #include "common.h"
      2 
      3 #define LMT 4000000
      4 
      5 int main(int argc, char **argv) {
      6   char **lines;
      7   size_t nlines = readlines(&lines, "input");
      8 
      9   int coords[nlines * 4];
     10   parse(coords, lines, nlines);
     11 
     12   uint64_t xc = UINT64_MAX;
     13   uint64_t yc = UINT64_MAX;
     14   int i;
     15   for (i = 0; i < LMT; i++) {
     16     lh *h = compintervals(coords, nlines, i);
     17     iv *t;
     18 
     19     int found = 0;
     20     LIST_FOREACH(t, h, entries) {
     21       if (t->a <= 0 && t->b >= LMT) {
     22         found = 1;
     23         break;
     24       }
     25     }
     26 
     27     if (found) {
     28       continue;
     29     } else {
     30       // this must be the line
     31       LIST_FOREACH(t, h, entries) {
     32         if (t->a <= 0 && t->b >= 0) {
     33           xc = (uint64_t)(t->b + 1);
     34           yc = (uint64_t)i;
     35           break;
     36         }
     37       }
     38       clear_lh(h);
     39       break;
     40     }
     41     clear_lh(h);
     42   }
     43 
     44   printf("%lu\n", LMT * xc + yc);
     45 }