Compare commits
11 Commits
b4232c905d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| aa49da96bb | |||
| c172b4e1ef | |||
| 2a57da02a9 | |||
| 04d7f1305c | |||
| d24974703f | |||
| 625cb4986f | |||
| 55f05e4f16 | |||
| 08c10aecd5 | |||
| f5551d2de2 | |||
| d1d69d08ad | |||
| a5ce4e5803 |
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"iostream": "cpp",
|
||||
"*.tcc": "cpp"
|
||||
}
|
||||
}
|
||||
18
.vscode/tasks.json
vendored
18
.vscode/tasks.json
vendored
@@ -2,22 +2,20 @@
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"label": "C/C++: cl.exe build active file",
|
||||
"command": "cl.exe",
|
||||
"args": [
|
||||
"--std",
|
||||
"gnu++23",
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
"/Zi",
|
||||
"/EHsc",
|
||||
"/nologo",
|
||||
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||
"${file}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
"$msCompile"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
|
||||
12
2/input.txt
12
2/input.txt
@@ -1,3 +1,9 @@
|
||||
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
|
||||
87 90 92 95 96 93
|
||||
12 15 16 17 17
|
||||
26 27 29 31 34 36 40
|
||||
@@ -8,9 +14,6 @@
|
||||
60 63 65 63 65 69
|
||||
70 73 76 79 77 78 84
|
||||
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
|
||||
72 75 79 80 82
|
||||
5 7 11 14 15 18 15
|
||||
@@ -24,9 +27,7 @@
|
||||
13 16 17 24 26 28 34
|
||||
16 14 17 20 21 23 26 28
|
||||
30 28 30 32 34 36 33
|
||||
64 63 64 66 66
|
||||
27 25 27 29 31 34 38
|
||||
51 49 50 53 59
|
||||
20 18 19 22 20 22 25 28
|
||||
25 23 24 26 28 25 22
|
||||
11 10 11 8 9 10 10
|
||||
@@ -994,7 +995,6 @@
|
||||
54 52 49 47 46
|
||||
18 15 13 12 9
|
||||
32 33 36 38 40 42 45
|
||||
81 83 84 85 87
|
||||
73 70 69 66 65 62 60 58
|
||||
89 91 92 93 94 96 97
|
||||
58 56 55 52 49 48 45 43
|
||||
|
||||
@@ -16,6 +16,7 @@ enum Direction {
|
||||
int main(){
|
||||
string line;
|
||||
int safeReports = 0;
|
||||
stringstream wholeDoc;
|
||||
|
||||
ifstream puzzle("input.txt", ifstream::in);
|
||||
|
||||
@@ -36,23 +37,24 @@ int main(){
|
||||
int prevlevel = currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
if (prevlevel - currentLevels.front()>0){
|
||||
dir = UP;
|
||||
} else if (prevlevel - currentLevels.front()< 0){
|
||||
if (prevlevel < currentLevels.front()){
|
||||
dir = DOWN;
|
||||
} else if (prevlevel > currentLevels.front()){
|
||||
dir = UP;
|
||||
} else {
|
||||
break;
|
||||
currentLevels.clear();
|
||||
}
|
||||
|
||||
|
||||
for (int level = 0; !currentLevels.empty();level=currentLevels.front()){
|
||||
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
||||
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||
if(prevlevel-level==0){ currentLevels.clear();break;}
|
||||
if(dir==UP&&(prevlevel-currentLevels.front())<0) {currentLevels.clear();break;}
|
||||
if(dir==DOWN&&(prevlevel-currentLevels.front()>0)) {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();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
if(numOfLevelsProcessed==numOfLevelsInLine){
|
||||
safeReports++;
|
||||
|
||||
BIN
2/puzzle2.exe
Normal file
BIN
2/puzzle2.exe
Normal file
Binary file not shown.
BIN
2/puzzle2.ilk
Normal file
BIN
2/puzzle2.ilk
Normal file
Binary file not shown.
BIN
2/puzzle2.obj
Normal file
BIN
2/puzzle2.obj
Normal file
Binary file not shown.
BIN
2/puzzle2.pdb
Normal file
BIN
2/puzzle2.pdb
Normal file
Binary file not shown.
BIN
2/puzzle2p2
Executable file
BIN
2/puzzle2p2
Executable file
Binary file not shown.
145
2/puzzle2p2.cpp
Normal file
145
2/puzzle2p2.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
UNSET
|
||||
};
|
||||
|
||||
int main(){
|
||||
string line;
|
||||
int safeReports = 0;
|
||||
stringstream wholeDoc;
|
||||
int linesReadFromFile= 0;
|
||||
|
||||
ifstream puzzle("input.txt", ifstream::in);
|
||||
|
||||
while (getline(puzzle, line)) {
|
||||
istringstream lineStream(line);
|
||||
string numberString;
|
||||
list<int> currentLevels;
|
||||
while (getline(lineStream, numberString, ' ')) {
|
||||
int number = stoi(numberString);
|
||||
currentLevels.push_back(number);
|
||||
}
|
||||
linesReadFromFile++;
|
||||
|
||||
list<int> currentLevelsBackup = currentLevels;
|
||||
int numOfLevelsProcessed = 0;
|
||||
auto curListIt = currentLevels.begin();
|
||||
curListIt++; //point to second item in list
|
||||
auto RevCurListIt = currentLevels.rbegin();
|
||||
RevCurListIt++; //points to second to last item
|
||||
enum Direction dir;
|
||||
bool listDirty =false;
|
||||
list<int>changeFromPrevLevel;
|
||||
list<int>levelGoesUp;
|
||||
list<int>levelGoDown;
|
||||
list<int>levelStaysSame;
|
||||
int totalChange=0;
|
||||
|
||||
//we are going to walk the levels and see what the change is.
|
||||
//the frontIt is the front number (starts at 2nd entry)
|
||||
//backIt is the first entry (starts at 1st entry)
|
||||
|
||||
auto frontIt = currentLevels.begin();
|
||||
frontIt++;
|
||||
auto backIt = currentLevels.begin();
|
||||
|
||||
for(int index = 1;frontIt!=currentLevels.end();index++){
|
||||
int change = (*frontIt) - (*backIt);
|
||||
totalChange+=change;
|
||||
changeFromPrevLevel.push_back(change);
|
||||
frontIt++;
|
||||
backIt++;
|
||||
if (change>0){
|
||||
levelGoesUp.push_front(index);
|
||||
} else if(change<0){
|
||||
levelGoDown.push_front(index);
|
||||
} else {
|
||||
levelStaysSame.push_front(index);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalChange>0){
|
||||
dir= UP;
|
||||
} else if (totalChange<0){
|
||||
dir = DOWN;
|
||||
}
|
||||
|
||||
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();
|
||||
} 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();
|
||||
}
|
||||
|
||||
if (!currentLevels.empty()){
|
||||
if (dir==UP&&levelGoDown.size()==1){
|
||||
list<int>::iterator itNumberToDelete = currentLevels.begin();
|
||||
advance(itNumberToDelete,levelGoDown.front());
|
||||
currentLevels.erase(itNumberToDelete);
|
||||
listDirty = true;
|
||||
} else if (dir==DOWN&&levelGoesUp.size()==1){
|
||||
auto itNumberToDelete = currentLevels.begin();
|
||||
advance(itNumberToDelete,levelGoesUp.front());
|
||||
currentLevels.erase(itNumberToDelete);
|
||||
listDirty=true;
|
||||
}
|
||||
|
||||
int numOfLevelsInLine = currentLevels.size();
|
||||
|
||||
//need to pull the first one to have something to compare to
|
||||
int prevlevel = currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
||||
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||
|
||||
prevlevel=currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
if(numOfLevelsProcessed==numOfLevelsInLine){
|
||||
safeReports++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cout <<"lines read in: " << linesReadFromFile<<"\n";
|
||||
cout <<"safe Reports: " << safeReports;
|
||||
puzzle.close();
|
||||
}
|
||||
BIN
2/puzzle2p2.exe
Normal file
BIN
2/puzzle2p2.exe
Normal file
Binary file not shown.
BIN
2/puzzle2p2.ilk
Normal file
BIN
2/puzzle2p2.ilk
Normal file
Binary file not shown.
BIN
2/puzzle2p2.obj
Normal file
BIN
2/puzzle2p2.obj
Normal file
Binary file not shown.
BIN
2/puzzle2p2.pdb
Normal file
BIN
2/puzzle2p2.pdb
Normal file
Binary file not shown.
BIN
2/vc140.pdb
Normal file
BIN
2/vc140.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user