the big Munashe birthday bash

Munashe is a mysterious Cnile.
munashe/munashe-day01.c
munashe/munashe-day01.c
// 2021-11-30
    // Advent of Code 2021 Day 1
    // Munashe
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <stdbool.h>
    #include <stdint.h>
    
    #define BUFF_CAP 2048
    
    int main(void){
        char fileName[] = "input.txt";
        FILE \*fp = fopen(fileName, "r");
        int numbers[BUFF_CAP] = {0};
        int lineCount = 0;
        if(!fp) {
            fprintf(stderr, "Could not open %s\n", fileName);
        }
        while(fscanf(fp, "%d", &numbers[lineCount++]) != EOF);
        fclose(fp);
        
        int part1 = 0;
        for(int i = 0; i < lineCount; ++i){
            part1 += numbers[i] < numbers[i+1] ? 1 : 0;
        }
        
        int part2 = 0;
        for(int i = 0; i < lineCount-2; ++i){
            int sum1 = numbers[i] + numbers[i+1] + numbers[i+2];
            int sum2 = numbers[i+1] + numbers[i+2] + numbers[i+3];
            if(sum1 < sum2){
                sum1 = numbers[i] + numbers[i+1] + numbers[i+2];
                part2++;
            }
        }
        printf("part1: %d\n", part1);
        printf("part2: %d\n", part2);
        return 0;
    }
    
munashe/munashe-day02.c
munashe/munashe-day02.c
// 2021-12-01
    // Advent of Code 2021 Day 2
    // Munashe
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define CAP 2000
    
    int main(void){
        char fileName[] = "input.txt";
        FILE \*fp = fopen(fileName, "r");
        int numbers[CAP] = {0};
        char commands[CAP][10] = {0};
        int count = 0;
        if(!fp) {
            fprintf(stderr, "Could not open %s\n", fileName);
        }
        while(fscanf(fp, "%s%d\n", commands[count], &numbers[count]) != EOF){
            ++count;
        }
        fclose(fp);
        
        int depth = 0;
        int dist = 0;
        for(int i = 0; i < count; ++i){
            if(commands[i][0] == 'f') { dist += numbers[i]; }
            if(commands[i][0] == 'u') { depth -= numbers[i]; }
            if(commands[i][0] == 'd') { depth += numbers[i]; }
        }
        printf("Part 1: %d\n", depth \* dist);
        
        depth = 0;
        dist = 0;
        int aim = 0;
        for(int i = 0; i < count; ++i){
            if(commands[i][0] == 'f') { dist += numbers[i]; depth += (numbers[i] \* aim); }
            if(commands[i][0] == 'u') { aim -= numbers[i]; }
            if(commands[i][0] == 'd') { aim += numbers[i]; }
        }
        printf("Part 2: %d\n", depth \* dist);
        
        return 0;
    }
    

Tags: