Compare commits
4 Commits
d24974703f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| aa49da96bb | |||
| c172b4e1ef | |||
| 2a57da02a9 | |||
| 04d7f1305c |
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"iostream": "cpp",
|
||||||
|
"*.tcc": "cpp"
|
||||||
|
}
|
||||||
|
}
|
||||||
10
2/input.txt
10
2/input.txt
@@ -1,3 +1,8 @@
|
|||||||
|
64 63 64 66 66
|
||||||
|
51 49 50 53 59
|
||||||
|
86 87 88 90 92 93 93 90
|
||||||
|
3 5 8 8 10 14
|
||||||
|
20 23 25 25 25
|
||||||
81 83 84 85 87
|
81 83 84 85 87
|
||||||
87 90 92 95 96 93
|
87 90 92 95 96 93
|
||||||
12 15 16 17 17
|
12 15 16 17 17
|
||||||
@@ -9,9 +14,6 @@
|
|||||||
60 63 65 63 65 69
|
60 63 65 63 65 69
|
||||||
70 73 76 79 77 78 84
|
70 73 76 79 77 78 84
|
||||||
25 27 29 32 35 35 36
|
25 27 29 32 35 35 36
|
||||||
86 87 88 90 92 93 93 90
|
|
||||||
20 23 25 25 25
|
|
||||||
3 5 8 8 10 14
|
|
||||||
3 4 7 9 12 12 14 20
|
3 4 7 9 12 12 14 20
|
||||||
72 75 79 80 82
|
72 75 79 80 82
|
||||||
5 7 11 14 15 18 15
|
5 7 11 14 15 18 15
|
||||||
@@ -25,9 +27,7 @@
|
|||||||
13 16 17 24 26 28 34
|
13 16 17 24 26 28 34
|
||||||
16 14 17 20 21 23 26 28
|
16 14 17 20 21 23 26 28
|
||||||
30 28 30 32 34 36 33
|
30 28 30 32 34 36 33
|
||||||
64 63 64 66 66
|
|
||||||
27 25 27 29 31 34 38
|
27 25 27 29 31 34 38
|
||||||
51 49 50 53 59
|
|
||||||
20 18 19 22 20 22 25 28
|
20 18 19 22 20 22 25 28
|
||||||
25 23 24 26 28 25 22
|
25 23 24 26 28 25 22
|
||||||
11 10 11 8 9 10 10
|
11 10 11 8 9 10 10
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ int main(){
|
|||||||
string line;
|
string line;
|
||||||
int safeReports = 0;
|
int safeReports = 0;
|
||||||
stringstream wholeDoc;
|
stringstream wholeDoc;
|
||||||
|
int linesReadFromFile= 0;
|
||||||
|
|
||||||
ifstream puzzle("input.txt", ifstream::in);
|
ifstream puzzle("input.txt", ifstream::in);
|
||||||
|
|
||||||
@@ -30,9 +31,9 @@ int main(){
|
|||||||
int number = stoi(numberString);
|
int number = stoi(numberString);
|
||||||
currentLevels.push_back(number);
|
currentLevels.push_back(number);
|
||||||
}
|
}
|
||||||
|
linesReadFromFile++;
|
||||||
|
|
||||||
list<int> currentLevelsBackup = currentLevels;
|
list<int> currentLevelsBackup = currentLevels;
|
||||||
int numOfLevelsInLine = currentLevels.size();
|
|
||||||
int numOfLevelsProcessed = 0;
|
int numOfLevelsProcessed = 0;
|
||||||
auto curListIt = currentLevels.begin();
|
auto curListIt = currentLevels.begin();
|
||||||
curListIt++; //point to second item in list
|
curListIt++; //point to second item in list
|
||||||
@@ -68,7 +69,6 @@ int main(){
|
|||||||
levelStaysSame.push_front(index);
|
levelStaysSame.push_front(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float averageChange = totalChange/(currentLevels.size()-1); //we use average change to smooth out the data
|
|
||||||
|
|
||||||
if (totalChange>0){
|
if (totalChange>0){
|
||||||
dir= UP;
|
dir= UP;
|
||||||
@@ -76,9 +76,32 @@ int main(){
|
|||||||
dir = DOWN;
|
dir = DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dir==UP&&levelGoDown.size()>2){ //if the overall direction goes up and more then 2 leves go down the list is bad
|
if(dir==UP&&changeFromPrevLevel.front()<0){
|
||||||
|
currentLevels.erase(currentLevels.begin());
|
||||||
|
levelGoDown.pop_front();
|
||||||
|
listDirty=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dir==UP&&levelGoDown.size()>1){ //if the overall direction goes up and more then 1 level go down the list is bad
|
||||||
currentLevels.clear();
|
currentLevels.clear();
|
||||||
} else if (dir==DOWN&&levelGoesUp.size()>2){ //same as above but opiosite dirrection
|
} else if (dir==DOWN&&levelGoesUp.size()>1){ //same as above but opiosite dirrection
|
||||||
|
currentLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (levelStaysSame.size()>1||(listDirty&&levelStaysSame.size()==0)){ //cant have more then 1 number the same or the list is bad
|
||||||
|
currentLevels.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentLevels.empty()&&levelStaysSame.size()==1){
|
||||||
|
auto itNumberToDelete = currentLevels.begin();
|
||||||
|
advance(itNumberToDelete,levelStaysSame.front());
|
||||||
|
currentLevels.erase(itNumberToDelete);
|
||||||
|
listDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(listDirty&&dir==DOWN&&levelGoesUp.size()>0){
|
||||||
|
currentLevels.clear();
|
||||||
|
} else if(listDirty&&dir==UP&&levelGoDown.size()>0){
|
||||||
currentLevels.clear();
|
currentLevels.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,16 +117,16 @@ int main(){
|
|||||||
currentLevels.erase(itNumberToDelete);
|
currentLevels.erase(itNumberToDelete);
|
||||||
listDirty=true;
|
listDirty=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int numOfLevelsInLine = currentLevels.size();
|
||||||
|
|
||||||
//need to pull the first one to have something to compare to
|
//need to pull the first one to have something to compare to
|
||||||
int prevlevel = currentLevels.front();
|
int prevlevel = currentLevels.front();
|
||||||
currentLevels.pop_front();
|
currentLevels.pop_front();
|
||||||
|
numOfLevelsProcessed++;
|
||||||
|
|
||||||
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
||||||
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||||
if(prevlevel==level){ currentLevels.clear();break;}
|
|
||||||
if(dir==UP&&(prevlevel<currentLevels.front())) {currentLevels.clear();break;}
|
|
||||||
if(dir==DOWN&&(prevlevel>currentLevels.front())) {currentLevels.clear();break;}
|
|
||||||
|
|
||||||
prevlevel=currentLevels.front();
|
prevlevel=currentLevels.front();
|
||||||
currentLevels.pop_front();
|
currentLevels.pop_front();
|
||||||
@@ -116,6 +139,7 @@ int main(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << safeReports;
|
cout <<"lines read in: " << linesReadFromFile<<"\n";
|
||||||
|
cout <<"safe Reports: " << safeReports;
|
||||||
puzzle.close();
|
puzzle.close();
|
||||||
}
|
}
|
||||||
BIN
2/puzzle2p2.exe
BIN
2/puzzle2p2.exe
Binary file not shown.
BIN
2/puzzle2p2.ilk
BIN
2/puzzle2p2.ilk
Binary file not shown.
BIN
2/puzzle2p2.obj
BIN
2/puzzle2p2.obj
Binary file not shown.
BIN
2/puzzle2p2.pdb
BIN
2/puzzle2p2.pdb
Binary file not shown.
BIN
2/vc140.pdb
BIN
2/vc140.pdb
Binary file not shown.
Reference in New Issue
Block a user