-
-
Save steadshot/183906aa60d5ff2253ca1fee1789b904 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef *IntPtr; | |
extern cmpfunc(a, b) register void *b; register void *a; { | |
return (0[(IntPtr) a] < 0[(IntPtr) b]) ? 1 : -1; | |
} | |
extern main(argc, argv) char **argv; { | |
auto FILE const * const fp = fopen("input.txt", "r"); | |
auto number, temp_sum, max_sum, idx, top_reindeers[sizeof idx], buf[sizeof 0[fp]], i = 0; | |
while(!feof(&0[fp])) { | |
fgets(&0[buf], sizeof 0[fp], &0[fp]); | |
if(sscanf(&0[buf], "%d", &number) > i) { | |
temp_sum += number; | |
} else { | |
if(idx < 3) | |
idx++[top_reindeers] = temp_sum; | |
else { | |
idx[top_reindeers] = temp_sum; | |
qsort(&0[top_reindeers], sizeof i, sizeof i, cmpfunc); | |
} | |
temp_sum = i; | |
} | |
} | |
fclose(&0[fp]); | |
for(; i < idx; ) | |
max_sum += i++[top_reindeers]; | |
printf("%d\n", *top_reindeers); | |
printf("%d\n", max_sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment