-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem15.cpp
54 lines (45 loc) · 1.17 KB
/
problem15.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
#include "threads/mingw.thread.h"
using namespace std;
unsigned long long counter = 0;
int size = 2;
struct Move {
int row;
int col;
};
vector<Move> pipeline;
void path(int row, int col) {
if(row == size && col == size) {
counter++;
if(counter % 5000000 == 0)
cout << "counter " << counter << " pipeline size " << pipeline.size() << " capacity " << pipeline.capacity() << '\n';
} else {
if(col+1 <= size) {
Move adding;
adding.col = col+1;
adding.row = row;
pipeline.push_back(adding);
}
if(row+1 <= size ){
Move adding;
adding.col = col;
adding.row = row+1;
pipeline.push_back(adding);
}
}
}
int main() {
for(size = 2; size < 10; size++) {
Move adding;
adding.col = 0;
adding.row = 0;
pipeline.push_back(adding);
while (!pipeline.empty()) {
Move t = pipeline.back();
pipeline.pop_back();
thread(path, t.row, t.col);
//path(t.row, t.col);
}
cout << "Problem 15 solution is " << counter;
}
return 0;
}