Skip to content

Instantly share code, notes, and snippets.

@steadshot
Created December 2, 2022 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steadshot/183906aa60d5ff2253ca1fee1789b904 to your computer and use it in GitHub Desktop.
Save steadshot/183906aa60d5ff2253ca1fee1789b904 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 1
#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