-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday20a.cpp
43 lines (40 loc) · 1.74 KB
/
day20a.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
#include "utils.hpp"
int main(int argc, char *argv[])
{
auto input = read_input("day20_input");
std::vector<std::pair<int, int>> initial_values{};
std::vector<std::pair<int, int>> current_values{};
int position = 0;
for (auto &&x : input)
{
initial_values.push_back(std::make_pair(std::stoi(x), position));
position++;
}
current_values = initial_values;
for (auto &&x : initial_values)
{
auto it = std::find(current_values.begin(), current_values.end(), x);
if (it != current_values.end())
{
auto index = std::distance(current_values.begin(), it);
auto new_index = (index + it->first);
new_index = ((new_index % ((long)current_values.size()-1)) + ((long)current_values.size()-1)) % ((long)current_values.size()-1);
if (new_index == 0)
{
new_index = (long)current_values.size() - 1;
}
current_values.erase(it);
auto new_it = current_values.begin() + new_index;
current_values.insert(new_it, x);
}
}
auto it = std::find(current_values.begin(), current_values.end(), std::make_pair(0,4333));
auto index = std::distance(current_values.begin(), it);
int val_thing = ((int)index + 1000) % current_values.size();
int val_thing_2 = ((int)index + 2000) % current_values.size();
int val_thing_3 = ((int)index + 3000) % current_values.size();
std::cout << current_values[val_thing].first << "\n";
std::cout << current_values[val_thing_2].first << "\n";
std::cout << current_values[val_thing_3].first << "\n";
std::cout << current_values[val_thing].first + current_values[val_thing_2].first + current_values[val_thing_3].first << "\n";
}