-
Notifications
You must be signed in to change notification settings - Fork 0
/
AoC15.cpp
76 lines (66 loc) · 1.12 KB
/
AoC15.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
// AoC15.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdint>
#include <iostream>
using std::cout;
class generator
{
public:
generator(uint64_t l, uint64_t m, int r) : last(l), mult(m), remn(r) {};
uint64_t gen()
{
while (true)
{
uint64_t temp = last;
temp *= mult;
temp %= 2147483647;
last = temp;
if (temp % remn == 0)
{
return temp;
}
}
}
private:
uint64_t last;
uint64_t mult;
int remn;
};
class judge
{
public:
void round(uint64_t a, uint64_t b)
{
if ((a & 0x000000000000FFFF) == (b & 0x000000000000FFFF))
{
total++;
}
}
unsigned int getTotal()
{
return total;
}
private:
unsigned int total = 0;
};
int _tmain(int argc, _TCHAR* argv[])
{
generator a(679, 16807, 1);
generator b(771, 48271, 1);
judge j;
for (int i = 0; i != 40000000; i++)
{
j.round(a.gen(), b.gen());
}
cout << "Part 1 Total " << j.getTotal() << "\n";
generator a2(679, 16807, 4);
generator b2(771, 48271, 8);
judge j2;
for (int i = 0; i != 5000000; i++)
{
j2.round(a2.gen(), b2.gen());
}
cout << "Total " << j2.getTotal() << "\n";
return 0;
}