-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountPatternsFrom.cpp
More file actions
99 lines (96 loc) · 4.1 KB
/
countPatternsFrom.cpp
File metadata and controls
99 lines (96 loc) · 4.1 KB
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
#include <iostream>
#include <vector>
#include <algorithm>
void removeChars(std::vector<char>& firstVector, const std::vector<char>& secondVector) {
firstVector.erase(std::remove_if(firstVector.begin(), firstVector.end(),
[&secondVector](char c) { return std::find(secondVector.begin(), secondVector.end(), c) != secondVector.end(); }),
firstVector.end());
sort( firstVector.begin(), firstVector.end() );
firstVector.erase( unique( firstVector.begin(), firstVector.end() ), firstVector.end() );
}
//std::vector<char> lol={'A','B','C','D','E','F','G','H','I'}; // need to take into consideration what I used already and what I want to take for the loop can't be global I know
unsigned int countPatternsFrom1(char firstDot, unsigned short length, std::vector<char> used) {
if (length < 2) return length;
if (length > 9) return 0;
used.push_back(firstDot);
int ile;
std::vector<char> ha;
switch (firstDot){
case 'B':
ha={'A','C','D','E','F','G','I'};
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('H');
removeChars(ha,used);
ile=ha.size();
break;
case 'D':
ha={'A','B','C','E','G','H','I'};
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('F');
removeChars(ha,used);
ile=ha.size();
break;
case 'F':
ha={'A','B','C','E','G','H','I'};
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('D');
removeChars(ha,used);
ile=ha.size();
break;
case 'H':
ha={'A','C','D','E','F','G','I'};
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('B');
removeChars(ha,used);
ile=ha.size();
break;
case 'A':
ha={'B','D','E','F','H'};
if(std::find(used.begin(), used.end(),'D')!=std::end(used)) ha.push_back('G');
if(std::find(used.begin(), used.end(),'B')!=std::end(used)) ha.push_back('C');
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('I');
removeChars(ha,used);
ile=ha.size();
break;
case 'C':
ha={'B','D','E','F','H'};
if(std::find(used.begin(), used.end(),'F')!=std::end(used)) ha.push_back('I');
if(std::find(used.begin(), used.end(),'B')!=std::end(used)) ha.push_back('A');
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('G');
removeChars(ha,used);
ile=ha.size();
break;
case 'G':
ha={'B','D','E','F','H'};
if(std::find(used.begin(), used.end(),'D')!=std::end(used)) ha.push_back('A');
if(std::find(used.begin(), used.end(),'H')!=std::end(used)) ha.push_back('I');
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('C');
removeChars(ha,used);
ile=ha.size();
break;
case 'I':
ha={'B','D','E','F','H'};
if(std::find(used.begin(), used.end(),'F')!=std::end(used)) ha.push_back('C');
if(std::find(used.begin(), used.end(),'H')!=std::end(used)) ha.push_back('G');
if(std::find(used.begin(), used.end(),'E')!=std::end(used)) ha.push_back('A');
removeChars(ha,used);
ile=ha.size();
break;
case 'E':
ha={'A','B','C','D','E','F','G','H','I'};
removeChars(ha,used);
ile=ha.size();
break;
}
//! Remove the possiblities from the vector
//? Mayby keeping trac of the used once would be better
if (length==2) return ile;
length--;
for (char k: ha) {
ile += countPatternsFrom1(k, length, used)-1;
}
return ile;
}
unsigned int countPatternsFrom(char firstDot, unsigned short length){
return countPatternsFrom1(firstDot,length,std::vector<char>());
}
int main() {
std::cout << countPatternsFrom('E', 4);
return 0;
}