-
Notifications
You must be signed in to change notification settings - Fork 0
/
day15a.c
35 lines (32 loc) · 813 Bytes
/
day15a.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "common.h"
#include "vector.h"
int main (int argc, char ** argv) {
Vector_t nums;
vector_init(&nums, 0);
long int x;
do {
int ret = scanf("%li", &x);
if (ret == 1) {
vector_push_back(&nums, x);
} else if (ret == EOF) {
break;
} else {
ERROR("scanf failed");
}
} while (1);
while (nums.count < 2020) {
ptrdiff_t ind = vector_find(&nums, x);
int y = 0;
if (ind != -1) {
for (intptr_t i = nums.count-2; i >= ind; --i) {
if (nums.data[i] == x) {
y = nums.count - 1 - i;
break;
}
}
}
vector_push_back(&nums, y);
x = y;
}
DISP(nums.data[nums.count-1]);
}