github.com/cycloss/advent-of-code@v0.0.0-20221210145555-15039b95faa6/2020/day7/day7pt2.c (about)

     1  #include "day7.h"
     2  
     3  extern hashMap* bagMap;
     4  extern arrayList* bagList;
     5  
     6  int findBagsWithinBag(char* bagName, int multiplier) {
     7  
     8      arrayList* currentBagList = (arrayList*)getValueForKey(bagMap, bagName);
     9  
    10      if (!currentBagList) {
    11          printf("No bags found for key: %s\n", bagName);
    12          return 0;
    13      }
    14  
    15      int total = 0;
    16  
    17      for (int i = 0; i < getSize(currentBagList); i++) {
    18          bag* b = getItemAt(currentBagList, i);
    19          total += b->count * multiplier;
    20          total += multiplier * findBagsWithinBag(b->color, b->count);
    21      }
    22  
    23      return total;
    24  }