Compare commits
No commits in common. "b4232c905d6f1cc50f645423bc6d4a74bf09336c" and "5a1721acf72c81737e554b751868a198714c5b54" have entirely different histories.
b4232c905d
...
5a1721acf7
5 changed files with 1 additions and 1072 deletions
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
|
@ -1,5 +0,0 @@
|
||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"*.tcc": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
|
|
@ -3,10 +3,8 @@
|
||||||
{
|
{
|
||||||
"type": "cppbuild",
|
"type": "cppbuild",
|
||||||
"label": "C/C++: gcc build active file",
|
"label": "C/C++: gcc build active file",
|
||||||
"command": "/usr/bin/g++",
|
"command": "/usr/bin/gcc",
|
||||||
"args": [
|
"args": [
|
||||||
"--std",
|
|
||||||
"gnu++23",
|
|
||||||
"-fdiagnostics-color=always",
|
"-fdiagnostics-color=always",
|
||||||
"-g",
|
"-g",
|
||||||
"${file}",
|
"${file}",
|
||||||
|
|
|
||||||
1000
2/input.txt
1000
2/input.txt
File diff suppressed because it is too large
Load diff
BIN
2/puzzle2
BIN
2/puzzle2
Binary file not shown.
|
|
@ -1,64 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <list>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
enum Direction {
|
|
||||||
UP,
|
|
||||||
DOWN
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
string line;
|
|
||||||
int safeReports = 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
int numOfLevelsInLine = currentLevels.size();
|
|
||||||
int numOfLevelsProcessed = 0;
|
|
||||||
|
|
||||||
//need to pull the first one to have something to compare to
|
|
||||||
enum Direction dir;
|
|
||||||
int prevlevel = currentLevels.front();
|
|
||||||
currentLevels.pop_front();
|
|
||||||
numOfLevelsProcessed++;
|
|
||||||
if (prevlevel - currentLevels.front()>0){
|
|
||||||
dir = UP;
|
|
||||||
} else if (prevlevel - currentLevels.front()< 0){
|
|
||||||
dir = DOWN;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
for (int level = 0; !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;}
|
|
||||||
|
|
||||||
prevlevel=currentLevels.front();
|
|
||||||
currentLevels.pop_front();
|
|
||||||
|
|
||||||
if(numOfLevelsProcessed==numOfLevelsInLine){
|
|
||||||
safeReports++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cout << safeReports;
|
|
||||||
puzzle.close();
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue