Day 1/C: Improve, return both results
This commit is contained in:
parent
e753594336
commit
2d7350d2c1
2 changed files with 19 additions and 11 deletions
File diff suppressed because one or more lines are too long
|
@ -1,19 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "input.h"
|
||||
enum {winsize=3};
|
||||
|
||||
int main(void) {
|
||||
uint16_t answer = 0;
|
||||
uint32_t prev = 0;
|
||||
for (uint16_t *p = input+3; p < (&input)[1]; p++) {
|
||||
uint32_t new = *(p-2) + *(p-1) + *p;
|
||||
int num[winsize], res[4]={0}, new, i, j;
|
||||
|
||||
if (new > prev)
|
||||
answer++;
|
||||
for (i=0;scanf("%d",&num[i%winsize])==1;i++) {
|
||||
if (i) {
|
||||
if (num[i%winsize] > res[1])
|
||||
res[0]++;
|
||||
|
||||
prev = new;
|
||||
res[1] = num[i%winsize];
|
||||
|
||||
if (i>2) {
|
||||
for (j=0,new=0;j<winsize;j++)
|
||||
new += num[j];
|
||||
|
||||
if (new > res[3])
|
||||
res[2]++;
|
||||
|
||||
res[3] = new;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Answer: %d\n", answer);
|
||||
printf("Silver: %d\nGold: %d\n", res[0], res[2]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue