blob: 1f78e149ca73bf8959b08a3bf21004f22921d022 (
plain) (
blame)
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
36
37
38
|
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
int n, s;
int *jumps;
FILE *fp;
if (!(jumps = calloc(PROGLEN, sizeof(int))))
err(EXIT_FAILURE, "calloc");
if (!(fp = fopen("input", "r")))
err(EXIT_FAILURE, "fopen");
for (int i = 0; fscanf(fp, "%d", &n) != EOF; i++)
jumps[i] = n;
fclose(fp);
s = 0;
for (int i = 0; i >= 0 && i < PROGLEN; s++) {
#ifdef PART2
if (jumps[i] >= 3) {
jumps[i]--;
i += jumps[i] + 1;
} else {
jumps[i]++;
i += jumps[i] - 1;
}
#else
jumps[i]++;
i += jumps[i] - 1;
#endif
}
printf("%d\n", s);
return EXIT_SUCCESS;
}
|