-
Notifications
You must be signed in to change notification settings - Fork 0
/
day15.c
44 lines (37 loc) · 820 Bytes
/
day15.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
36
37
38
39
40
41
42
43
44
// Advent of Code - Day 15
// @curiouskiwi / @gary_anderson
// 15 Dec 2020
#include <stdio.h>
int nums[30000000] = {0};
int main(void)
{
// 6,3,15,13,1,0
nums[6] = 1;
nums[3] = 2;
nums[15] = 3;
nums[13] = 4;
nums[1] = 5;
nums[0] = 6;
// next move will be
nums[0] = 7;
int previndex = 6;
int turn = 7;
int thisnum = 0;
while (turn < 2020)
{
thisnum = (previndex) ? turn - previndex : 0;
turn++;
previndex = nums[thisnum];
nums[thisnum] = turn;
}
printf("Part 1: %i\n", thisnum);
while (turn < 30000000)
{
thisnum = (previndex) ? turn - previndex : 0;
turn++;
previndex = nums[thisnum];
nums[thisnum] = turn;
}
printf("Part 2: %i\n", thisnum);
//unique nums //3611559
}