-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoC17.cpp
104 lines (84 loc) · 1.32 KB
/
AoC17.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// AoC17.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
using std::vector;
#include <iostream>
using std::cout;
class circleBuffer
{
public:
circleBuffer()
{
buf.reserve(50000001);
buf.push_back(0);
position = 0;
}
void advance(unsigned int toAdv, int val)
{
unsigned int newPosition = position + toAdv;
newPosition %= buf.size();
newPosition++;
auto bIter = buf.begin();
bIter += newPosition;
buf.insert(bIter, val);
position = newPosition;
}
void out()
{
for (auto &b : buf)
{
cout << b << " ";
}
cout << "\n";
}
private:
vector<int> buf;
unsigned int position;
};
class circleBufferN
{
public:
circleBufferN()
{
buf.reserve(2);
buf.push_back(0);
buf.push_back(0);
position = 0;
size = 1;
}
void advance(unsigned int toAdv, int val)
{
unsigned int newPosition = position + toAdv;
newPosition %= size;
newPosition++;
if (newPosition == 1)
{
buf[1] = val;
}
position = newPosition;
size++;
}
void out()
{
for (auto &b : buf)
{
cout << b << " ";
}
cout << "\n";
}
private:
vector<int> buf;
unsigned int position;
unsigned int size;
};
int _tmain(int argc, _TCHAR* argv[])
{
circleBufferN a;
for (unsigned int i = 1; i!=50000001; i++)
{
a.advance(363, i);
}
a.out();
return 0;
}