-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday15.cpp
61 lines (50 loc) · 1.16 KB
/
day15.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <map>
#include <unordered_map>
#include "data.h"
std::map<char, std::string> getReplacements()
{
std::map<char, std::string> ret{{',', " "}};
return ret;
}
void process(Data& data)
{
std::unordered_map<uint64_t, uint64_t> when;
std::unordered_map<uint64_t, uint64_t> before;
uint64_t now = 0;
uint64_t spoken = 0;
uint64_t last;
for(now = 0; now < data.lines[0].numbers.size(); ++now)
{
when[data.lines[0].numbers[now]] = now;
last = data.lines[0].numbers[now];
}
do
{
if (before.find(last) == before.end())
{
spoken = 0;
}
else
{
spoken = when[last] - before[last];
}
if (when.find(spoken) != when.end())
{
before[spoken] = when[spoken];
}
when[spoken] = now;
if (now == 2019)
{
std::cout << now << " " << spoken << std::endl;
}
else if (now == 29999999)
{
std::cout << now << " " << spoken << std::endl;
return;
}
last = spoken;
now++;
}
while(true);
}