day 1: task 2
This commit is contained in:
parent
7a1411e86d
commit
9354fb17cc
2 changed files with 2267 additions and 6 deletions
2252
day_1/input.txt
Normal file
2252
day_1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
|
@ -96,16 +96,25 @@ int main(void) {
|
|||
|
||||
yylex_destroy(scanner);
|
||||
|
||||
// task 1.1
|
||||
unsigned long max_val = 0;
|
||||
// task 1
|
||||
unsigned long max_vals[3] = {0, 0, 0};
|
||||
for (unsigned long i = 0; i < parser_state->size; i++) {
|
||||
if (parser_state->calorie_list[i] > max_val) {
|
||||
max_val = parser_state->calorie_list[i];
|
||||
if (parser_state->calorie_list[i] > max_vals[0]) {
|
||||
int y = 0;
|
||||
while (y < 3 && parser_state->calorie_list[i] > max_vals[y+1]) {
|
||||
y++;
|
||||
}
|
||||
|
||||
for (int yx = 0; yx < y; yx++) {
|
||||
max_vals[yx] = max_vals[yx+1];
|
||||
}
|
||||
max_vals[y] = parser_state->calorie_list[i];
|
||||
}
|
||||
}
|
||||
|
||||
printf("Largest individual calorie load: %lu\n", max_val);
|
||||
|
||||
printf("Largest individual calorie loads:\n%lu\n%lu\n%lu\n", max_vals[0], max_vals[1], max_vals[2]);
|
||||
printf("-------------\n");
|
||||
printf("total: %lu\n", max_vals[0] + max_vals[1] + max_vals[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue